From 8756c0950ca9053713262abd1092f6d100adc9a5 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Jan 2023 14:26:28 +0100 Subject: [PATCH] fix(ui): properly position Lazy tabs when opening another cmd. Fixes #361 --- lua/lazy/util.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index 8e8a638..846c6d0 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -8,14 +8,28 @@ end ---@param opts? LazyFloatOptions function M.float(opts) opts = opts or {} - if require("lazy.view").visible() then + local cursor + local View = require("lazy.view") + if View.visible() then + -- set cursor to the top of the ui, so the tabs are visible + cursor = vim.api.nvim_win_get_cursor(View.view.win) + vim.api.nvim_win_set_cursor(View.view.win, { 1, 0 }) opts = vim.tbl_deep_extend("force", { zindex = 60, border = "none", margin = { top = 3, left = 2, right = 2 }, }, opts) end - return require("lazy.view.float")(opts) + local ret = require("lazy.view.float")(opts) + -- restore the cursor + if cursor then + ret:on("BufLeave", function() + if View.visible() then + vim.api.nvim_win_set_cursor(View.view.win, cursor) + end + end, { once = true }) + end + return ret end function M.open(uri)