Skip to content

Commit fd36cab

Browse files
committed
remove duplication from PreviewCSSColorInLine
1 parent c7001e7 commit fd36cab

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

after/syntax/css.vim

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,27 @@ endf
129129

130130
function! s:PreviewCSSColorInLine()
131131
" TODO use cssColor matchdata
132-
let n = 1
133-
let foundcolor = matchstr( getline('.'), '#[0-9A-Fa-f]\{3,6\}\>' )
134-
while foundcolor != ''
135-
if foundcolor =~ '#\x\{6}$'
136-
let color = foundcolor
137-
elseif foundcolor =~ '#\x\{3}$'
132+
let n = 0
133+
while 1
134+
let foundcolor = matchstr( getline('.'), '#\x\{3}\(\x\{3}\)\?\>', 0, n )
135+
if len( foundcolor ) == 0 | break | endif
136+
137+
if len( foundcolor ) == 4
138138
let color = substitute(foundcolor, '\(\x\)\(\x\)\(\x\)', '\1\1\2\2\3\3', '')
139139
else
140-
let color = ''
140+
let color = foundcolor
141141
endif
142142

143-
if color != ''
144-
call s:SetMatcher(color,foundcolor)
145-
endif
143+
call s:SetMatcher(color,foundcolor)
146144

147145
let n+=1
148-
let foundcolor = matchstr( getline('.'), '#[0-9A-Fa-f]\{3,6}', 0, n )
149146
endwhile
150147

148+
let n = 0
149+
while 1
150+
let foundcolorlist = matchlist( getline('.'), 'rgb[a]\=(\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\).\{-})', 0, n )
151+
if len( foundcolorlist ) == 0 | break | endif
151152

152-
let n = 1
153-
let foundcolorlist = matchlist( getline('.'), 'rgb[a]\=(\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\).\{-})', 0, n )
154-
while len(foundcolorlist) != 0
155153
let foundcolorlist[1] = s:value2hex( foundcolorlist[1] )
156154
let foundcolorlist[2] = s:value2hex( foundcolorlist[2] )
157155
let foundcolorlist[3] = s:value2hex( foundcolorlist[3] )
@@ -161,8 +159,7 @@ function! s:PreviewCSSColorInLine()
161159
call s:SetMatcher( color, foundcolorlist[0] )
162160

163161
let n+=1
164-
let foundcolorlist = matchlist( getline('.'), 'rgb[a]\=(\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\),\s*\(\d\{1,3}\s*%\=\).\{-})', 0, n )
165-
endw
162+
endwhile
166163
endfunction
167164

168165
if has("gui_running") || &t_Co==256

0 commit comments

Comments
 (0)