fix(init): guard view, undo, and filter against dirty buffer

Problem: `toggle_view`, `undo_write`, and `filter` all call
`buffer.render()` which rewrites the buffer from the store, silently
discarding any unsaved edits. The previous `require_saved()` change
missed these three entry points.

Solution: Add `require_saved()` to the `view` and `filter` keymap
lambdas and to `M.undo_write()`. Also guard `M.filter()` directly so
`:Pending filter` from the command line is covered too.
This commit is contained in:
Barrett Ruth 2026-03-06 12:00:15 -05:00
parent 23ae390f23
commit edd1750a0e

View file

@ -185,6 +185,9 @@ end
---@param pred_str string
---@return nil
function M.filter(pred_str)
if not require_saved() then
return
end
if pred_str == 'clear' or pred_str == '' then
buffer.set_filter({}, {})
local bufnr = buffer.bufnr()
@ -253,6 +256,9 @@ function M._setup_buf_mappings(bufnr)
M.toggle_complete()
end,
view = function()
if not require_saved() then
return
end
buffer.toggle_view()
end,
priority = function()
@ -265,6 +271,9 @@ function M._setup_buf_mappings(bufnr)
M.undo_write()
end,
filter = function()
if not require_saved() then
return
end
vim.ui.input({ prompt = 'Filter: ' }, function(input)
if input then
M.filter(input)
@ -380,6 +389,9 @@ end
---@return nil
function M.undo_write()
if not require_saved() then
return
end
local s = get_store()
local stack = s:undo_stack()
if #stack == 0 then