Skip to content

fix: repeat copy-mode navigation keys - #2372

Open
ogulcancelik wants to merge 1 commit into
masterfrom
fix/copy-mode-arrow-repeat
Open

fix: repeat copy-mode navigation keys#2372
ogulcancelik wants to merge 1 commit into
masterfrom
fix/copy-mode-arrow-repeat

Conversation

@ogulcancelik

@ogulcancelik ogulcancelik commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • repeat all copy-mode cursor and scroll navigation when terminals report explicit repeat events, including arrows, Page Up/Down, Home/End, Vim-style motions, and Ctrl-B/F/U/D
  • keep confirm, exit, prefix, selection, search-opening, and other modal actions single-shot
  • preserve input-source ownership with a copy-navigation-specific consumed lease

Reproduction

macOS Ghostty reports held keys as Kitty Repeat events; Windows can report repeated native presses. Before this change, those paths moved once in copy mode. The patched build repeats navigation continuously without allowing action-key repeats to escape the mode.

Tests

  • just check
  • automated macOS Ghostty → SSH validation: held Up changed copy-mode scroll offset from 0 to 53
  • regression coverage for Ghostty enhanced arrows, Windows native character repeats, Ctrl navigation, both input routers, and action-key suppression

Refs #2371

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Copy-mode navigation now supports explicit terminal key-repeat events for arrows, Page Up/Down, Home, and End. Dedicated input leases route these events through copy-mode handling while preserving existing repeat behavior for other keys.

Changes

Copy-navigation repeat handling

Layer / File(s) Summary
Navigation repeat contract and test
src/app/input/copy_mode.rs
AppState permits repeats only for selected navigation keys in copy mode. The test validates repeated arrow movement and cursor clamping.
Repeat lease disposition
src/app/input/lease.rs
ConsumedInputLease records copy-navigation repeats. The lease table identifies these leases and excludes them from generic repeat planning.
Press and repeat event routing
src/app/mod.rs, src/app/runtime.rs, docs/next/CHANGELOG.md
Input routing records copy-navigation leases on key presses and replays repeat events while copy mode remains active. The changelog documents the supported keys.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Terminal
  participant AppState
  participant InputLeaseTable
  participant CopyModeHandler
  Terminal->>AppState: Send key press
  AppState->>InputLeaseTable: Record RepeatCopyNavigation
  Terminal->>AppState: Send KeyEventKind::Repeat
  AppState->>InputLeaseTable: Check copy-navigation lease
  AppState->>CopyModeHandler: Replay navigation repeat_count times
Loading

Possibly related issues

Possibly related PRs

  • herdrdev/herdr#2142 — Provides the input-lease repeat-routing system extended by this change.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: repeating copy-mode navigation keys.
Description check ✅ Passed The description directly explains the copy-mode repeat behavior, preserved single-shot actions, implementation approach, reproduction, and validation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/copy-mode-arrow-repeat

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 5, 2026

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/app/input/copy_mode.rs (1)

1187-1199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for both repeat routers.

This test exercises App::route_client_input, which covers the headless routing path. The PR also changes src/app/runtime.rs, and the allowlist includes PageUp, PageDown, Home, and End. Add one runtime-path test and cases for the remaining allowlisted keys.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e08b7c75-531f-4917-9e1a-26f5e9b923ae

📥 Commits

Reviewing files that changed from the base of the PR and between eb93ec8 and 3638cce.

📒 Files selected for processing (5)
  • docs/next/CHANGELOG.md
  • src/app/input/copy_mode.rs
  • src/app/input/lease.rs
  • src/app/mod.rs
  • src/app/runtime.rs

@ogulcancelik

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@joonhwan

joonhwan commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Though I'm interested in this fix , when i cargo run this branch, copy mode's keys(i.e : j,k,ctrl-u,ctrl-d ...) cannot be repeated(For Windows herdr test).

@ogulcancelik
ogulcancelik force-pushed the fix/copy-mode-arrow-repeat branch from 3638cce to 7cce478 Compare August 9, 2026 02:26
@ogulcancelik

ogulcancelik commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

@joonhwan Thanks for catching this you were right. The original allowlist covered only non-character navigation. 7cce478 now includes h/j/k/l, word and paragraph motions, Ctrl-B/F/U/D, and the other safe copy-mode movements, with a Windows native-repeat regression test. Could you confirm, exit, prefix, selection, and search-opening actions remain single-shot?

@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown

Greptile Summary

