Skip to content

Commit 0bb80df

Browse files
authored
fix: keep line after deleting empty bullet (#27)
# Motivation Pressing Return on an empty bullet with `delete_last_bullet_if_empty` enabled removed the whole line, moving the cursor up. The spec now requires the bullet marker to be cleared while keeping the cursor on that line. # Summary of Changes - Route whitespace-only bullet text through the shared empty-bullet handling. - Remove the special-case insert-mode deletion path that used `ddi`. - Update `LC-003` coverage and spec text to assert that the blank line remains. # Testing - `mise run test:spec LC-003` - `mise run test:spec LC-004` - `mise run test:spec LC-005` - `mise run openspec:check` - `mise run test` - `mise run fmt:check` # Dependencies/Special Considerations none
1 parent a3eaa6f commit 0bb80df

3 files changed

Lines changed: 7 additions & 18 deletions

File tree

lua/bullets/actions.lua

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ local function checkbox_continuation_prefix(bullet, prefix)
377377
end
378378

379379
local function is_empty_bullet_text(text)
380-
if text == '' then
380+
if text:match '^%s*$' then
381381
return true
382382
end
383383

@@ -908,17 +908,6 @@ function M.insert_new_bullet()
908908
return ''
909909
end
910910

911-
if bullet.text:match '^%s*$' and config.options.delete_last_bullet_if_empty == 1 then
912-
if mode ~= 'n' then
913-
vim.api.nvim_feedkeys(keys '<Esc>ddi', 'n', false)
914-
return ''
915-
end
916-
917-
vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, {})
918-
vim.cmd.startinsert()
919-
return ''
920-
end
921-
922911
if is_empty_bullet_text(bullet.text) and delete_empty_bullet(lnum, bullet, mode) then
923912
return ''
924913
end

openspec/specs/list-continuation/spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The plugin SHALL handle an empty continued list item according to `delete_last_b
3939
- AND the current line is an empty list item
4040
- WHEN bullet insertion is triggered
4141
- THEN the empty list item is removed
42+
- AND the cursor remains on the same line
4243

4344
#### Scenario: Promote empty item {#LC-004}
4445

test/bullets_spec.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,16 @@ describe('Bullets.vim', function()
220220
helpers.new_buffer {
221221
'# Hello there',
222222
'- this is the first bullet',
223+
'- ',
223224
}
224-
-- First CR creates "- " empty bullet, second CR on empty bullet deletes it
225-
helpers.feedkeys 'A<CR><CR>'
225+
-- CR on empty bullet deletes it
226+
helpers.feedkeys 'A<CR>'
226227
local lines = helpers.get_lines()
227-
-- Strip trailing empty lines before comparison.
228-
while #lines > 0 and lines[#lines] == '' do
229-
table.remove(lines)
230-
end
228+
231229
assert.are.same({
232230
'# Hello there',
233231
'- this is the first bullet',
232+
'', -- cursor should be here, we do not want to remove the line
234233
}, lines)
235234
end)
236235

0 commit comments

Comments
 (0)