irongit

A Neovim plugin enabling you to solve LeetCode problems.

fix: change window on lang change

kawreauthored
parent d29d9f2commit 55d43131d63a22b1d43108435ab61f3661014be7Browse files

1 file changed, +10 -5

+10-5lua/leetcode-ui/question.lua
@@ -70,16 +70,13 @@ function Question:create_buffer(new_tabp)
7070 if new_tabp then
7171 cmd = ("$tabe %s"):format(file_name)
7272 else
73- cmd = ("e %s"):format(file_name)
73+ cmd = ("edit %s"):format(file_name)
7474 end
7575
7676 local i = self:fold_range()
7777 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()
8178
82- utils.exec_hook("question_enter", self)
79+ vim.api.nvim_exec2(cmd, {})
8380
8481 return false
8582 end
@@ -148,6 +145,8 @@ Question.unmount = vim.schedule_wrap(function(self, pre) self:_unmount(pre) end)
148145 function Question:handle_mount()
149146 self:create_buffer(true)
150147
148+ self.winid = vim.api.nvim_get_current_win()
149+
151150 table.insert(_Lc_questions, self)
152151
153152 vim.api.nvim_create_autocmd("QuitPre", {
@@ -159,6 +158,8 @@ function Question:handle_mount()
159158 self.console = Console(self)
160159 self.info = Info(self)
161160
161+ utils.exec_hook("question_enter", self)
162+
162163 return self
163164 end
164165
@@ -231,6 +232,10 @@ end
231232 ---@param self lc.ui.Question
232233 ---@param lang lc.lang
233234 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+
234239 local old_lang, old_bufnr = self.lang, self.bufnr
235240 self.lang = lang
236241