From 5e3c112cb32c9cb6e8622aab4446358e039def7c Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 29 Jun 2024 14:22:53 +0200 Subject: [PATCH] feat(ui): use [[ & ]] to navigate between plugins. Fixes #1463 --- lua/lazy/view/config.lua | 2 ++ lua/lazy/view/init.lua | 22 ++++++++++++++++++++++ lua/lazy/view/render.lua | 10 +++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lua/lazy/view/config.lua b/lua/lazy/view/config.lua index e834573..d65f03c 100644 --- a/lua/lazy/view/config.lua +++ b/lua/lazy/view/config.lua @@ -34,6 +34,8 @@ M.keys = { profile_sort = "", profile_filter = "", abort = "", + next = "]]", + prev = "[[", } ---@type table diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 6ff3c81..468ac8a 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -111,6 +111,28 @@ function M.create() end end) + self:on_key(ViewConfig.keys.next, function() + local cursor = vim.api.nvim_win_get_cursor(self.view.win) + for l = 1, #self.render.locations, 1 do + local loc = self.render.locations[l] + if loc.from > cursor[1] then + vim.api.nvim_win_set_cursor(self.view.win, { loc.from, 8 }) + return + end + end + end) + + self:on_key(ViewConfig.keys.prev, function() + local cursor = vim.api.nvim_win_get_cursor(self.view.win) + for l = #self.render.locations, 1, -1 do + local loc = self.render.locations[l] + if loc.from < cursor[1] then + vim.api.nvim_win_set_cursor(self.view.win, { loc.from, 8 }) + return + end + end + end) + self:on_key(ViewConfig.keys.profile_sort, function() if self.state.mode == "profile" then self.state.profile.sort_time_taken = not self.state.profile.sort_time_taken diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index c128147..e1eec6c 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -201,7 +201,15 @@ function M:help() :nl() self:append("or the plugin was just updated. Otherwise the plugin webpage will open."):nl():nl() - self:append("Use "):append("", "LazySpecial"):append(" on a commit or plugin to open the diff view"):nl() + self:append("Use "):append("", "LazySpecial"):append(" on a commit or plugin to open the diff view"):nl():nl() + self + :append("Use ") + :append("<]]>", "LazySpecial") + :append(" and ") + :append("<[[>", "LazySpecial") + :append(" to navigate between plugins") + :nl() + :nl() self:nl() self:append("Keyboard Shortcuts", "LazyH2"):nl()