A Neovim plugin enabling you to solve LeetCode problems.
fix(hooks): change `question_enter` order
1 file changed, +10 -14
+10-14lua/leetcode-ui/question.lua
| @@ -82,16 +82,15 @@ function Question:create_buffer() | ||
| 82 | 82 | local path, existed = self:path() |
| 83 | 83 | |
| 84 | 84 | vim.cmd("$tabe " .. path) |
| 85 | - | |
| 86 | 85 | self.bufnr = vim.api.nvim_get_current_buf() |
| 87 | 86 | self.winid = vim.api.nvim_get_current_win() |
| 88 | 87 | |
| 89 | - self:open_buffer(existed, false) | |
| 88 | + self:open_buffer(existed) | |
| 90 | 89 | end |
| 91 | 90 | |
| 92 | 91 | ---@param existed boolean |
| 93 | ----@param loaded boolean | |
| 94 | -function Question:open_buffer(existed, loaded) | |
| 92 | +function Question:open_buffer(existed) | |
| 93 | + vim.api.nvim_win_set_buf(self.winid, self.bufnr) | |
| 95 | 94 | vim.api.nvim_set_option_value("buflisted", true, { buf = self.bufnr }) |
| 96 | 95 | |
| 97 | 96 | local i = self:fold_range() |
| @@ -102,11 +101,6 @@ function Question:open_buffer(existed, loaded) | ||
| 102 | 101 | if existed then -- |
| 103 | 102 | self:reset_lines() |
| 104 | 103 | end |
| 105 | - | |
| 106 | - if not loaded then | |
| 107 | - utils.exec_hooks("question_enter", self) | |
| 108 | - self:autocmds() | |
| 109 | - end | |
| 110 | 104 | end |
| 111 | 105 | |
| 112 | 106 | ---@param before boolean |
| @@ -191,12 +185,15 @@ end | ||
| 191 | 185 | function Question:handle_mount() |
| 192 | 186 | self:create_buffer() |
| 193 | 187 | |
| 194 | - table.insert(_Lc_state.questions, self) | |
| 195 | - | |
| 196 | 188 | self.description = Description(self):mount() |
| 197 | 189 | self.console = Console(self) |
| 198 | 190 | self.info = Info(self) |
| 199 | 191 | |
| 192 | + table.insert(_Lc_state.questions, self) | |
| 193 | + | |
| 194 | + self:autocmds() | |
| 195 | + utils.exec_hooks("question_enter", self) | |
| 196 | + | |
| 200 | 197 | return self |
| 201 | 198 | end |
| 202 | 199 | |
| @@ -281,11 +278,10 @@ Question.change_lang = vim.schedule_wrap(function(self, lang) | ||
| 281 | 278 | local loaded = vim.api.nvim_buf_is_loaded(self.bufnr) |
| 282 | 279 | vim.fn.bufload(self.bufnr) |
| 283 | 280 | |
| 284 | - vim.api.nvim_win_set_buf(self.winid, self.bufnr) | |
| 285 | - | |
| 286 | 281 | vim.api.nvim_set_option_value("buflisted", false, { buf = old_bufnr }) |
| 282 | + self:open_buffer(existed) | |
| 287 | 283 | |
| 288 | - self:open_buffer(existed, loaded) | |
| 284 | + if not loaded then utils.exec_hooks("question_enter", self) end | |
| 289 | 285 | end) |
| 290 | 286 | |
| 291 | 287 | if not ok then |