Skip to content

Commit d70f5fb

Browse files
committed
parse only the visible part of each line
This closes ap#46.
1 parent bb34fb4 commit d70f5fb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

autoload/css_color.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,19 @@ let s:_listsep = s:_ws_ . ','
238238
let s:_otherargs_ = '\%(,[^)]*\)\?'
239239
let s:_funcexpr = s:_funcname . '[(]' . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_ws_ . s:_otherargs_ . '[)]'
240240
let s:_csscolor = s:_hexcolor . '\|' . s:_funcexpr
241+
" N.B. sloppy heuristic constants for performance reasons:
242+
" a) start somewhere left of screen in case of partially visible colorref
243+
" b) take some multiple of &columns to handle multibyte chars etc
241244
" N.B. these substitute() calls are here just for the side effect
242245
" of invoking s:create_syn_match during substitution -- because
243246
" match() and friends do not allow finding all matches in a single
244247
" scan without examining the start of the string over and over
245248
function! s:parse_screen()
246249
call s:clear_matches()
247-
call substitute( join( getline('w0','w$'), "\n" ), b:css_color_pat, '\=s:create_syn_match()', 'g' )
250+
let leftcol = winsaveview().leftcol
251+
let left = max([ leftcol - 15, 0 ])
252+
let width = &columns * 4
253+
call filter( range( line('w0'), line('w$') ), 'substitute( strpart( getline(v:val), col([v:val, left]), width ), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
248254
call s:create_matches()
249255
endfunction
250256

0 commit comments

Comments
 (0)