Feature/Hunk mode - add to stage & revert block actions#15
Closed
fcmiranda wants to merge 19 commits into
Closed
Conversation
Adds a per-hunk revert affordance on unstaged file diffs. In the Files panel, <c-j>/<c-k> cycle through hunks, <enter> reverts the selected hunk, and clicking the marker glyph in the divider column reverts that hunk directly. Hunks are reverted via `git apply --reverse` against the worktree, scoped to one hunk at a time.
Show "enter Revert hunk" tooltip beside the marker glyph when the mouse hovers over it, mirroring the AI-generate button's tooltip pattern. The tooltip overlays the right diff panel on the marker's row only while the cursor is on the divider column at a hunk start.
Replace the Enter handler with a dedicated `<c-r>` keybinding for
reverting the currently selected (or hovered) hunk. Also update the
hover tooltip to show `c-r Revert hunk`. Enter no longer triggers
revert — `<c-r>` is the single source of truth for the action key.
feat(diff): hover color + diff-focused status bar hints
- Revert-hunk marker now uses accent_secondary on mouse hover (matching
the AI sparkle's hover pattern), distinct from accent (selected via
c-j/c-k cycle) and separator (default).
- Status bar shows a tighter, diff-focused hint set when the diff panel
has focus: {/} prev/next hunk, [/] side view, and on Files context
c-j/c-k cycle + c-r revert. The c-r key is highlighted when a hunk
is selected so the action is more discoverable.
feat(diff): only surface c-r when a hunk is selected
c-r is now hidden from the status bar unless `selected_revert_hunk` is
set, and is prepended as the first hint when present. Pressing c-r
without a selection is a no-op so showing it always was noise — it
appears only when the action will actually do something.
fix(diff): don't scroll on c-j/c-k if hunk already visible
center_selected_revert_block was unconditionally re-centering the diff
on every cycle, which is jarring when the target hunk is already in
the viewport. Only scroll when the hunk's start row is outside the
visible range.
feat(diff): group c-r and c-j/c-k revert hints together
Move the cycle keys (c-j/c-k) next to c-r at the front of the status
bar so the revert action and its cycle keys read as one cluster
instead of being split across the line.
fix(diff): show hover feedback even when revert hunk is already selected
Previously the selected color (accent) overrode hover styling, so
hovering a hunk that was already selected via c-j/c-k showed no visual
change. Add an UNDERLINED modifier on hover that stacks with whichever
fg color is in effect, so the marker reacts to the cursor in every
state.
fix(diff): use bg fill for hover so it shows even when hunk is selected
UNDERLINED didn't render reliably on the Nerd Font marker glyph in
many terminals. Switch to a selected_bg background fill on hover —
visible regardless of fg color and terminal capabilities, including
when a hunk is already selected (accent fg + selected_bg fill).
fix(diff): make hover unambiguously visible via REVERSED
The selected_bg fill blended too subtly with the selected accent fg —
hovering a focused hunk looked nearly identical to just being focused.
Use REVERSED to invert fg/bg on hover; the marker reads as a high-
contrast highlight regardless of which fg color is currently active.
fix(diff): solid bg fill on hover + drop c-r tooltip when not selected
Hover now paints the marker as a solid colored cell (fg ↔ bg with
panel background). Visually unmistakable in any terminal — including
when the hunk is already selected, where the previous REVERSED/bg
tweaks were too subtle.
Tooltip text drops the c-r keybind when the hovered hunk isn't the
selected one, since pressing c-r in that state is misleading. Falls
back to a plain "Revert hunk" label.
fix(diff): paint full divider gap with hover bg
Single-cell bg fill was easy to miss against the surrounding panel
background — fill both columns of the divider gap with the hover bg
so the marker reads as a clearly-coloured pill against the diff.
Also fixes the second render path which was still on UNDERLINED.
fix(diff): hover changes only the icon color, no bg fill
Drop the colored bg pill — hover now switches the marker fg to
text_strong, which wins over both the selected accent and default
separator colors. Selected stays accent when not hovered, default is
separator. Hover is visible in every state because the icon color
itself changes; nothing else in the divider gap is touched.
fix(diff): use accent_secondary for hover so it matches tooltip key color
Hover color was text_strong (off-white). Switch to accent_secondary so
the hovered marker reads in the same yellow as the c-r shortcut key
text inside the tooltip — visually links the two.
- Change revert_block keybinding from <c-r> to <enter> - Update Escape handler to clear hunk selection before search - Update status bar hints and tooltips accordingly
…igation
- Removed non-functional Ctrl+J/K hunk navigation in favor of configurable { and }
- Updated { and } navigation to automatically select the target hunk, enabling keyboard-only revert without mouse hover
- Removed fixed KeyCode::Char('{')/('}') handlers in favor of keybinding config
Keep keyboard-only revert flow intact after applying a hunk by auto-selecting the nearest remaining hunk on refresh. Also let users override the revert marker icon, weight, and colors from config without changing the active theme.
When a revert refresh selects the nearest remaining hunk, recenter it if it lands outside the current viewport so keyboard-only revert keeps the active target visible.
Use a dedicated revert key in hunk mode so Enter is no longer overloaded in the diff view. Update the files help and status hints to advertise r as the single keyboard action for reverting the selected hunk.
- Renamed `RevertHunkMarkerConfig` to `HunkMarkerConfig` and updated all references. - Updated `GuiConfig` to use the new `HunkMarkerConfig`. - Refactored `GitCommands` to use `build_hunk_patch` instead of `build_patch`. - Changed GUI logic to handle hunk actions instead of revert actions, including renaming variables and methods for clarity. - Updated rendering logic to display hunk markers instead of revert markers. - Adjusted undo functionality to track hunk actions instead of revert actions. - Modified tooltip rendering to reflect hunk actions for staging and reverting.
feat(gui): add hunk mode with navigation, refactor markers and improve UX
22d0113 to
f918338
Compare
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
@Blankeos I have implemented several improvements on top of
feature/revert-block-clean:New Features
7f31007)bb2f672)Refactoring
cf69f2b)rkey for consistency (0db65e2)Fixes
352a834)H : enter into hunk mode
esc: exit hunk mode
Hunk mode:
j: next hunk
k: previous hunk
a: add to stage
r: revert
u: undo (undo previous action)
Let me know what do you think!
Changed Files
src/config/keybindings.rs— keybinding updatessrc/config/mod.rs/src/config/user_config.rs— config adjustmentssrc/git/staging.rs— staging logic improvementssrc/gui/mod.rs— hunk mode implementationsrc/gui/controller/diff_mode.rs— diff mode controller updatessrc/gui/presentation/diff_mode.rs— presentation layer updatessrc/gui/views.rs— view updatessrc/pager/side_by_side.rs— side-by-side pager refactor