Skip to content

Migrate hardcoded keys to KeyBindings using TG 2.1.1-develop.59 Command enum values#120

Merged
tig merged 9 commits into
developfrom
copilot/configure-editor-key-bindings
May 15, 2026
Merged

Migrate hardcoded keys to KeyBindings using TG 2.1.1-develop.59 Command enum values#120
tig merged 9 commits into
developfrom
copilot/configure-editor-key-bindings

Conversation

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor

Tab, Shift+Tab, F3, Shift+F3, Ctrl+F, and Ctrl+H were handled via direct key comparison in OnKeyDownNotHandled instead of through Terminal.Gui's KeyBindings system, making them non-configurable.

Changes

  • Bumped TerminalGuiVersion from 2.1.0 to 2.1.1-develop.59, which includes the new Command enum values added in gui-cs/Terminal.Gui#5309.
  • Added 6 new key bindings in DefaultKeyBindings (Editor.Commands.cs):
    • Command.InsertTab → Tab
    • Command.Unindent → Shift+Tab
    • Command.FindNext → F3
    • Command.FindPrevious → Shift+F3
    • Command.Find → Ctrl+F
    • Command.Replace → Ctrl+H
  • Registered AddCommand handlers for all 6 commands with extracted helper methods.
  • Removed hardcoded key checks from OnKeyDownNotHandled in Editor.Keyboard.cs — the direct key comparisons for Tab, Shift+Tab, F3, Shift+F3, Ctrl+F, and Ctrl+H are replaced by proper KeyBindings entries.
  • Tab/Shift+Tab reclaim logic updated — still removes the framework's focus-cycling bindings after ApplyKeyBindings, but now re-adds them bound to Command.InsertTab / Command.Unindent.
  • Added 20 integration tests in EditorKeyBindingTests.cs covering DefaultKeyBindings registration, InvokeCommand behavior (including ReadOnly guards), and key-to-command wire-up for all 6 migrated bindings.

All six keys are now user-configurable through the DefaultKeyBindings dictionary, consistent with how every other editor key binding works.

Copilot AI assigned Copilot and tig May 14, 2026
Copilot AI linked an issue May 14, 2026 that may be closed by this pull request
Define editor-specific Command constants (InsertTabCommand, UnindentCommand,
FindNextCommand, FindPreviousCommand, FindCommand, ReplaceCommand) and register
them via AddCommand + DefaultKeyBindings so all keys are user-configurable.

Remove hardcoded key checks (Tab, Shift+Tab, F3, Shift+F3, Ctrl+F, Ctrl+H)
from OnKeyDownNotHandled, which now only handles rune insertion.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/218aede8-cecb-4b28-98fa-b6785329a127

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot AI changed the title [WIP] Make all keys used in Editor configurable Move hardcoded keys to configurable KeyBindings May 14, 2026
Copilot AI requested a review from tig May 14, 2026 18:34
Copilot finished work on behalf of tig May 14, 2026 18:34
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

1 similar comment
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

…ound missing enum values

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/996d1878-3b57-459f-b812-610d4519bbbc

Co-authored-by: tig <585482+tig@users.noreply.github.com>

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

Reverted in e671ac1. All custom (Command)10001005 casts are removed; the original OnKeyDownNotHandled key handling is restored. A Terminal.Gui issue should be filed requesting proper Command enum values for these editor operations (InsertTab, Unindent, FindNext, FindPrevious, Find, Replace) so this can be done properly upstream.

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

Addressed in e671ac1 — same revert as above, restoring original key handling and removing all custom Command casts.

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

Reverted the custom Command enum workaround in e671ac1. The keys (Tab, Shift+Tab, F3, Shift+F3, Ctrl+F, Ctrl+H) are back in OnKeyDownNotHandled. Once Terminal.Gui adds the needed command enum values (InsertTab, Unindent, FindNext, FindPrevious, Find, Replace), we can migrate these to the KeyBindings system properly.

@copilot read the constitution regarding this being part of TG. We don't work around TG limits like missing command enum values. We file Issues against TG so things get fixed right.

Reverted in e671ac1 — no more custom (Command)1000 casts. The original OnKeyDownNotHandled approach is restored. An issue should be filed against Terminal.Gui to add the missing command enum values.

Copilot AI changed the title Move hardcoded keys to configurable KeyBindings Revert: Move hardcoded keys to configurable KeyBindings May 14, 2026
Copilot finished work on behalf of tig May 14, 2026 19:02
Copilot AI changed the title Revert: Move hardcoded keys to configurable KeyBindings Revert: hardcoded keys remain in OnKeyDownNotHandled until TG adds missing Command enum values May 14, 2026
Copilot finished work on behalf of tig May 14, 2026 19:03
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot you file the issue on tg

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot you file the issue on tg

I'm unable to file issues on other repositories — I can only make changes within this repo's PR. Could you or another maintainer file the issue on gui-cs/Terminal.Gui requesting the following Command enum additions?

  • InsertTab — insert a tab / indent selection
  • Unindent — remove one indentation level
  • FindNext — move to next search match
  • FindPrevious — move to previous search match
  • Find — open Find UI
  • Replace — open Replace UI

Once those land in TG, the keys currently in OnKeyDownNotHandled can be migrated to the KeyBindings system properly.

@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot see gui-cs/Terminal.Gui#5309 - it's been merged. you might have to wait for nuget to publish.

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot see gui-cs/Terminal.Gui#5309 - it's been merged. you might have to wait for nuget to publish.

Checked — the latest available NuGet package (2.1.1-develop.56) doesn't include the new Command values yet. The PR is merged but a new package build hasn't been published. Once a new 2.1.1-develop.* version ships with Command.InsertTab / Unindent / Find / FindNext / FindPrevious / Replace, I can bump TerminalGuiVersion and migrate the keys from OnKeyDownNotHandled to KeyBindings.

Copilot AI changed the title Revert: hardcoded keys remain in OnKeyDownNotHandled until TG adds missing Command enum values Revert: hardcoded keys remain in OnKeyDownNotHandled until TG publishes new Command enum values May 14, 2026
Copilot finished work on behalf of tig May 14, 2026 20:45
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot .59 is now published.

Copilot AI and others added 2 commits May 14, 2026 20:49

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot .59 is now published.

Bumped TerminalGuiVersion to 2.1.1-develop.59 and migrated all 6 keys from OnKeyDownNotHandled to KeyBindings using the proper Command enum values in 7bfe263. Tab, Shift+Tab, F3, Shift+F3, Ctrl+F, and Ctrl+H are now configurable through DefaultKeyBindings.

Copilot AI changed the title Revert: hardcoded keys remain in OnKeyDownNotHandled until TG publishes new Command enum values Migrate hardcoded keys to KeyBindings using TG 2.1.1-develop.59 Command enum values May 14, 2026
Copilot finished work on behalf of tig May 14, 2026 20:54
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot I don't see any new tests. Is this all thourogly tested?

Copilot AI and others added 2 commits May 14, 2026 21:07

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I don't see any new tests. Is this all thourogly tested?

Added 20 integration tests in EditorKeyBindingTests.cs (commit 6f9910f):

  • 6 tests verify DefaultKeyBindings contains all new commands
  • 6 tests verify InvokeCommand produces correct behavior (InsertTab inserts, Unindent removes whitespace, FindNext/FindPrevious select matches, Find/Replace raise events)
  • 2 tests verify ReadOnly guards for InsertTab and Unindent
  • 6 tests verify key-to-command wire-up via KeyBindings.GetCommands

Combined with the pre-existing tests in EditorTabTests (7 tests for Tab/Shift+Tab via key injection), EditorSearchHitTests (4 tests for F3/Shift+F3/Ctrl+F/Ctrl+H via key injection), and EditorReadOnlyTests (Tab/ShiftTab read-only guards), all six migrated bindings have thorough coverage.

Copilot finished work on behalf of tig May 14, 2026 21:08
@tig tig merged commit d1314c6 into develop May 15, 2026
8 checks passed
@tig tig deleted the copilot/configure-editor-key-bindings branch May 15, 2026 12:10
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.

All keys used in Editor should be configurable

2 participants