From 8af184edbb4236f484a756fda56622e7cd08788b Mon Sep 17 00:00:00 2001 From: nomvan Date: Tue, 5 May 2026 05:56:49 +0900 Subject: [PATCH] fix: remove invalid Ctrl+Shift+C keybinding --- cli.py | 18 ++++-------------- tests/cli/test_invalid_keybindings.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 tests/cli/test_invalid_keybindings.py diff --git a/cli.py b/cli.py index 96ecb8ecfd14..9996dc331ca3 100644 --- a/cli.py +++ b/cli.py @@ -10484,20 +10484,10 @@ def handle_ctrl_c(event): self._should_exit = True event.app.exit() - @kb.add('c-S-c') # Ctrl+Shift+C - def handle_ctrl_shift_c(event): - """Copy text to clipboard (terminal-native). - - This is a no-op at the application level. Terminal emulators - handle the actual copy operation when Ctrl+Shift+C is pressed. - This binding prevents Hermes from intercepting the keystroke - as an interrupt signal. - - On macOS the standard copy shortcut is Cmd+C (no Hermes binding - needed). On Linux/Windows Ctrl+Shift+C is the conventional - terminal copy shortcut. - """ - return # No-op — let the terminal perform native copy + # Do not bind Ctrl+Shift+C here. prompt_toolkit does not support a + # portable key name for that chord (e.g. 'c-S-c' raises + # ValueError: Invalid key), and terminal emulators handle copy before + # the application sees it anyway. @kb.add('c-q') # Ctrl+Q def handle_ctrl_q(event): diff --git a/tests/cli/test_invalid_keybindings.py b/tests/cli/test_invalid_keybindings.py new file mode 100644 index 000000000000..d02dd9ec4a17 --- /dev/null +++ b/tests/cli/test_invalid_keybindings.py @@ -0,0 +1,18 @@ +from pathlib import Path + +import pytest +from prompt_toolkit.key_binding import KeyBindings + + +@pytest.mark.parametrize("key", ["c-S-c"]) +def test_prompt_toolkit_rejects_non_portable_key_names(key): + kb = KeyBindings() + + with pytest.raises(Exception, match="Invalid key"): + kb.add(key)(lambda event: None) + + +def test_cli_does_not_register_invalid_ctrl_shift_c_binding(): + source = Path(__file__).resolve().parents[2] / "cli.py" + + assert "@kb.add('c-S-c')" not in source.read_text()