feat: Ctrl+Left/Right word navigation and Ctrl+Shift+Left/Right selection (#137)#138
Merged
tig merged 2 commits intoMay 17, 2026
Merged
Conversation
…tion (tui-cs#137) Add Command.WordLeft, WordRight, WordLeftExtend, WordRightExtend, KillWordLeft, KillWordRight support to Editor. - Default key bindings: Ctrl+Left / Ctrl+Right → WordLeft / WordRight Ctrl+Shift+Left / Ctrl+Shift+Right → WordLeftExtend / WordRightExtend Ctrl+Backspace / Ctrl+Delete → KillWordLeft / KillWordRight - Word boundary uses TextUtilities.GetNextCaretPosition with CaretPositioningMode.WordStartOrSymbol (matches AvaloniaEdit and TG's own TextView: stops at word starts and between symbol runs). - WordLeft/Right collapse an existing selection to the appropriate end before moving, matching plain arrow key behavior. - KillWord respects ReadOnly, collapses any selection first, and wraps the Remove call in a RunUpdate scope so undo is one step. - 16 new unit tests in EditorWordNavigationTests; key binding guard assertions added to EditorKeyBindingConfigTests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds word-wise navigation, selection extension, and word-kill editing commands to Terminal.Gui.Editor.Editor, aligning editor behavior with common Ctrl-modified key expectations and exposing the bindings via Editor.DefaultKeyBindings for configuration.
Changes:
- Added helpers for word-boundary navigation and deletion using
TextUtilities.GetNextCaretPosition(..., CaretPositioningMode.WordStartOrSymbol). - Registered 6 new commands and default keybindings for Ctrl+Left/Right, Ctrl+Shift+Left/Right, Ctrl+Backspace/Delete.
- Added new unit tests for word navigation/selection/kill behavior and expanded keybinding default assertions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Terminal.Gui.Editor/Editor.Selection.cs |
Introduces word-boundary helper methods for moving the caret and deleting to word boundaries. |
src/Terminal.Gui.Editor/Editor.Commands.cs |
Adds default keybindings and command registrations for word navigation/selection/kill. |
tests/Terminal.Gui.Editor.Tests/EditorWordNavigationTests.cs |
New unit tests covering the new commands’ behavior. |
tests/Terminal.Gui.Editor.Tests/EditorKeyBindingConfigTests.cs |
Adds assertions ensuring the new commands exist in defaults and have expected keys. |
Comments suppressed due to low confidence (1)
tests/Terminal.Gui.Editor.Tests/EditorWordNavigationTests.cs:203
- This test only asserts that the resulting text no longer starts with "hello", which could still pass for incorrect deletions (e.g., deleting too much). Consider asserting the exact expected document text after KillWordRight (and, if relevant, the expected caret position) to make the test more robust.
editor.InvokeCommand (Command.KillWordRight);
Assert.False (editor.Document!.Text.StartsWith ("hello"));
Assert.Equal (0, editor.CaretOffset);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
tig
approved these changes
May 17, 2026
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.
Copilot Session
[913adbc6-5ccd-4633-b2a6-c0a09b84dc9e]
Fixes #137 —
Editornow responds to the modifier keys described in the issue.What's new
Ctrl+LeftWordLeftCtrl+RightWordRightCtrl+Shift+LeftWordLeftExtendCtrl+Shift+RightWordRightExtendCtrl+BackspaceKillWordLeftCtrl+DeleteKillWordRightImplementation notes
TextUtilities.GetNextCaretPositionwithCaretPositioningMode.WordStartOrSymbol, the same mode used by AvaloniaEdit and TG's ownTextViewfor Ctrl+Left/Right. This stops at word starts and between adjacent punctuation/symbol runs, giving intuitive jumps across operators and brackets.WordLeftcollapses toSelectionStart,WordRightcollapses toSelectionEnd, matching the behaviour of the plain arrow keys.ReadOnly; replace any active selection rather than doing a word-boundary delete (consistent withDeleteCharLeft/DeleteCharRight); wrapped in aRunUpdatescope so undo is a single step.Editor.DefaultKeyBindingsand are therefore overridable via Terminal.Gui'sConfigurationManagerJSON profile mechanism.Files changed
src/Terminal.Gui.Editor/Editor.Selection.cs—GetWordBoundaryOffset,MoveCaretToWordBoundary,KillToWordBoundaryhelperssrc/Terminal.Gui.Editor/Editor.Commands.cs— 6 key bindings + 6AddCommandregistrationstests/Terminal.Gui.Editor.Tests/EditorWordNavigationTests.cs— 16 new unit tests (new file)tests/Terminal.Gui.Editor.Tests/EditorKeyBindingConfigTests.cs— guard assertions for all 6 new commands in the defaults