From 4901706b9818bac869d297cc10f9cd4b819e4bc8 Mon Sep 17 00:00:00 2001 From: Akrm Al-Hakimi Date: Thu, 23 Jul 2026 13:49:11 -0400 Subject: [PATCH] fix: sync session hunk status with native undo/redo Undoing an accepted hunk reverted the buffer and diff overlay but left the session log showing "accepted", so the sidebar was stale. Reconcile the session in sync_undo_state: undo marks the applied hunks pending again, redo re-marks them accepted. Only hunks applied in that step (present pre-accept, gone post-accept) are touched, covering accept_all without mislabeling rejected or superseded hunks. --- lua/jumpy/navigate.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lua/jumpy/navigate.lua b/lua/jumpy/navigate.lua index c0446b4..55ec6d5 100644 --- a/lua/jumpy/navigate.lua +++ b/lua/jumpy/navigate.lua @@ -32,6 +32,29 @@ local function same_lines(a, b) return vim.deep_equal(a, b) end +--- Hunk indices an accept step applied: present in the pre-accept snapshot but +--- gone from the post-accept one (they were written into the buffer + cleared). +local function applied_hunk_idxs(entry) + local before = (entry.before_state and entry.before_state.hunks) or {} + local after = (entry.after_state and entry.after_state.hunks) or {} + local idxs = {} + for idx, hunk in pairs(before) do + if hunk and not after[idx] then + idxs[#idxs + 1] = idx + end + end + return idxs +end + +--- Keep the session log in step with native undo/redo: undoing an accept puts +--- those hunks back to "pending" (the change is no longer applied); redoing it +--- marks them "accepted" again. +local function reconcile_session(bufnr, entry, status) + for _, idx in ipairs(applied_hunk_idxs(entry)) do + session.mark_hunk(bufnr, idx, status) + end +end + local function sync_undo_state(bufnr) if syncing_undo[bufnr] or not vim.api.nvim_buf_is_valid(bufnr) then return @@ -50,6 +73,7 @@ local function sync_undo_state(bufnr) render.restore(bufnr, entry.before_state) restore_offsets(bufnr, entry.before_offsets) syncing_undo[bufnr] = nil + reconcile_session(bufnr, entry, "pending") M._refresh_quickfix() return end @@ -58,6 +82,7 @@ local function sync_undo_state(bufnr) render.restore(bufnr, entry.after_state) restore_offsets(bufnr, entry.after_offsets) syncing_undo[bufnr] = nil + reconcile_session(bufnr, entry, "accepted") M._refresh_quickfix() return end