Skip to content

Commit

Permalink
Support #rrggbbaa values
Browse files Browse the repository at this point in the history
Apparently, #rrggbbaa values are legal now. So let's support that
and add the alpha values accordingly
  • Loading branch information
chrisbra committed Aug 24, 2016
1 parent c656b84 commit 9073286
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions autoload/Colorizer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,6 @@ function! s:ColorRGBValues(val) "{{{2
endif
endfor
if len(rgb) == 4
" drop alpha channel
" call remove(rgb, 3)
let rgb = s:ApplyAlphaValue(rgb)
endif
let clr = printf("%02X%02X%02X", rgb[0],rgb[1],rgb[2])
Expand Down Expand Up @@ -1001,6 +999,14 @@ function! s:PreviewColorHex(match) "{{{2
let color = list[idx]
endif
endif
if len(split(pattern, '\zs')) == 8
" apply alpha value
let l = split(pattern, '..\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])
endif
call s:SetMatcher(s:hex_pattern[0]. pattern. s:hex_pattern[2], {'bg': color})
endfunction

Expand Down Expand Up @@ -1391,7 +1397,7 @@ function! s:ColorInit(...) "{{{1
endif

let s:hex_pattern = get(g:, 'colorizer_hex_pattern',
\ ['#', '\%(\x\{3}\|\x\{6}\)', '\%(\>\|[-_]\)\@='])
\ ['#', '\%(\x\{3}\|\x\{6}\|\x\{8\}\)', '\%(\>\|[-_]\)\@='])

if s:HasGui() || &t_Co >= 8 || s:HasColorPattern()
" The list of available match() patterns
Expand Down Expand Up @@ -1960,6 +1966,8 @@ endfunction

function! s:ApplyAlphaValue(rgb) "{{{1
" Add Alpha Value to RGB values
" takes a list of [ rr, gg, bb, aa] values
" alpha can be 0-1
let bg = <sid>SynID('Normal', 'bg')
if empty(bg) || !has('float')
return a:rgb[0:3]
Expand Down
1 change: 1 addition & 0 deletions doc/Colorizer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ looking at my Amazon whishlist: http://www.amazon.de/wishlist/2BKAHE8J7Z6UW
- Make it work with Vims Term Truecolor feature (patch 7.4.1770)
- Make it work with neovim fixes https://github.com/chrisbra/Colorizer/issues/45
and https://github.com/chrisbra/Colorizer/issues/46
- Support css colors: #rrggbbaa format

0.11 Jan 15, 2015 {{{1
- use |TextChanged| autocommand if possible
Expand Down

0 comments on commit 9073286

Please sign in to comment.