fix(input): freeze Command enum with explicit values (gui-cs/Editor#241)#5524
Merged
Conversation
Command was a declaration-ordinal enum (only NotBound=0 explicit). Enums compile to integer constants, so separately-built assemblies — notably the Terminal.Gui.Editor package — bake each command's integer into their key bindings. Inserting a member (e.g. Home in 2.4.4) shifted every later value, re-mapping already-compiled bindings to the wrong command: Backspace invoked SelectAll (tui-cs/Editor#241). Assign every member an explicit value frozen to its current ordinal (no behavior change) so the integers are an ABI contract, plus a doc note and a CommandFrozenValueTests guard. New commands must be appended with the next unused number, never inserted or renumbered. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bump the Editor package 2.4.1 -> 2.5.4 so its compiled-in Command ordinals match this TG (the frozen enum), fixing the Notepad/ConfigurationEditor 'Backspace selects all' mismatch (tui-cs/Editor#241). 2.5.4 also renamed the Document/Highlighting namespaces under Terminal.Gui.Editor.*, so update the scenarios' usings to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 25, 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.
The bug (tui-cs/Editor#241, still live)
Commandwas a declaration-ordinal enum — onlyNotBound = 0was explicit; every other member took its value from position. Enums compile to integer constants, so a separately-built assembly — notably theTerminal.Gui.Editorpackage — bakes each command's integer into its key bindings at build time.When TG 2.4.4 inserted
Homenear the top of the enum, every later value shifted by +1. An Editor package compiled against the pre-Homeordinals then had its bindings resolve to the wrong commands at runtime — most visibly Backspace invokingSelectAll("Backspace selects all"). #241 was closed by republishing aligned versions, but the underlying fragility was never removed, so it recurs on any version skew (e.g. the Editor repo currently pins TG2.4.0, pre-Home, while consumers run2.4.8).The fix
Give every
Commandmember an explicit integer value frozen to its current ordinal. This is a pure no-op for the running TG (values are unchanged) but makes the integers an ABI contract: inserting/reordering a member can no longer silently renumber the rest. New commands must be appended with the next unused number.Command.cs: explicit= Non all 92 members + a<remarks>note explaining the contract.CommandFrozenValueTests: locksNotBound = 0, the binding-criticalDeleteCharRight=40 / DeleteCharLeft=41 / SelectAll=42trio, value uniqueness, and a frozen sample — so a future reorder fails CI instead of shipping.Existing
CommandEnumOrderTestscontinue to pass.Note
This freeze prevents future drift. Already-published Editor packages built against pre-
Homeordinals still need one republish against a post-freeze TG to realign — tracked separately (Editor repo TG-pin bump + release).🤖 Generated with Claude Code