From edd1750a0ec2547c56b2f74fbe598d73ffb2f169 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Mar 2026 12:00:15 -0500 Subject: [PATCH] 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. --- lua/pending/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/pending/init.lua b/lua/pending/init.lua index d25b100..f89ffe1 100644 --- a/lua/pending/init.lua +++ b/lua/pending/init.lua @@ -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