Skip to content

Commit c5249aa

Browse files
authored
fix: org_meta_return on checkbox item (#568)
1 parent 3d6acc6 commit c5249aa

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

lua/orgmode/org/mappings.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ function OrgMappings:handle_return(suffix)
571571
vim.cmd([[normal! ^]])
572572
item = Files.get_current_file():get_current_node()
573573
end
574-
if item.type == 'paragraph' or item.type == 'bullet' then
574+
if item.type == 'paragraph' or item.type == 'bullet' or item.type == 'checkbox' or item.type == 'status' then
575575
local listitem = item.node:parent()
576576
if listitem:type() ~= 'listitem' then
577577
return

tests/plenary/ui/mappings_spec.lua

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,23 +442,61 @@ describe('Mappings', function()
442442
'',
443443
'* TODO Test orgmode',
444444
' - Regular item',
445-
' - Second recular item',
445+
' - Second regular item',
446446
' - Nested item',
447+
' - [x] Checkbox item',
448+
' - [x] Second checkbox item',
449+
' - [x] Nested checkbox item',
447450
})
448451

449452
assert.are.same({
450453
' - Regular item',
451-
' - Second recular item',
454+
' - Second regular item',
452455
' - Nested item',
453-
}, vim.api.nvim_buf_get_lines(0, 3, 6, false))
456+
' - [x] Checkbox item',
457+
' - [x] Second checkbox item',
458+
' - [x] Nested checkbox item',
459+
}, vim.api.nvim_buf_get_lines(0, 3, 9, false))
460+
461+
-- test for plain list item
454462
vim.fn.cursor(4, 1)
455463
vim.cmd([[exe "norm ,\<CR>"]])
456464
assert.are.same({
457465
' - Regular item',
458466
' - ',
459-
' - Second recular item',
467+
' - Second regular item',
460468
' - Nested item',
461-
}, vim.api.nvim_buf_get_lines(0, 3, 7, false))
469+
' - [x] Checkbox item',
470+
' - [x] Second checkbox item',
471+
' - [x] Nested checkbox item',
472+
}, vim.api.nvim_buf_get_lines(0, 3, 10, false))
473+
474+
-- tests for checkbox item
475+
vim.fn.cursor(8, 7) -- on the opening bracket
476+
vim.cmd([[exe "norm ,\<CR>"]])
477+
assert.are.same({
478+
' - Regular item',
479+
' - ',
480+
' - Second regular item',
481+
' - Nested item',
482+
' - [x] Checkbox item',
483+
' - [ ] ',
484+
' - [x] Second checkbox item',
485+
' - [x] Nested checkbox item',
486+
}, vim.api.nvim_buf_get_lines(0, 3, 11, false))
487+
vim.fn.cursor(8, 8) -- on the 'x' (a.k.a. status)
488+
vim.cmd([[exe "norm ,\<CR>"]])
489+
assert.are.same({
490+
' - Regular item',
491+
' - ',
492+
' - Second regular item',
493+
' - Nested item',
494+
' - [x] Checkbox item',
495+
' - [ ] ',
496+
' - [ ] ',
497+
' - [x] Second checkbox item',
498+
' - [x] Nested checkbox item',
499+
}, vim.api.nvim_buf_get_lines(0, 3, 12, false))
462500
end)
463501

464502
it('should add list item with blank line with Enter (org_meta_return)', function()
@@ -473,13 +511,13 @@ describe('Mappings', function()
473511
'',
474512
'* TODO Test orgmode',
475513
' - Regular item',
476-
' - Second recular item',
514+
' - Second regular item',
477515
' - Nested item',
478516
})
479517

480518
assert.are.same({
481519
' - Regular item',
482-
' - Second recular item',
520+
' - Second regular item',
483521
' - Nested item',
484522
}, vim.api.nvim_buf_get_lines(0, 3, 6, false))
485523
vim.fn.cursor(4, 1)
@@ -488,7 +526,7 @@ describe('Mappings', function()
488526
' - Regular item',
489527
'',
490528
' - ',
491-
' - Second recular item',
529+
' - Second regular item',
492530
' - Nested item',
493531
}, vim.api.nvim_buf_get_lines(0, 3, 8, false))
494532
config:extend({

0 commit comments

Comments
 (0)