diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index 64b30783..76e093a4 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -754,6 +754,32 @@ function Previewer.base:update_render_markdown() end end +function Previewer.base:update_ts_context(close) + -- excerpt from nvim-treesitter-context `update_single_context` + if not package.loaded["treesitter-context"] then return end + local bufnr, winid = self.preview_bufnr, self.win.preview_winid + if close then + -- Original cursorline (match) out of bounds, hide ts-context + require("treesitter-context.render").close(winid) + return + end + -- Temporarily set "zindex" higher than fzf-lua + local config = require("treesitter-context.config") + local saved_zindex = config.zindex + config.zindex = self.win._o.winopts.zindex + 20 + require("treesitter-context.render").close_leaked_contexts() + local context_ranges, context_lines = require("treesitter-context.context").get(bufnr, winid) + if not context_ranges or #context_ranges == 0 then + require("treesitter-context.render").close(winid) + else + assert(context_lines) + require("treesitter-context.render").open(bufnr, winid, context_ranges, context_lines) + -- _G.dump("ts", bufnr, winid, context_ranges, context_lines) + end + -- Restore saved "zindex" + config.zindex = saved_zindex +end + function Previewer.buffer_or_file:do_syntax(entry) if not self.preview_bufnr then return end if not entry or not entry.path then return end @@ -845,7 +871,6 @@ function Previewer.buffer_or_file:do_syntax(entry) end function Previewer.buffer_or_file:maybe_set_cursorline(win, pos) - if not self.winopts.cursorline then return end local wininfo = utils.getwininfo(win) if wininfo and pos[1] >= wininfo.topline @@ -854,9 +879,11 @@ function Previewer.buffer_or_file:maybe_set_cursorline(win, pos) -- reset cursor pos even when it's already there, no bigggie -- local curpos = vim.api.nvim_win_get_cursor(win) vim.api.nvim_win_set_cursor(win, pos) - vim.wo[win].cursorline = true + vim.wo[win].cursorline = self.winopts.cursorline + self:update_ts_context() else vim.wo[win].cursorline = false + self:update_ts_context(true) end end