Skip to content

fix: make ctrl+d/u scroll half-page instead of full page#25

Merged
umputun merged 7 commits intoumputun:masterfrom
rashpile:fix-ctrl-du-half-page
Apr 5, 2026
Merged

fix: make ctrl+d/u scroll half-page instead of full page#25
umputun merged 7 commits intoumputun:masterfrom
rashpile:fix-ctrl-du-half-page

Conversation

@rashpile
Copy link
Copy Markdown
Contributor

@rashpile rashpile commented Apr 5, 2026

Summary

Splits ctrl+d/ctrl+u from PgDn/PgUp so they scroll half a page, matching vim/less/tmux convention.

Closes #24

What's changed

  • ctrl+d/ctrl+u now scrolls half the viewport height in all three panes (diff, tree, TOC)
  • PgDn/PgUp unchanged — still scrolls full page
  • Help overlay text was already correct ("half-page down / up")

Test plan

  • Unit tests for ctrl+d/u moving half page in diff pane
  • Unit tests for ctrl+d/u moving half page in tree pane
  • Verify PgDn/PgUp still moves full page
  • Full test suite passes

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates key navigation so Ctrl+d / Ctrl+u perform half-page movement while keeping PgDn / PgUp as full-page paging, aligning behavior with common terminal navigators (vim/less/tmux).

Changes:

  • Split Ctrl+d/u handling from PgDn/PgUp in tree, TOC, and diff navigation.
  • Added half-page diff cursor movement helpers and expanded unit tests for new behavior.
  • Updated user-facing docs to describe half-page scrolling for Ctrl+d/u.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ui/model.go Separates Ctrl+d/u from PgDn/PgUp across panes; routes to half-page movement.
ui/diffview.go Introduces half-page diff cursor movement functions.
ui/model_test.go Updates existing paging tests and adds new tests for half-page movement.
README.md Documents Ctrl+d/u as half-page scroll.
.claude-plugin/skills/revdiff/references/usage.md Mirrors README keybinding doc update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice and clean change, thx. one real issue though.

moveDiffCursorHalfPageDown/Up use syncViewportToCursor() which only adjusts viewport when cursor leaves the visible area. with a typical viewport of ~36 lines, first ctrl+d moves cursor to line 18 but viewport stays at offset 0 since line 18 is still visible. in vim/less ctrl+d scrolls both viewport and cursor by half a page simultaneously.

the fix should be straightforward - use explicit YOffset adjustment like the existing full-page functions do, but with halfPage offset instead of viewport.Height. smth like:

// half-page down
m.viewport.SetYOffset(min(m.viewport.YOffset+halfPage, maxOffset))
// half-page up
m.viewport.SetYOffset(max(0, m.viewport.YOffset-halfPage))

also worth adding viewport.YOffset assertions to the half-page tests - currently they only check cursor position, which is why the viewport issue wasn't caught.

btw, Copilot flagged the same thing in inline comments 1, 2 and 5 - those are valid. the other two (about max(1, ...) in tests) are noise since test viewport is always large enough.

rashpile added 7 commits April 5, 2026 22:53
ctrl+d/u now scroll half a page in diff, tree, and TOC panes,
matching vim convention. PgDn/PgUp remain full-page scroll.
- Update README.md and usage.md: ctrl+d/u described as "Half-page scroll" instead of "Page scroll"
- Add changelog entry for half-page scroll fix
- Add missing ctrl+u test case in TestModel_TreeCtrlDUMovesHalfPage
Replace syncViewportToCursor() with explicit YOffset adjustment
so viewport scrolls by half page simultaneously with cursor,
matching vim/less ctrl+d/u behavior.

Add viewport.YOffset assertions to half-page tests.
@rashpile rashpile force-pushed the fix-ctrl-du-half-page branch from 00b02a9 to c72270b Compare April 5, 2026 20:07
@rashpile
Copy link
Copy Markdown
Contributor Author

rashpile commented Apr 5, 2026

Rebased on latest master.

Fixed the viewport scrolling issue — good catch. syncViewportToCursor() only adjusts when cursor leaves the visible area, so the first ctrl+d would move the cursor but the viewport stayed put.

Now both moveDiffCursorHalfPageDown/Up use explicit SetYOffset adjustment (like the full-page functions do), so cursor and viewport scroll simultaneously by half a page.

Added viewport.YOffset assertions to both ctrl+d and ctrl+u tests to prevent regressions.

Copy link
Copy Markdown
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, viewport scrolling fix looks correct. thx

@umputun umputun merged commit 4ede187 into umputun:master Apr 5, 2026
1 check passed
@rashpile rashpile deleted the fix-ctrl-du-half-page branch April 6, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: ctrl+d/u should scroll half-page, not full page

3 participants