A Neovim plugin enabling you to solve LeetCode problems.
feat(console): restore winid on `hide()`
1 file changed, +12 -6
+12-6lua/leetcode-ui/layout/console.lua
| @@ -14,6 +14,7 @@ local log = require("leetcode.logger") | ||
| 14 | 14 | ---@field testcase lc.ui.Console.TestcasePopup |
| 15 | 15 | ---@field result lc.ui.Console.ResultPopup |
| 16 | 16 | ---@field popups lc.ui.Console.Popup[] |
| 17 | +---@field prev_winid integer | |
| 17 | 18 | local ConsoleLayout = Layout:extend("LeetConsoleLayout") |
| 18 | 19 | |
| 19 | 20 | function ConsoleLayout:unmount() -- |
| @@ -24,15 +25,19 @@ function ConsoleLayout:unmount() -- | ||
| 24 | 25 | self.popups = { self.testcase, self.result } |
| 25 | 26 | end |
| 26 | 27 | |
| 28 | +function ConsoleLayout:show() | |
| 29 | + self.prev_winid = vim.api.nvim_get_current_win() | |
| 30 | + | |
| 31 | + ConsoleLayout.super.show(self) | |
| 32 | +end | |
| 33 | + | |
| 27 | 34 | function ConsoleLayout:hide() |
| 28 | 35 | ConsoleLayout.super.hide(self) |
| 29 | 36 | |
| 30 | - pcall(function() | |
| 31 | - local winid = vim.api.nvim_get_current_win() | |
| 32 | - if winid == self.question.description.winid then | |
| 33 | - vim.api.nvim_set_current_win(self.question.winid) | |
| 34 | - end | |
| 35 | - end) | |
| 37 | + if self.prev_winid and vim.api.nvim_win_is_valid(self.prev_winid) then | |
| 38 | + vim.api.nvim_set_current_win(self.prev_winid) | |
| 39 | + self.prev_winid = nil | |
| 40 | + end | |
| 36 | 41 | end |
| 37 | 42 | |
| 38 | 43 | function ConsoleLayout:mount() |
| @@ -90,6 +95,7 @@ function ConsoleLayout:init(parent) | ||
| 90 | 95 | self.testcase = Testcase(self) |
| 91 | 96 | self.result = Result(self) |
| 92 | 97 | self.popups = { self.testcase, self.result } |
| 98 | + self.prev_winid = nil | |
| 93 | 99 | |
| 94 | 100 | ConsoleLayout.super.init( |
| 95 | 101 | self, |