Skip to content

Commit fa12cbe

Browse files
authored
fix: enter was broken on non-bullet lines, now fixed (#16)
1 parent d5cc8bf commit fa12cbe

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lua/markdown-tools/keymaps.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,16 @@ function M.setup_keymaps(keymaps, commands_enabled, file_types)
221221
and (line:match(pattern_bullet) or line:match(pattern_numbered) or line:match(pattern_checkbox))
222222

223223
if is_list_end then
224-
-- If it is, call the list continuation function directly
225-
require("markdown-tools.lists").continue_list_on_enter()
224+
-- If it is, schedule the list continuation function to run soon
225+
vim.schedule(function()
226+
require("markdown-tools.lists").continue_list_on_enter()
227+
end)
228+
return "" -- Handled: tell Neovim to do nothing further for this <CR>
226229
else
227-
-- Otherwise, insert a literal newline
228-
vim.api.nvim_input("<CR>")
230+
-- Otherwise, let Neovim handle <CR> as default
231+
return vim.api.nvim_replace_termcodes("<CR>", true, true, true)
229232
end
230-
end, { buffer = true, desc = "Continue Markdown List" })
233+
end, { buffer = true, desc = "Continue Markdown List", expr = true })
231234
end
232235
end,
233236
})

lua/markdown-tools/lists.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function M.continue_list_on_enter()
3838
-- if it's a list line and cursor is at the end. So, marker_type should exist.
3939
if not marker_type then
4040
-- Fallback just in case: insert a normal newline
41-
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<CR>", true, false, true), "n", false)
41+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<CR>", true, false, true), "i", false)
4242
return
4343
end
4444

0 commit comments

Comments
 (0)