refactor: reactive refresh architecture for hunk staging (#283)#311
Merged
esmuellert merged 3 commits intomainfrom Mar 7, 2026
Merged
refactor: reactive refresh architecture for hunk staging (#283)#311esmuellert merged 3 commits intomainfrom
esmuellert merged 3 commits intomainfrom
Conversation
…line When toggling from side-by-side to inline mode, ns_highlight extmarks from the side-by-side renderer remained on the buffer. inline_view.update() only cleared ns_inline via inline.clear(), leaving orphaned highlights visible after staging/unstaging hunks. Use lifecycle.clear_highlights() which clears all four namespaces (ns_highlight, ns_filler, ns_conflict, ns_inline), matching what side_by_side.update() already does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace manual view.update/explorer.refresh calls in stage_hunk, unstage_hunk, and discard_hunk with a single reactive data flow: .git watcher → sync_mutable_buffers → auto_refresh → diff recompute Changes: - New sync_mutable_buffers() in auto_refresh.lua: fetches :0 content from git, compares with buffer, writes only if changed, triggers diff recomputation. Handles readonly/nowrite virtual buffers. - .git watcher debounced callback calls sync_mutable_buffers alongside explorer.refresh (tree rebuild) - Enable auto_refresh for all buffers (remove virtual buffer guards) - Keymaps: stage/unstage/discard just do git operation + notify - Refresh re-selection: only calls on_file_select when group or comparison base (HEAD vs :0) changes - Guard check: detects HEAD→:0 revision switch for partially staged files - inline_view: lifecycle.clear_highlights for namespace cleanup on toggle - Removed 4 overlapping tests, added 10 strict E2E keymap-driven tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Pass no_jump flag from refresh re-selection to on_file_select so cursor position is preserved during watcher-triggered updates - Stage hunk only allowed from unstaged view (modified_revision == nil) - Unstage hunk only allowed from staged view (modified_revision == ':0') - Prevents staging already-staged hunks (fixes #283) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 7, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the manual refresh wiring in stage/unstage/discard hunk operations with a reactive architecture where the
.gitwatcher is the single source of truth.Root Cause
The staging system had no clear ownership for "who refreshes what after a git operation." A single
stage_hunktriggered up to 3 concurrentview.update()calls that raced against each other, causing stale highlights, flickering, and missing refreshes.Architecture Change
Keymaps just do the git operation + notify. Zero refresh logic.
Changes
Core
sync_mutable_buffers()inauto_refresh.lua: fetches:0content from git, compares with buffer, writes only if changed. Handles readonly/nowrite virtual buffers..gitwatcher debounced callback callssync_mutable_buffersalongsideexplorer.refreshauto_refreshfor all buffers (removed virtual buffer guards)Simplifications
explorer.refresh(),view.update(), stale captures, last-hunk branches)on_file_selectwhen group or comparison base changes (HEAD→:0)no_jumpflag)lifecycle.clear_highlights()in inline_view for namespace cleanup on toggleTests
hunk_operations_spec.lua)stale_buffer_spec.lua: removed 4 overlapping tests, kept 3 welcome page testsNet
~100 lines added, ~260 lines removed. Single refresh path, no more racing.
Fixes