fix(lists): skip own indent in smart_return when auto-indent is active
CI / cargo fmt --check (push) Failing after 22s
CI / cargo clippy (push) Successful in 1m0s
CI / cargo test (push) Successful in 1m30s
CI / editor keymaps (push) Successful in 1m50s

nvim defaults autoindent=on, so the indent inserted by Vim/Nvim after
the <CR> we return was being doubled by our own indent prefix —
pressing Enter on a sub-item produced a deeper-nested item instead of
a same-level one. Detect any auto-indent mechanism (autoindent,
smartindent, cindent, indentexpr) and let it own the indentation;
otherwise add it ourselves so vim's noautoindent default still works.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 15:01:21 +00:00
parent bcb32777fb
commit 7a0cec4920
2 changed files with 15 additions and 2 deletions
+9 -1
View File
@@ -790,7 +790,15 @@ function M.smart_return()
-- "break out of the list" behaviour on an empty bullet).
return esc .. '0DA' .. cr
end
return cr .. indent .. marker .. ' ' .. (cb and '[ ] ' or '')
-- nvim defaults `autoindent=on`, which inserts the previous line's
-- indent right after the `<CR>` we return. If we then add our own
-- `indent`, the new bullet is pushed one level deeper than the one
-- the user is continuing. Skip our copy whenever any auto-indent
-- mechanism is active and let Vim/Nvim insert the indent for us.
local auto = vim.bo.autoindent or vim.bo.smartindent or vim.bo.cindent
or (vim.bo.indentexpr ~= nil and vim.bo.indentexpr ~= '')
local effective_indent = auto and '' or indent
return cr .. effective_indent .. marker .. ' ' .. (cb and '[ ] ' or '')
end
return cr
end