@@ -125,34 +125,31 @@ function! s:PreviewCSSColorInLine()
125125 " TODO use cssColor matchdata
126126 let n = 0
127127 while 1
128- let foundcolor = matchstr ( getline (' .' ), ' #\x\{3}\(\x\{3}\)\?\>' , 0 , n )
129- if len ( foundcolor ) == 0 | break | endif
130-
131- if len ( foundcolor ) == 4
132- let color = substitute (foundcolor, ' \(\x\)\(\x\)\(\x\)' , ' \1\1\2\2\3\3' , ' ' )
133- else
134- let color = foundcolor
135- endif
136-
137- call s: SetMatcher (color ,foundcolor)
138-
128+ let rgb = matchlist ( getline (' .' ), ' #\(\x\)\(\x\)\(\x\)\>' , 0 , n )
129+ if len ( rgb ) == 0 | break | endif
130+ let [r ,g ,b ] = rgb[1 :3 ]
131+ call s: SetMatcher ( ' #' .r .r .g .g .b .b , rgb[0 ] )
139132 let n += 1
140133 endwhile
134+ unlet rgb
141135
142136 let n = 0
143137 while 1
144- let foundcolorlist = matchlist ( getline (' .' ), ' rgb[a]\=(\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\).\{-})' , 0 , n )
145- if len ( foundcolorlist ) == 0 | break | endif
146-
147- let foundcolorlist[1 ] = s: value2hex ( foundcolorlist[1 ] )
148- let foundcolorlist[2 ] = s: value2hex ( foundcolorlist[2 ] )
149- let foundcolorlist[3 ] = s: value2hex ( foundcolorlist[3 ] )
150-
151- let color = " #" .join ( foundcolorlist[1 :3 ], " " )
152-
153- call s: SetMatcher ( color , foundcolorlist[0 ] )
138+ let rgb = matchstr ( getline (' .' ), ' #\x\{6}\>' , 0 , n )
139+ if len ( rgb ) == 0 | break | endif
140+ call s: SetMatcher ( rgb, rgb )
141+ let n += 1
142+ endwhile
143+ unlet rgb
154144
155- let n += 1
145+ let n = 0
146+ while 1
147+ let rgb = matchlist ( getline (' .' ), ' rgba\?(\(\d\{1,3}%\?\)\s*,\s*\(\d\{1,3}%\?\)\s*,\s*\(\d\{1,3}%\?\)\s*\%(,[^)]*\)\?)' , 0 , n )
148+ if len ( rgb ) == 0 | break | endif
149+ let [r ,g ,b ] = rgb[1 :3 ]
150+ let color = ' #' .s: value2hex (r ).s: value2hex (g ).s: value2hex (b )
151+ call s: SetMatcher ( color , rgb[0 ] )
152+ let n += 1
156153 endwhile
157154endfunction
158155
0 commit comments