-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only colorize visible area #20
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,9 @@ endfunction | |
function! s:RgbaColor(str, lineno) "{{{2 | ||
if has("gui_running") | ||
let bg = synIDattr(synIDtrans(hlID("Normal")), "bg") | ||
let bg_r = str2nr(bg[1].bg[2], 16) | ||
let bg_g = str2nr(bg[3].bg[4], 16) | ||
let bg_b = str2nr(bg[5].bg[6], 16) | ||
let bg_r = str2nr(bg[1:2], 16) | ||
let bg_g = str2nr(bg[3:4], 16) | ||
let bg_b = str2nr(bg[5:6], 16) | ||
else | ||
" translucent colors would display incorrectly, so ignore the alpha value | ||
return s:RgbaColorForTerm(a:str, a:lineno) | ||
|
@@ -195,15 +195,9 @@ function! s:RgbaColor(str, lineno) "{{{2 | |
let r = float2nr(ceil(ar * alpha) + ceil(bg_r * (1 - alpha))) | ||
let g = float2nr(ceil(ag * alpha) + ceil(bg_g * (1 - alpha))) | ||
let b = float2nr(ceil(ab * alpha) + ceil(bg_b * (1 - alpha))) | ||
if r > 255 | ||
let r = 255 | ||
endif | ||
if g > 255 | ||
let g = 255 | ||
endif | ||
if b > 255 | ||
let b = 255 | ||
endif | ||
let r = min([r, 255]) | ||
let g = min([g, 255]) | ||
let b = min([b, 255]) | ||
let l:color = printf('#%02x%02x%02x', r, g, b) | ||
call add(ret, [l:color, pat]) | ||
endwhile | ||
|
@@ -286,9 +280,18 @@ function! colorizer#ColorHighlight(update, ...) "{{{1 | |
if g:colorizer_fgcontrast != s:saved_fgcontrast || (exists("a:1") && a:1 == '!') | ||
let s:force_group_update = 1 | ||
endif | ||
for i in range(1, line("$")) | ||
for i in range(line("w0"), line("w$")) | ||
" skip folded lines | ||
if foldclosed(i) > 0 | ||
continue | ||
endif | ||
call s:PreviewColorInLine(i) | ||
endfor | ||
|
||
" A hack for colorizing after opening a folding | ||
if ( winheight('.') - line('w$') + line('w0') ) > 1 | ||
autocmd CursorHold * silent call colorizer#ColorHighlight(1) | ||
endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 比较关键的改动是这以上的十几行。 |
||
let s:force_group_update = 0 | ||
let s:saved_fgcontrast = g:colorizer_fgcontrast | ||
augroup Colorizer | ||
|
@@ -305,7 +308,8 @@ function! colorizer#ColorHighlight(update, ...) "{{{1 | |
autocmd CursorMoved,CursorMovedI * silent call s:CursorMoved() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不需要了吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我认为不需要。因为后面还有 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
我并没有查到相关都文档说明这个。而且 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 但是不会高亮带 alpha 值的颜色,比如 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嗯,alpha值会被漏掉。 |
||
endif | ||
" rgba handles differently, so need updating | ||
autocmd GUIEnter * silent call colorizer#ColorHighlight(1) | ||
autocmd CursorMoved * silent call colorizer#ColorHighlight(1) | ||
autocmd CursorMovedI * silent call colorizer#ColorHighlight(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这会导致移动光标时异常缓慢。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般可视范围内的代码小于100行(我的设置字号9,14寸笔记本上最多不到50行。含有“折叠”时,也会跳过"折叠“的代码),处理应该会很快。我自己使用并不觉得卡。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你按住 l 或者 k 试试呢? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按住 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我个人一般是用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不知道是不是我 CPU 比较拙还是可视区域颜色比较多,j k 也会卡。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我的CPU是4核2.6GHz。 |
||
autocmd BufEnter * silent call colorizer#ColorHighlight(1) | ||
autocmd WinEnter * silent call colorizer#ColorHighlight(1) | ||
autocmd ColorScheme * let s:force_group_update=1 | silent call colorizer#ColorHighlight(1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个自动命令不在组里,可能会被反复添加。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
明白了,难怪加了这个之后会卡死没反应。可以移到组里。
或者,去掉
call s:ClearMatches()
,这样就不需要这段代码。