@@ -618,36 +618,46 @@ function Previewer.base:scroll(direction)
618618 self .win :update_preview_scrollbar ()
619619 self :update_render_markdown ()
620620 self :update_ts_context ()
621- self :copy_extmarks ()
622621end
623622
624623-- https://github.com/kevinhwang91/nvim-bqf/blob/b51a37fcd808edafd52511458467c8c9a701ea8d/lua/bqf/preview/extmark.lua#L20
624+ -- copy extmarks from src_buf to buf
625+ --- @param src_buf integer
626+ --- @param buf integer
627+ --- @param win integer
628+ --- @param topline integer 0-based
629+ --- @param botline integer 0-based
630+ --- @param ns integer
631+ local copy_extmarks = function (src_buf , buf , win , topline , botline , ns )
632+ local src_win = fn .win_findbuf (src_buf )[1 ]
633+ local src_leftcol = src_win and api .nvim_win_call (src_win , fn .winsaveview ).leftcol or nil
634+ -- virt_text is related to screen https://github.com/neovim/neovim/issues/14050
635+ local no_virt_text = api .nvim_win_call (win , fn .winsaveview ).leftcol ~= src_leftcol
636+ api .nvim_buf_clear_namespace (buf , ns , topline , botline )
637+ local extmarks = api .nvim_buf_get_extmarks (src_buf , - 1 , { topline , 0 }, { botline , - 1 },
638+ { details = true })
639+ for _ , m in ipairs (extmarks ) do
640+ local _ , row , col , details = unpack (m ) --- @cast details -?
641+ details .ns_id = nil
642+ if no_virt_text and details .virt_text then details .virt_text = nil end
643+ pcall (api .nvim_buf_set_extmark , buf , ns , row , col , details )
644+ end
645+ end
646+
647+ --- @return fun ()
625648function Previewer .base :copy_extmarks ()
626- -- copy extmarks from source window to preview window
627- if not self .win or not self .win :validate_preview () or not self .loaded_entry or not self .loaded_entry .bufnr then return end
628649 self .ns_extmarks = self .ns_extmarks or api .nvim_create_namespace (" fzf-lua.preview.extmarks" )
629- local src_bufnr = self .loaded_entry .bufnr
630- local dst_bufnr = self .preview_bufnr
631- local ns = self .ns_extmarks
632- local win = self .win .preview_winid
633- local winview = api .nvim_win_call (win , fn .winsaveview )
634- local topline = winview .topline
635- local botline = fn .line (" w$" , win )
636- local src_winid = fn .bufwinid (src_bufnr )
637- local src_leftcol = src_winid ~= - 1 and api .nvim_win_call (src_winid , fn .winsaveview ).leftcol or nil
638- -- virt_text is related to screen https://github.com/neovim/neovim/issues/14050
639- local no_virt_text = winview .leftcol ~= src_leftcol
640- api .nvim_buf_clear_namespace (dst_bufnr , ns , topline , botline )
641- for _ , n in pairs (api .nvim_get_namespaces ()) do
642- local extmarks = api .nvim_buf_get_extmarks (src_bufnr , n , { topline - 1 , 0 },
643- { botline - 1 , - 1 },
644- { details = true })
645- for _ , m in ipairs (extmarks ) do
646- local _ , row , col , details = unpack (m ) --- @cast details -?
647- details .ns_id = nil
648- if no_virt_text and details .virt_text then details .virt_text = nil end
649- pcall (api .nvim_buf_set_extmark , dst_bufnr , ns , row , col , details )
650- end
650+ api .nvim_set_decoration_provider (self .ns_extmarks , {
651+ on_win = function (_ , win , buf , topline , botline )
652+ if win ~= self .win .preview_winid then return end
653+ local src_buf = self .loaded_entry and self .loaded_entry .bufnr
654+ if not src_buf then return end
655+ copy_extmarks (src_buf , buf , win , topline , botline , self .ns_extmarks )
656+ return false
657+ end ,
658+ })
659+ return function ()
660+ api .nvim_set_decoration_provider (self .ns_extmarks , {})
651661 end
652662end
653663
@@ -1535,7 +1545,6 @@ function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
15351545 self :update_render_markdown ()
15361546 self :update_ts_context ()
15371547 self :attach_snacks_image_inline ()
1538- vim .schedule (function () self :copy_extmarks () end )
15391548 end
15401549 -- for attach_snacks_image_{inline,buf}
15411550 -- https://github.com/folke/snacks.nvim/pull/1615
0 commit comments