@@ -1319,18 +1319,17 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
13191319 return
13201320 end
13211321
1322- self .orig_pos = { lnum , math.max (0 , col - 1 ) }
1322+ self .orig_pos = { lnum , math.max (1 , col ) - 1 }
13231323 api .nvim_win_set_cursor (win , cached_pos or self .orig_pos )
13241324 self :maybe_set_cursorline (win , self .orig_pos )
1325- -- fn.clearmatches() is slow for bigfile
1326- if self .match_id then
1327- pcall (fn .matchdelete , self .match_id )
1328- self .match_id = nil
1329- end
1325+
1326+ self .ns_previewer = self .ns_previewer or api .nvim_create_namespace (" fzf-lua.preview.hl" )
1327+ api .nvim_buf_clear_namespace (buf , self .ns_previewer , 0 , - 1 )
1328+ local extmark
13301329
13311330 -- If regex is available (grep/lgrep), match on current line
1332- local regex_start , regex_end = 0 , nil
13331331 if regex and hls .search then
1332+ local regex_start , regex_end = 0 , nil
13341333 -- vim.regex is always magic, see `:help vim.regex`
13351334 local ok , reg = pcall (vim .regex , regex )
13361335 if ok then
@@ -1348,13 +1347,19 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
13481347 regex , reg )
13491348 end
13501349 if regex_start > 0 then
1351- self .match_id = fn .matchaddpos (hls .search , { { lnum , regex_start , regex_end } }, 11 ) --- @as integer
1350+ extmark = api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , regex_start - 1 , {
1351+ end_line = lnum - 1 ,
1352+ end_col = regex_start - 1 + regex_end ,
1353+ hl_group = hls .search ,
1354+ })
13521355 end
13531356 end
13541357
13551358 -- Fallback to cursor hl, only if column exists
1356- if regex_start <= 0 and hls .cursor and col > 0 then
1357- self .match_id = fn .matchaddpos (hls .cursor , { { lnum , math.max (1 , col ) } }, 11 ) --- @as integer
1359+ if not extmark and hls .cursor and col > 0 then
1360+ local end_lnum , end_col = entry .end_line or lnum , entry .end_col or col + 1
1361+ api .nvim_buf_set_extmark (buf , self .ns_previewer , lnum - 1 , math.max (1 , col ) - 1 ,
1362+ { end_line = end_lnum - 1 , end_col = math.max (1 , end_col ) - 1 , hl_group = hls .cursor })
13581363 end
13591364
13601365 utils .zz ()
0 commit comments