Skip to content

Commit

Permalink
feat(ui): Save cursor position when toggling plugin details
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhas07 committed Feb 24, 2024
1 parent aedcd79 commit a3ff2f1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local Text = require("lazy.view.text")
---@field progress {total:number, done:number}
---@field _diagnostics LazyDiagnostic[]
---@field locations {name:string, from: number, to: number, kind?: LazyPluginKind}[]
---@field selected_plugin {name: string, row: number}?
local M = {}

---@return LazyRender
Expand Down Expand Up @@ -255,9 +256,21 @@ function M:section(section)
end)
if count > 0 then
self:append(section.title, "LazyH2"):append(" (" .. count .. ")", "LazyComment"):nl()
local old_selected_plugin = self.selected_plugin
self.selected_plugin = nil
for _, plugin in ipairs(section_plugins) do
self:plugin(plugin)
end

if
self.selected_plugin ~= nil
and (old_selected_plugin == nil or old_selected_plugin.name ~= self.selected_plugin.name)
then
vim.api.nvim_win_set_cursor(self.view.win, { self.selected_plugin.row, 0 })
elseif self.selected_plugin == nil and old_selected_plugin ~= nil then
vim.api.nvim_win_set_cursor(self.view.win, { old_selected_plugin.row, 0 })
end

self:nl()
end
end
Expand Down Expand Up @@ -428,6 +441,7 @@ function M:plugin(plugin)

if self.view:is_selected(plugin) then
self:details(plugin)
self.selected_plugin = { name = plugin.name, row = plugin_start }
end
self:tasks(plugin)
self.locations[#self.locations + 1] =
Expand Down

0 comments on commit a3ff2f1

Please sign in to comment.