Skip to content

Fix Ctrl keybinding in terminal on Windows#1385

Open
CowgillAlex wants to merge 1 commit intopingdotgg:mainfrom
CowgillAlex:terminal-arrow
Open

Fix Ctrl keybinding in terminal on Windows#1385
CowgillAlex wants to merge 1 commit intopingdotgg:mainfrom
CowgillAlex:terminal-arrow

Conversation

@CowgillAlex
Copy link

@CowgillAlex CowgillAlex commented Mar 24, 2026

What Changed

Changed keybindings.ts and its test to properly handle ctrl + rightArrow, ctrl + leftArrow.

Why

Currently the terminal interprets ctrl + right arrow and ctrl + left arrow on Windows as b and f, rather than moving the caret to the next/previous word. This fixes that to no longer interpret the sequence as b and f

I assume that Linux keyboards would handle the terminal ctrl inputs in the same way

UI Changes

Before:

t3code.before.mp4
t3code.after.mp4

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Low Risk
Low risk: small, localized change to terminal escape sequences for non-macOS Ctrl+Arrow navigation, covered by updated unit tests.

Overview
Fixes non-macOS terminal word navigation so Ctrl+ArrowLeft/Right emits the expected control-modified arrow escape sequences (\u001b[1;5D / \u001b[1;5C) instead of Alt-style word jumps.

Updates terminalNavigationShortcutData to return the new sequences only for Ctrl+Arrow on Windows/Linux, and adjusts tests to assert the corrected output.

Written by Cursor Bugbot for commit 30f0822. This will update automatically on new commits. Configure here.

Note

Fix Ctrl+Arrow keybindings in terminal on Windows

On non-macOS, Ctrl+ArrowLeft/Right now sends \u001b[1;5D/\u001b[1;5C (standard xterm control sequences for word movement) instead of the previously used \u001bb/\u001bf (which are Alt/Option-based sequences). Alt+Arrow on non-macOS no longer produces a word-move sequence and now returns null. macOS behavior (Option+Arrow for word, Cmd+Arrow for line) is unchanged.

Macroscope summarized 30f0822.

Copilot AI review requested due to automatic review settings March 24, 2026 23:17
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e202c7a2-10fe-436b-9fd6-4347409a8e60

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

if (event.ctrlKey && !event.metaKey && !event.altKey) {
return moveWordCtrl;
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Alt+Arrow word movement removed on non-Mac platforms

Medium Severity

The refactored else branch for non-Mac platforms only handles Ctrl+Arrow, but the previous code also handled Alt+Arrow for word movement (returning TERMINAL_WORD_BACKWARD/TERMINAL_WORD_FORWARD). That Alt+Arrow path was dropped entirely, so Alt+Arrow on Windows/Linux now returns null instead of sending the word-movement escape sequence. On Linux, Alt+Arrow is a common way to navigate by word in terminals, making this a functional regression that doesn't appear to be intentional based on the PR description.

Fix in Cursor Fix in Web

Copy link
Contributor

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

Adjusts terminal navigation key handling so Ctrl+Left/Right produces the expected escape sequences (not literal b/f characters) for word-wise cursor movement, targeting Windows terminal behavior in the web app’s xterm-based terminal.

Changes:

  • Added CSI escape sequences for Ctrl+Arrow word navigation (\u001b[1;5D / \u001b[1;5C).
  • Updated terminalNavigationShortcutData to return these sequences for non-macOS Ctrl+Arrow.
  • Updated unit tests to assert the new sequences.

Reviewed changes

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

File Description
apps/web/src/keybindings.ts Adds Ctrl+Arrow escape sequences and changes non-macOS mapping logic in terminalNavigationShortcutData.
apps/web/src/keybindings.test.ts Updates expectations for non-macOS Ctrl+Arrow mappings to the new CSI sequences.

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

Comment on lines +288 to +293
} else {

if (event.ctrlKey && !event.metaKey && !event.altKey) {
return moveWordCtrl;
}
return null;
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

This change alters behavior for all non-macOS platforms (including Linux), even though the PR title scopes the fix to Windows. If only Windows needs the CSI sequences, consider gating the ctrlKey mapping to Windows platforms (or update the PR title/description to reflect the broader behavior change).

Copilot uses AI. Check for mistakes.
Comment on lines +289 to +293

if (event.ctrlKey && !event.metaKey && !event.altKey) {
return moveWordCtrl;
}
return null;
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

On non-macOS, Alt+ArrowLeft/Right is no longer handled at all (previously it mapped to TERMINAL_WORD_*). If dropping Alt-based word navigation is not intentional, reintroduce an altKey branch for non-macOS; otherwise, add an explicit test/assertion documenting that altKey is unsupported on non-macOS to avoid accidental regressions.

Copilot uses AI. Check for mistakes.
Comment on lines 274 to +292
@@ -280,15 +285,12 @@ export function terminalNavigationShortcutData(
return moveLine;
}
return null;
} else {

if (event.ctrlKey && !event.metaKey && !event.altKey) {
return moveWordCtrl;
}
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

There’s some inconsistent formatting in the newly added code (a very long moveWordCtrl line and a blank line inside the else block). Running the formatter / wrapping moveWordCtrl similarly to moveWord/moveLine will keep style consistent and avoid trailing whitespace.

Copilot uses AI. Check for mistakes.
Comment on lines 439 to 447
it("maps Ctrl+Arrow on non-macOS to word movement", () => {
assert.strictEqual(
terminalNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true }), "Win32"),
"\u001bb",
"\u001b[1;5D",
);
assert.strictEqual(
terminalNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true }), "Linux"),
"\u001bf",
"\u001b[1;5C",
);
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

The updated expectations now use the CSI Ctrl+Arrow sequences for both Win32 and Linux, but the test name still reads as a single generic non-macOS case. Consider splitting this into explicit platform-specific assertions (e.g., Windows vs Linux) or adding a case for non-macOS altKey behavior (supported vs unsupported) so the intended cross-platform contract is clear.

Copilot uses AI. Check for mistakes.
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.

2 participants