Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions autoload/Colorizer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down