Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1fcd2ee

Browse files
committed
fix(hooks): exec LeetQuestionNew on lang change
1 parent b3ab6cb commit 1fcd2ee

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lua/leetcode-ui/question.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function Question:get_snippet()
3131
)
3232
end
3333

34-
---@private
3534
function Question:create_file()
3635
local lang = utils.get_lang(self.lang)
3736
local alt = lang.alt and ("." .. lang.alt) or ""
@@ -180,17 +179,28 @@ function Question:lines()
180179
return table.concat(lines, "\n", start_i, end_i)
181180
end
182181

182+
---@param self lc.ui.Question
183183
---@param lang lc.lang
184184
Question.change_lang = vim.schedule_wrap(function(self, lang)
185+
local old_lang = self.lang
185186
self.lang = lang
186-
self:create_file()
187187

188-
local new_bufnr = vim.fn.bufadd(self.file:absolute())
188+
local new_bufnr = vim.fn.bufadd(self:create_file())
189189
if new_bufnr ~= 0 then
190+
local bufloaded = vim.fn.bufloaded(new_bufnr)
191+
190192
vim.api.nvim_win_set_buf(self.winid, new_bufnr)
193+
194+
vim.api.nvim_buf_set_option(self.bufnr, "buflisted", false)
195+
vim.api.nvim_buf_set_option(new_bufnr, "buflisted", true)
196+
191197
self.bufnr = new_bufnr
198+
if bufloaded == 0 then --
199+
utils.exec_hooks("LeetQuestionNew", self)
200+
end
192201
else
193202
log.error("Changing language failed")
203+
self.lang = old_lang
194204
end
195205
end)
196206

lua/leetcode.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function leetcode.should_skip(on_vimenter)
1010
if on_vimenter then
1111
if vim.fn.argc() ~= 1 then return true end
1212

13-
local usr_arg, arg = vim.fn.argv()[1], config.user.arg
13+
local usr_arg, arg = config.user.arg, vim.fn.argv()[1]
1414
if usr_arg ~= arg then return true end
1515

1616
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)

0 commit comments

Comments
 (0)