Skip to content

Fixes #4924. Setting Shortcut.Key to Key.Empty now removes the key binding - #4925

Merged
tig merged 3 commits into
developfrom
pr/4919-kitty-keyboard-protocol-alt-gr-fix
Apr 11, 2026
Merged

Fixes #4924. Setting Shortcut.Key to Key.Empty now removes the key binding#4925
tig merged 3 commits into
developfrom
pr/4919-kitty-keyboard-protocol-alt-gr-fix

Conversation

@tig

@tig tig commented Apr 10, 2026

Copy link
Copy Markdown
Member

Fixes #4924

Problem

Shortcut.UpdateKeyBindings had an early-return guard:

if (!Key.IsValid)
{
    return;
}

Key.IsValid is false for Key.Empty, so setting shortcut.Key = Key.Empty was a no-op — the previously-registered binding was never removed. The old key kept firing the action.

Fix

  • Remove the if (!Key.IsValid) return guard entirely.
  • Guard only the add path with if (Key != Key.Empty), so:
    • The old binding is always removed.
    • Key.Empty is never registered as a new binding.

Changes

File Change
Terminal.Gui/Views/Shortcut.cs Remove invalid early-return; add Key.Empty guards on add paths
Tests/…/ShortcutTests.KeyDown.cs Two new failing-before/passing-after unit tests
Examples/UICatalog/Scenarios/Keys.cs Add "Disable Quit Key" shortcut to demo the fix; use StatusBar with Dim.Fill(statusBar) for list views
Terminal.Gui/Drivers/AnsiDriver/AnsiInput.cs Expose KeyboardFlags as a public property
Terminal.Gui/Drivers/AnsiDriver/AnsiComponentFactory.cs Include kitty keyboard state in driver name
Terminal.Gui/Drivers/DriverImpl.cs Make KittyKeyboardProtocol public
Terminal.Gui/Drivers/IDriver.cs TODO comment for capabilities extension
Tests/…/InitTests.cs Update assertion for new driver name format
Tests/…/AllDriverTests.cs Update assertion for new driver name format

Tests

Two new tests in ShortcutTests.KeyDown.cs:

  • Setting_Key_To_Empty_Removes_KeyBinding — view-scoped binding
  • Setting_Key_To_Empty_Removes_AppLevel_KeyBinding — app-scoped (BindKeyToApplication = true)

Both fail on the unfixed code and pass with the fix.

…nding

- Remove the `if (!Key.IsValid) return` early exit from UpdateKeyBindings,
  which prevented cleanup when Key was set to Key.Empty (IsValid is false for Empty).
- Guard only the *add* path with `if (Key != Key.Empty)` so the old binding
  is always removed but Key.Empty is never registered as a new binding.
- Add two unit tests that fail without the fix and pass with it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tig
tig force-pushed the pr/4919-kitty-keyboard-protocol-alt-gr-fix branch from 1a3ccda to 7c96c5d Compare April 10, 2026 15:33

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

Fixes #4924 by ensuring that setting Shortcut.Key = Key.Empty actually removes any previously-registered key binding rather than leaving the old binding active.

Changes:

  • Updated Shortcut.UpdateKeyBindings to always remove the old binding and to skip adding a new binding when Key is Key.Empty.
  • Added unit tests covering both view-scoped and application-scoped bindings being removed when Key is set to Key.Empty.

Reviewed changes

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

File Description
Terminal.Gui/Views/Shortcut.cs Adjusts key-binding update logic to allow unbinding via Key.Empty.
Tests/UnitTestsParallelizable/Views/ShortcutTests.KeyDown.cs Adds regression tests for unbinding behavior; minor cleanup to event handlers/loops.

Comment thread Terminal.Gui/Views/Shortcut.cs
Comment thread Terminal.Gui/Views/Shortcut.cs

@BDisp BDisp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great. Now assigning a command to a key is always guaranteed, as long as the key is not empty.

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.

Setting Shortcut.Key to Key.Empty does not remove the key binding

3 participants