diff --git a/autoload/Colorizer.vim b/autoload/Colorizer.vim index cd3de83..a40d258 100644 --- a/autoload/Colorizer.vim +++ b/autoload/Colorizer.vim @@ -994,7 +994,7 @@ function! s:PreviewColorHex(match) "{{{2 " explicitly at the end (see #64) let color = matchstr(a:match, s:hex_pattern[1]."$") let pattern = color - if len(color) == 3 + if len(color) == 3 || len(color) == 4 let color = substitute(color, '.', '&&', 'g') endif if &t_Co == 8 && !s:HasGui() @@ -1008,13 +1008,19 @@ function! s:PreviewColorHex(match) "{{{2 let color = list[idx] endif endif - if len(split(pattern, '\zs')) == 8 + if len(split(color, '\zs')) == 8 " apply alpha value - let l = split(pattern, '..\zs') + let l = split(color, '..\zs') call map(l, 'printf("%2d", "0x".v:val)') - let l[3] = string(str2float(l[3])/255) " normalize to 0-1 - let l = s:ApplyAlphaValue(l) - let color = printf("%02X%02X%02X", l[0], l[1], l[2]) + if get(g:, 'colorizer_alpha_first', 0) + let l[0] = string(str2float(l[0])/255) " normalize to 0-1 + let l = s:ApplyAlphaValue([l[1], l[2], l[3], l[0]]) + let color = printf("%02X%02X%02X", l[0], l[1], l[2]) + else + let l[3] = string(str2float(l[3])/255) " normalize to 0-1 + let l = s:ApplyAlphaValue(l) + let color = printf("%02X%02X%02X", l[0], l[1], l[2]) + endif endif call s:SetMatcher(s:hex_pattern[0]. pattern. s:hex_pattern[2], {'bg': color}) if s:use_virtual_text @@ -1487,7 +1493,7 @@ function! s:ColorInit(...) "{{{1 let s:conceal = [&l:cole, &l:cocu] let s:hex_pattern = get(g:, 'colorizer_hex_pattern', - \ ['#', '\%(\x\{3}\|\x\{6}\|\x\{8\}\)', '\%(\>\|[-_]\)\@=']) + \ ['#', '\%(\x\{3}\|\x\{4}\|\x\{6}\|\x\{8\}\)', '\%(\>\|[-_]\)\@=']) if s:HasGui() || &t_Co >= 8 || s:HasColorPattern() " The list of available match() patterns