Skip to content

Commit 4a84bd6

Browse files
committed
feat(icons): use virtual text if possible (has('nvim') or has('textprop'))
Closes justinmk#145, justinmk#253
1 parent c87a8e1 commit 4a84bd6

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

autoload/dirvish.vim

+24-6
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,19 @@ func! s:apply_icons() abort
426426
if 0 == len(s:cb_map)
427427
return
428428
endif
429-
highlight clear Conceal
429+
if has('nvim')
430+
if !exists('s:ns_id')
431+
let s:ns_id = nvim_create_namespace('dirvish.icons')
432+
endif
433+
elseif v:version >= 901 && has('textprop')
434+
if !exists('s:prop_type')
435+
let s:prop_type = 'dirvish.icons'
436+
call prop_type_add(s:prop_type, {})
437+
endif
438+
else
439+
highlight clear Conceal
440+
endif
441+
430442
let i = 0
431443
for f in getline(1, '$')
432444
let i += 1
@@ -438,11 +450,17 @@ func! s:apply_icons() abort
438450
endif
439451
endfor
440452
if icon != ''
441-
let isdir = (f[-1:] == s:sep)
442-
let f = substitute(s:f(f), escape(s:sep,'\').'$', '', 'g') " Full path, trim slash.
443-
let tail_esc = escape(fnamemodify(f,':t').(isdir?(s:sep):''), '[,*.^$~\')
444-
exe 'syntax match DirvishColumnHead =\%'.i.'l^.\{-}\ze'.tail_esc.'$= conceal cchar='.icon
445-
endif
453+
if has('nvim')
454+
call nvim_buf_set_extmark(0, s:ns_id, i-1, 0, #{virt_text: [[icon, 'DirvishColumnHead']], virt_text_pos: 'inline'})
455+
elseif v:version >= 901 && has('textprop')
456+
call prop_add(i, 1, #{type: s:prop_type, text: icon})
457+
else
458+
let isdir = (f[-1:] == s:sep)
459+
let f = substitute(s:f(f), escape(s:sep,'\').'$', '', 'g') " Full path, trim slash.
460+
let tail_esc = escape(fnamemodify(f,':t').(isdir?(s:sep):''), '[,*.^$~\')
461+
exe 'syntax match DirvishColumnHead =\%'.i.'l^.\{-}\ze'.tail_esc.'$= conceal cchar='.icon
462+
endif
463+
endif
446464
endfor
447465
endf
448466

0 commit comments

Comments
 (0)