Skip to content

feat(editor): remember counted half-page scrolling - #432

Merged
fcoury merged 5 commits into
mainfrom
explore/count-scroll
Nov 3, 2026
Merged

fcoury merged 5 commits into
mainfrom
explore/count-scroll

Conversation

@fcoury

@fcoury fcoury commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Neovim's [count]CTRL-D and [count]CTRL-U do more than jump half a page. A count sets the window-local 'scroll' option, and later plain CTRL-D / CTRL-U reuse that distance. The cursor moves the same number of lines and keeps its screen row until the start or end of the file, where CTRL-D lands on the last line. CTRL-Y and CTRL-E then nudge the view by one line and leave the cursor put until it would leave the screen.

Red already had HalfPageDown / HalfPageUp and a count prefix. This extends that path instead of adding a second one. Each window remembers the distance from the last counted Ctrl-D or Ctrl-U. With no count yet, the distance is half the window height. A resize, or any other change to that window's content height, drops the remembered value so the next plain press is half the new height again. The cursor keeps its screen row; near the end of the file Ctrl-D moves it to the last line and leaves the viewport where it is.

Ctrl-Y is ScrollLineUp. It scrolls the view up [count] lines (default 1) and does not move the cursor unless the cursor would leave the scrolloff margin. Neovim's scroll-down is CTRL-E, and that key already toggles the file tree. Alt-E is the default for ScrollLineDown. It is unbound in normal mode, so Ctrl-E stays NeoTree, and it keeps the E mnemonic ("extra" lines) from Neovim. Both actions take [count], use 0 in the keymap to mean the default of one line, and can be remapped in [keys.normal].

Soft-wrapped continuations count as screen rows, so a long line does not jump a whole buffer line per count. Red has no folds, so a count never skips a hidden line. Inline comment cards and Markdown table projections insert virtual rows; a step follows the next source segment, which can cover more than one terminal row while those decorations are on screen.

The recording unsets NO_COLOR and uses Catppuccin Mocha, so syntax highlighting, the status line, and the Nerd Font icon stay in color.

Colored still: Catppuccin Mocha syntax, blue status line, Rust icon

5 Ctrl-D, then Ctrl-D, Ctrl-U, Ctrl-Y, and Alt-E

How to Test

git fetch && git checkout explore/count-scroll
cargo run -- <file>

In normal mode:

  1. 5 then Ctrl-D. The view and cursor move 5 lines, and the cursor stays on the same screen row.
  2. Ctrl-D again. It moves another 5 lines, not half the window.
  3. Ctrl-U. It moves back 5 lines.
  4. Near the end of the file, Ctrl-D puts the cursor on the last line.
  5. Ctrl-Y scrolls the view up one line. 3 Ctrl-Y scrolls three. The cursor stays until it would cross the scrolloff margin.
  6. Alt-E scrolls the view down the same way. Ctrl-E still toggles the file tree.
  7. Resize the terminal and press plain Ctrl-D. The distance is half the new height.

cargo test --test editing counted_half_page half_page_down resizing_the_window ctrl_y_and_alt scroll_line_down half_page_counts nowrap_half vim_half_page covers the remembered distance, the end-of-file clamp, resize, wrapped rows, Ctrl-Y / Alt-E with and without a count, and a remapped scroll-down key.

Open in Web Open in Cursor 

Ctrl-D and Ctrl-U keep a window-local scroll distance, and Ctrl-Y
and Alt-E scroll the view by a count without moving the cursor until
it would leave the screen.
@fcoury
fcoury marked this pull request as ready for review November 3, 2026 03:30
@fcoury

fcoury commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T03:33:01.195006Z 59a7f42 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59a7f42d6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/editor.rs Resolved
The next event checks bounds before the action runs, so clearing the
preserve flag at the end of Ctrl-D let a following count pull the
cursor back into the scrolloff margin.
@cursor
cursor Bot marked this pull request as draft November 3, 2026 03:37
@fcoury
fcoury marked this pull request as ready for review November 3, 2026 03:42
Keep counted half-page scrolling and the -c key=value flags together.

# Conflicts:
#	CHANGELOG.md
Keep counted scrolling together with the latest main.
A file created in the same timestamp tick does not change the directory
mtime, so the non-recursive snapshot can stay identical until the clock moves.
@fcoury
fcoury merged commit 34636a6 into main Nov 3, 2026
16 checks passed
@fcoury
fcoury deleted the explore/count-scroll branch November 3, 2026 04:08
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.

1 participant