irongit

A Neovim plugin enabling you to solve LeetCode problems.

refactor: reset code on open by default

kawreauthored
parent 144c5b6commit 7cec0d37bad6258d73f2cc2c2f33ffdee9324327Browse files

5 files changed, +17 -31

+3-9lua/leetcode-ui/question.lua
@@ -48,14 +48,10 @@ function Question:set_lines(code)
4848 end
4949
5050 function Question:reset_lines()
51- if not self.reset then
52- return
53- end
54-
5551 local new_lines = self:snippet(true) or ""
5652
5753 vim.schedule(function() --
58- log.info("Previous code found and reseted\nTo undo, simply press `u`")
54+ log.info("Previous code found and reset\nTo undo, simply press `u`")
5955 end)
6056
6157 self:set_lines(new_lines)
@@ -315,14 +311,12 @@ Question.change_lang = vim.schedule_wrap(function(self, lang)
315311 end)
316312
317313 ---@param problem lc.cache.Question
318----@param reset boolean
319-function Question:init(problem, reset)
314+function Question:init(problem)
320315 self.cache = problem
321316 self.lang = config.lang
322- self.reset = reset and true or false
323317 end
324318
325----@type fun(question: lc.cache.Question, reset?: boolean): lc.ui.Question
319+---@type fun(question: lc.cache.Question): lc.ui.Question
326320 local LeetQuestion = Question
327321
328322 return LeetQuestion
+4-4lua/leetcode-ui/renderer/menu.lua
@@ -154,11 +154,11 @@ function Menu:unmount()
154154
155155 require("leetcode.command").q_close_all()
156156
157- if self.winid and vim.api.nvim_win_is_valid(self.winid) then
158- vim.api.nvim_win_close(self.winid, true)
159- end
160-
161157 vim.schedule(function()
158+ if self.winid and vim.api.nvim_win_is_valid(self.winid) then
159+ vim.api.nvim_win_close(self.winid, true)
160+ end
161+
162162 if self.bufnr and vim.api.nvim_buf_is_valid(self.bufnr) then
163163 vim.api.nvim_buf_delete(self.bufnr, { force = true })
164164 end
+2-2lua/leetcode/command/init.lua
@@ -140,7 +140,7 @@ function cmd.qot()
140140 return log.err(err)
141141 end
142142 local problemlist = require("leetcode.cache.problemlist")
143- Question(problemlist.get_by_title_slug(qot.title_slug), true):mount()
143+ Question(problemlist.get_by_title_slug(qot.title_slug)):mount()
144144 end)
145145 end
146146
@@ -168,7 +168,7 @@ function cmd.random_question(opts)
168168
169169 local item = problems.get_by_title_slug(q.title_slug) or {}
170170 local Question = require("leetcode-ui.question")
171- Question(item, true):mount()
171+ Question(item):mount()
172172 end
173173
174174 function cmd.start_with_cmd()
+6-7lua/leetcode/config/hooks.lua
@@ -2,15 +2,14 @@
22 local hooks = {}
33
44 hooks["question_enter"] = {
5- vim.schedule_wrap(function(q)
5+ function(q)
66 -- https://github.com/kawre/leetcode.nvim/issues/14
7- if q.lang ~= "rust" then
8- return
7+ if q.lang == "rust" then
8+ pcall(function()
9+ require("rust-tools.standalone").start_standalone_client()
10+ end)
911 end
10- pcall(function()
11- require("rust-tools.standalone").start_standalone_client()
12- end)
13- end),
12+ end,
1413 }
1514
1615 return hooks
+2-9lua/leetcode/pickers/question.lua
@@ -128,7 +128,7 @@ return {
128128 }),
129129 sorter = conf.generic_sorter(theme),
130130 attach_mappings = function(prompt_bufnr, map)
131- local function mount_question(reset)
131+ actions.select_default:replace(function()
132132 local selection = action_state.get_selected_entry()
133133 if not selection then
134134 return
@@ -140,14 +140,7 @@ return {
140140 end
141141
142142 actions.close(prompt_bufnr)
143- Question(q, reset):mount()
144- end
145-
146- actions.select_default:replace(function()
147- mount_question()
148- end)
149- map({ "n", "i" }, "<C-Enter>", function()
150- mount_question(true)
143+ Question(q):mount()
151144 end)
152145
153146 return true