Skip to content

Commit c505362

Browse files
committed
fix: promote ordered empty bullets from parent
1 parent dedf1de commit c505362

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎lua/bullets/actions.lua‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ local function spaced_lines(prefix)
364364
return lines, #lines
365365
end
366366

367+
local function previous_bullet_with_indent(lnum, indent)
368+
for row = lnum - 1, 1, -1 do
369+
local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1]
370+
if line:match("^%s*$") then
371+
return nil
372+
end
373+
374+
local previous = resolve_bullet(parse_line(line), row)
375+
if previous and previous.indent == indent then
376+
return previous
377+
end
378+
end
379+
380+
return nil
381+
end
382+
367383
local function delete_empty_bullet(lnum, bullet, mode)
368384
local behavior = config.options.delete_last_bullet_if_empty
369385
if behavior == 0 then
@@ -380,7 +396,8 @@ local function delete_empty_bullet(lnum, bullet, mode)
380396
promoted.indent = promoted.indent
381397
:gsub("\t$", "")
382398
:gsub(string.rep(" ", vim.o.shiftwidth > 0 and vim.o.shiftwidth or vim.o.tabstop) .. "$", "")
383-
local prefix = next_prefix(promoted)
399+
local parent = previous_bullet_with_indent(lnum, promoted.indent)
400+
local prefix = next_prefix(parent or promoted)
384401
vim.api.nvim_set_current_line(prefix or "")
385402
vim.api.nvim_win_set_cursor(0, { lnum, #(prefix or "") })
386403
return true

0 commit comments

Comments
 (0)