The PR makes explicit repeat events replay copy-mode navigation while preserving single-shot modal actions and input-source ownership.

  • Adds a copy-navigation repeat allowlist covering arrows, paging, line edges, search traversal, and Vim-style motions.
  • Adds a dedicated consumed input lease and equivalent replay behavior for local and headless/client input paths.
  • Adds regression tests for Kitty/Ghostty events, Windows character navigation, control-key paging, search prompts, and prefix handling.
  • Documents the fix in the next-release changelog.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security issues identified.

The local and headless paths consistently establish, replay, and release copy-navigation leases, while the allowlist and mode guards keep non-navigation actions single-shot.

Important Files Changed

Filename Overview
src/app/input/copy_mode.rs Adds a tightly scoped repeatability predicate and tests covering navigation, modal-action exclusions, search prompts, prefixes, and platform-specific repeat events.
src/app/input/lease.rs Adds a dedicated consumed-lease disposition used to retain copy-navigation ownership across explicit repeat events.
src/app/mod.rs Extends headless/client event routing to establish copy-navigation leases on presses and replay matching repeat events.
src/app/runtime.rs Mirrors the copy-navigation lease and replay behavior in the asynchronous local-input runtime path.
docs/next/CHANGELOG.md Documents repeat support for copy-mode navigation and continued single-shot handling for other actions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Raw key event] --> B[Normalize against input lease]
  B --> C{Press or Repeat?}
  C -->|Press| D{Copy-mode navigation?}
  D -->|Yes| E[Execute navigation once]
  E --> F[Store RepeatCopyNavigation lease]
  D -->|No| G[Use normal input routing]
  C -->|Repeat| H{Matching copy-navigation lease and Copy mode active?}
  H -->|Yes| I[Replay navigation repeat_count times]
  H -->|No| J[Use normal repeat plan]
  K[Key release] --> L[Remove lease]
Loading

Reviews (1): Last reviewed commit: "fix: repeat copy-mode navigation keys" | Re-trigger Greptile

@joonhwan

joonhwan commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@ogulcancelik

@joonhwan Thanks for catching this you were right. The original allowlist covered only non-character navigation. 7cce478 now includes h/j/k/l, word and paragraph motions, Ctrl-B/F/U/D, and the other safe copy-mode movements, with a Windows native-repeat regression test. Could you confirm, exit, prefix, selection, and search-opening actions remain single-shot?

This feature now works in windows 11 / wt.exe ! The test results follow.

  • repeat check
    • "char movemetn" - h/j/k/l : ok
    • "page up" - Ctrl+Shift+b(Ctrl-B) : ok (Ctrl+b is prefix in my case)
    • "page down" - Ctrl+Shift+f(Ctrl-F) or Ctrl+f(Ctrl-f) repeat : ok 🫨
    • "half-page up/down" - Ctrl+d/u or Ctrl+Shift+d/u repeat : ok
  • no repeat check
    • "search" - "/" or "?" : ok
    • "visual selection" - "v/space" : ok
    • "yank" - "y/enter" : ok. [1]
    • "exit cursor mode" - "q/esc", : ok. [1]

[1] : no input from repeating keys after exiting cursor mode, which is qood

BTW, since I've been using herdr, i've not have any chance to use "n/N" keys successfully(like. 10 h) . 😢

@shibayu36

Copy link
Copy Markdown

Thank you for working on the copy-mode key repeat! This behavior has bothered me too, so I'm glad to see a fix in progress.

One suggestion: could the repeat decision be based on what the key press actually did, instead of a list of keys?

As analyzed in #2371, what this suppression needs to prevent is: a key triggers an action that leaves the mode, the key is still held, and the remaining repeats leak into the next mode as input. If so, whether a held key is safe to repeat is decided by the action it triggered, not by which key it is bound to.

Currently is_repeatable_navigation_key is a list of keys that are allowed to repeat, and its char list (h/j/k/l, g, G, w, b, e, …) duplicates the dispatch list in handle_copy_mode_key. Adding a new navigation motion later means updating both places, and missing one silently leaves only the new key non-repeating, which is hard to notice. If instead the repeat was stopped only when the press is observed to do something that should stop it — such as leaving the mode — everything else would repeat automatically, and the allowlist would not need updating when navigation motions are added.

One more reason: if copy-mode keybindings become configurable in the future (I proposed this in #587), a hardcoded key list stops working — for example, binding cursor-up to ctrl+p would leave it non-repeating. Deciding from the result of the press keeps working no matter how keys are rebound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants