Skip to content

feat: Ctrl+Left/Right word navigation and Ctrl+Shift+Left/Right selection (#137)#138

Merged
tig merged 2 commits into
tui-cs:developfrom
YourRobotOverlord:feature/137-word-navigation
May 17, 2026
Merged

feat: Ctrl+Left/Right word navigation and Ctrl+Shift+Left/Right selection (#137)#138
tig merged 2 commits into
tui-cs:developfrom
YourRobotOverlord:feature/137-word-navigation

Conversation

@YourRobotOverlord

Copy link
Copy Markdown
Collaborator
Copilot Session

[913adbc6-5ccd-4633-b2a6-c0a09b84dc9e]

Fixes #137Editor now responds to the modifier keys described in the issue.

What's new

Key Command Behaviour
Ctrl+Left WordLeft Jump to the previous word start; collapses any selection
Ctrl+Right WordRight Jump to the next word start; collapses any selection
Ctrl+Shift+Left WordLeftExtend Extend selection to the previous word start
Ctrl+Shift+Right WordRightExtend Extend selection to the next word start
Ctrl+Backspace KillWordLeft Delete from the previous word start to the caret
Ctrl+Delete KillWordRight Delete from the caret to the next word start

Implementation notes

  • Word boundary — uses TextUtilities.GetNextCaretPosition with CaretPositioningMode.WordStartOrSymbol, the same mode used by AvaloniaEdit and TG's own TextView for Ctrl+Left/Right. This stops at word starts and between adjacent punctuation/symbol runs, giving intuitive jumps across operators and brackets.
  • Selection collapsingWordLeft collapses to SelectionStart, WordRight collapses to SelectionEnd, matching the behaviour of the plain arrow keys.
  • Kill commands — respect ReadOnly; replace any active selection rather than doing a word-boundary delete (consistent with DeleteCharLeft/DeleteCharRight); wrapped in a RunUpdate scope so undo is a single step.
  • All six commands are registered in Editor.DefaultKeyBindings and are therefore overridable via Terminal.Gui's ConfigurationManager JSON profile mechanism.

Files changed

  • src/Terminal.Gui.Editor/Editor.Selection.csGetWordBoundaryOffset, MoveCaretToWordBoundary, KillToWordBoundary helpers
  • src/Terminal.Gui.Editor/Editor.Commands.cs — 6 key bindings + 6 AddCommand registrations
  • tests/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

…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>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/Terminal.Gui.Editor/Editor.Selection.cs
Comment thread tests/Terminal.Gui.Editor.Tests/EditorWordNavigationTests.cs
Comment thread tests/Terminal.Gui.Editor.Tests/EditorWordNavigationTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tig
tig merged commit f82b346 into tui-cs:develop May 17, 2026
4 checks passed
@YourRobotOverlord
YourRobotOverlord deleted the feature/137-word-navigation branch May 17, 2026 04:49
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.

Editor should support movement/selection modifier keys

3 participants