A Neovim plugin enabling you to solve LeetCode problems.
refactor: change exit shortcut to `qa`
2 files changed, +7 -13
+6-12lua/leetcode-ui/layout/console.lua
| @@ -14,7 +14,6 @@ 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 | |
| 18 | 17 | local ConsoleLayout = Layout:extend("LeetConsoleLayout") |
| 19 | 18 | |
| 20 | 19 | function ConsoleLayout:unmount() -- |
| @@ -25,19 +24,15 @@ function ConsoleLayout:unmount() -- | ||
| 25 | 24 | self.popups = { self.testcase, self.result } |
| 26 | 25 | end |
| 27 | 26 | |
| 28 | -function ConsoleLayout:show() | |
| 29 | - self.prev_winid = vim.api.nvim_get_current_win() | |
| 30 | - | |
| 31 | - ConsoleLayout.super.show(self) | |
| 32 | -end | |
| 33 | - | |
| 34 | 27 | function ConsoleLayout:hide() |
| 35 | 28 | ConsoleLayout.super.hide(self) |
| 36 | 29 | |
| 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 | |
| 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) | |
| 41 | 36 | end |
| 42 | 37 | |
| 43 | 38 | function ConsoleLayout:mount() |
| @@ -97,7 +92,6 @@ function ConsoleLayout:init(parent) | ||
| 97 | 92 | self.testcase = Testcase(self) |
| 98 | 93 | self.result = Result(self) |
| 99 | 94 | self.popups = { self.testcase, self.result } |
| 100 | - self.prev_winid = nil | |
| 101 | 95 | |
| 102 | 96 | ConsoleLayout.super.init( |
| 103 | 97 | self, |