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

Commit fe51320

Browse files
committed
feat: focus results on code run
1 parent 72a0446 commit fe51320

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lua/leetcode-ui/layout/console.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ function ConsoleLayout:mount()
5252
end
5353

5454
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
5659
Runner:init(self.question):run(submit)
5760
end
5861

lua/leetcode/command/init.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,31 +340,31 @@ function cmd.inject()
340340
local q = utils.curr_question()
341341
if not q then return end
342342

343-
if vim.api.nvim_buf_is_valid(q.bufnr) then
343+
if api.nvim_buf_is_valid(q.bufnr) then
344344
local start_i, end_i = q:range(true)
345+
local not_found = {}
345346

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`")
353349
else
354350
local before = q:inject(true)
355351
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"))
357353
end
358354
end
359355

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`")
362358
else
363359
local after = q:inject(false)
364360
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"))
366362
end
367363
end
364+
365+
if not vim.tbl_isempty(not_found) then
366+
log.error(table.concat(not_found, " and ") .. " not found")
367+
end
368368
end
369369
end
370370

0 commit comments

Comments
 (0)