@@ -61,8 +61,6 @@ function M.setup_keymaps(keymaps, commands_enabled, file_types)
61
61
mode = " v" , -- Visual mode only
62
62
key = keymaps .insert_code_block ,
63
63
cmd = function ()
64
- -- Still need Lua for prompt, exit visual first
65
- vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (" <Esc>" , true , false , true ), " n" , false )
66
64
require (" markdown-tools.commands" ).insert_code_block ({ range = 2 })
67
65
end ,
68
66
desc = " Code block (Visual)" ,
@@ -155,25 +153,14 @@ function M.setup_keymaps(keymaps, commands_enabled, file_types)
155
153
},
156
154
{
157
155
command_key = " insert_checkbox" ,
158
- mode = " n" , -- Normal mode only
159
- key = keymaps .insert_checkbox ,
160
- cmd = function ()
161
- require (" markdown-tools.commands" ).insert_checkbox ()
162
- end ,
163
- desc = " Checkbox (Normal)" ,
164
- },
165
- {
166
- command_key = " insert_checkbox" ,
167
- mode = " v" , -- Visual mode only
156
+ mode = { " n" , " v" },
168
157
key = keymaps .insert_checkbox ,
169
- -- Call the Lua function directly, which handles line insertion
170
158
cmd = function ()
171
- -- Exit visual mode before calling the command
159
+ -- Esc first, in case in visual mode.
172
160
vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (" <Esc>" , true , false , true ), " n" , false )
173
161
require (" markdown-tools.commands" ).insert_checkbox ()
174
162
end ,
175
- desc = " Checkbox" , -- Updated description
176
- opts = nil , -- Remove remap = true, no longer needed
163
+ desc = " Checkbox" ,
177
164
},
178
165
{
179
166
command_key = " toggle_checkbox" , -- Renamed key
@@ -207,30 +194,12 @@ function M.setup_keymaps(keymaps, commands_enabled, file_types)
207
194
208
195
-- Add keymap for continuing lists on Enter if enabled (buffer-local)
209
196
if require (" markdown-tools.config" ).options .continue_lists_on_enter then
210
- vim .keymap .set (" i" , " <CR>" , function ()
211
- local line = vim .api .nvim_get_current_line ()
212
- local _ , cursor_col = unpack (vim .api .nvim_win_get_cursor (0 ))
213
-
214
- -- Define separate patterns for each list type
215
- local pattern_bullet = " ^%s*[-*+]%s+"
216
- local pattern_numbered = " ^%s*%d+%.%s+"
217
- local pattern_checkbox = " ^%s*[-*+] %[[ x]%]%s+"
218
-
219
- -- Check if cursor is at end and any pattern matched
220
- local is_list_end = cursor_col == # line
221
- and (line :match (pattern_bullet ) or line :match (pattern_numbered ) or line :match (pattern_checkbox ))
222
-
223
- if is_list_end then
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>
229
- else
230
- -- Otherwise, let Neovim handle <CR> as default
231
- return vim .api .nvim_replace_termcodes (" <CR>" , true , true , true )
232
- end
233
- end , { buffer = true , desc = " Continue Markdown List" , expr = true })
197
+ vim .keymap .set (
198
+ " i" ,
199
+ " <CR>" ,
200
+ require (" markdown-tools.lists" ).keymap_init ,
201
+ { buffer = true , desc = " Continue Markdown List" , expr = true }
202
+ )
234
203
end
235
204
end ,
236
205
})
0 commit comments