A Neovim plugin enabling you to solve LeetCode problems.
fix: change window on lang change
1 file changed, +10 -5
+10-5lua/leetcode-ui/question.lua
| @@ -70,16 +70,13 @@ function Question:create_buffer(new_tabp) | ||
| 70 | 70 | if new_tabp then |
| 71 | 71 | cmd = ("$tabe %s"):format(file_name) |
| 72 | 72 | else |
| 73 | - cmd = ("e %s"):format(file_name) | |
| 73 | + cmd = ("edit %s"):format(file_name) | |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | 76 | local i = self:fold_range() |
| 77 | 77 | if i then cmd = cmd .. (" | %d,%dfold"):format(1, i) end |
| 78 | - vim.api.nvim_exec2(cmd, {}) | |
| 79 | - | |
| 80 | - self.winid = vim.api.nvim_get_current_win() | |
| 81 | 78 | |
| 82 | - utils.exec_hook("question_enter", self) | |
| 79 | + vim.api.nvim_exec2(cmd, {}) | |
| 83 | 80 | |
| 84 | 81 | return false |
| 85 | 82 | end |
| @@ -148,6 +145,8 @@ Question.unmount = vim.schedule_wrap(function(self, pre) self:_unmount(pre) end) | ||
| 148 | 145 | function Question:handle_mount() |
| 149 | 146 | self:create_buffer(true) |
| 150 | 147 | |
| 148 | + self.winid = vim.api.nvim_get_current_win() | |
| 149 | + | |
| 151 | 150 | table.insert(_Lc_questions, self) |
| 152 | 151 | |
| 153 | 152 | vim.api.nvim_create_autocmd("QuitPre", { |
| @@ -159,6 +158,8 @@ function Question:handle_mount() | ||
| 159 | 158 | self.console = Console(self) |
| 160 | 159 | self.info = Info(self) |
| 161 | 160 | |
| 161 | + utils.exec_hook("question_enter", self) | |
| 162 | + | |
| 162 | 163 | return self |
| 163 | 164 | end |
| 164 | 165 | |
| @@ -231,6 +232,10 @@ end | ||
| 231 | 232 | ---@param self lc.ui.Question |
| 232 | 233 | ---@param lang lc.lang |
| 233 | 234 | Question.change_lang = vim.schedule_wrap(function(self, lang) |
| 235 | + if vim.api.nvim_get_current_win() ~= self.winid then | |
| 236 | + vim.api.nvim_set_current_win(self.winid) | |
| 237 | + end | |
| 238 | + | |
| 234 | 239 | local old_lang, old_bufnr = self.lang, self.bufnr |
| 235 | 240 | self.lang = lang |
| 236 | 241 |