Skip to content

Commit

Permalink
fix: change window on lang change
Browse files Browse the repository at this point in the history
  • Loading branch information
kawre committed Feb 24, 2024
1 parent d29d9f2 commit 55d4313
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lua/leetcode-ui/question.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ function Question:create_buffer(new_tabp)
if new_tabp then
cmd = ("$tabe %s"):format(file_name)
else
cmd = ("e %s"):format(file_name)
cmd = ("edit %s"):format(file_name)
end

local i = self:fold_range()
if i then cmd = cmd .. (" | %d,%dfold"):format(1, i) end
vim.api.nvim_exec2(cmd, {})

self.winid = vim.api.nvim_get_current_win()

utils.exec_hook("question_enter", self)
vim.api.nvim_exec2(cmd, {})

return false
end
Expand Down Expand Up @@ -148,6 +145,8 @@ Question.unmount = vim.schedule_wrap(function(self, pre) self:_unmount(pre) end)
function Question:handle_mount()
self:create_buffer(true)

self.winid = vim.api.nvim_get_current_win()

table.insert(_Lc_questions, self)

vim.api.nvim_create_autocmd("QuitPre", {
Expand All @@ -159,6 +158,8 @@ function Question:handle_mount()
self.console = Console(self)
self.info = Info(self)

utils.exec_hook("question_enter", self)

return self
end

Expand Down Expand Up @@ -231,6 +232,10 @@ end
---@param self lc.ui.Question
---@param lang lc.lang
Question.change_lang = vim.schedule_wrap(function(self, lang)
if vim.api.nvim_get_current_win() ~= self.winid then
vim.api.nvim_set_current_win(self.winid)
end

local old_lang, old_bufnr = self.lang, self.bufnr
self.lang = lang

Expand Down

0 comments on commit 55d4313

Please sign in to comment.