Skip to content

Commit

Permalink
feat: focus results on code run
Browse files Browse the repository at this point in the history
  • Loading branch information
kawre committed Feb 28, 2024
1 parent 72a0446 commit fe51320
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 4 additions & 1 deletion lua/leetcode-ui/layout/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function ConsoleLayout:mount()
end

function ConsoleLayout:run(submit)
if config.user.console.open_on_runcode then self:show() end
if config.user.console.open_on_runcode then
self:show()
self.result:focus()
end
Runner:init(self.question):run(submit)
end

Expand Down
24 changes: 12 additions & 12 deletions lua/leetcode/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,31 +340,31 @@ function cmd.inject()
local q = utils.curr_question()
if not q then return end

if vim.api.nvim_buf_is_valid(q.bufnr) then
if api.nvim_buf_is_valid(q.bufnr) then
local start_i, end_i = q:range(true)
local not_found = {}

if start_i == nil and end_i == nil then
log.error("`@leet start` and `@leet end` not found")
return
end

if start_i == nil then
log.error("`@leet start` not found")
if not start_i then
table.insert(not_found, "`@leet start`")
else
local before = q:inject(true)
if before then
vim.api.nvim_buf_set_lines(q.bufnr, 0, start_i - 1, false, vim.split(before, "\n"))
api.nvim_buf_set_lines(q.bufnr, 0, start_i - 1, false, vim.split(before, "\n"))
end
end

if end_i == nil then
log.error("`@leet end` not found")
if not end_i then
table.insert(not_found, "`@leet end`")
else
local after = q:inject(false)
if after then
vim.api.nvim_buf_set_lines(q.bufnr, end_i + 1, -1, false, vim.split(after, "\n"))
api.nvim_buf_set_lines(q.bufnr, end_i + 1, -1, false, vim.split(after, "\n"))
end
end

if not vim.tbl_isempty(not_found) then
log.error(table.concat(not_found, " and ") .. " not found")
end
end
end

Expand Down

0 comments on commit fe51320

Please sign in to comment.