A Neovim plugin enabling you to solve LeetCode problems.
feat: focus `results` on code run
2 files changed, +16 -13
+4-1lua/leetcode-ui/layout/console.lua
| @@ -52,7 +52,10 @@ function ConsoleLayout:mount() | ||
| 52 | 52 | end |
| 53 | 53 | |
| 54 | 54 | function ConsoleLayout:run(submit) |
| 55 | - if config.user.console.open_on_runcode then self:show() end | |
| 55 | + if config.user.console.open_on_runcode then | |
| 56 | + self:show() | |
| 57 | + self.result:focus() | |
| 58 | + end | |
| 56 | 59 | Runner:init(self.question):run(submit) |
| 57 | 60 | end |
| 58 | 61 |
+12-12lua/leetcode/command/init.lua
| @@ -340,31 +340,31 @@ function cmd.inject() | ||
| 340 | 340 | local q = utils.curr_question() |
| 341 | 341 | if not q then return end |
| 342 | 342 | |
| 343 | - if vim.api.nvim_buf_is_valid(q.bufnr) then | |
| 343 | + if api.nvim_buf_is_valid(q.bufnr) then | |
| 344 | 344 | local start_i, end_i = q:range(true) |
| 345 | + local not_found = {} | |
| 345 | 346 | |
| 346 | - if start_i == nil and end_i == nil then | |
| 347 | - log.error("`@leet start` and `@leet end` not found") | |
| 348 | - return | |
| 349 | - end | |
| 350 | - | |
| 351 | - if start_i == nil then | |
| 352 | - log.error("`@leet start` not found") | |
| 347 | + if not start_i then | |
| 348 | + table.insert(not_found, "`@leet start`") | |
| 353 | 349 | else |
| 354 | 350 | local before = q:inject(true) |
| 355 | 351 | if before then |
| 356 | - vim.api.nvim_buf_set_lines(q.bufnr, 0, start_i - 1, false, vim.split(before, "\n")) | |
| 352 | + api.nvim_buf_set_lines(q.bufnr, 0, start_i - 1, false, vim.split(before, "\n")) | |
| 357 | 353 | end |
| 358 | 354 | end |
| 359 | 355 | |
| 360 | - if end_i == nil then | |
| 361 | - log.error("`@leet end` not found") | |
| 356 | + if not end_i then | |
| 357 | + table.insert(not_found, "`@leet end`") | |
| 362 | 358 | else |
| 363 | 359 | local after = q:inject(false) |
| 364 | 360 | if after then |
| 365 | - vim.api.nvim_buf_set_lines(q.bufnr, end_i + 1, -1, false, vim.split(after, "\n")) | |
| 361 | + api.nvim_buf_set_lines(q.bufnr, end_i + 1, -1, false, vim.split(after, "\n")) | |
| 366 | 362 | end |
| 367 | 363 | end |
| 364 | + | |
| 365 | + if not vim.tbl_isempty(not_found) then | |
| 366 | + log.error(table.concat(not_found, " and ") .. " not found") | |
| 367 | + end | |
| 368 | 368 | end |
| 369 | 369 | end |
| 370 | 370 |