diff --git a/prompt_toolkit/input/win32.py b/prompt_toolkit/input/win32.py index d79bded04..3e819a5c9 100644 --- a/prompt_toolkit/input/win32.py +++ b/prompt_toolkit/input/win32.py @@ -145,7 +145,7 @@ class ConsoleInputReader: b"\x1d": Keys.ControlSquareClose, # Control-] b"\x1e": Keys.ControlCircumflex, # Control-^ b"\x1f": Keys.ControlUnderscore, # Control-underscore (Also for Ctrl-hyphen.) - b"\x7f": Keys.Backspace, # (127) Backspace (ASCII Delete.) + b"\x7f": Keys.ControlBackspace, # (127) Backspace (ASCII Delete.) } # Keys that don't carry character data. @@ -347,7 +347,7 @@ def _event_to_key_presses(self, ev: KEY_EVENT_RECORD) -> List[KeyPress]: else: result = KeyPress(u_char, u_char) - # First we handle Shift-Control-Arrow/Home/End (need to do this first) + # First we handle Shift-Control-Arrow/Home/End/Ins/Del/PgUp/PgDown/BS (need to do this first) if ( ( ev.ControlKeyState & self.LEFT_CTRL_PRESSED @@ -364,8 +364,10 @@ def _event_to_key_presses(self, ev: KEY_EVENT_RECORD) -> List[KeyPress]: Keys.Home: Keys.ControlShiftHome, Keys.End: Keys.ControlShiftEnd, Keys.Insert: Keys.ControlShiftInsert, + Keys.Delete: Keys.ControlShiftDelete, Keys.PageUp: Keys.ControlShiftPageUp, Keys.PageDown: Keys.ControlShiftPageDown, + Keys.Backspace: Keys.ControlShiftBackspace, } result.key = mapping.get(result.key, result.key) @@ -403,6 +405,7 @@ def _event_to_key_presses(self, ev: KEY_EVENT_RECORD) -> List[KeyPress]: Keys.Delete: Keys.ShiftDelete, Keys.PageUp: Keys.ShiftPageUp, Keys.PageDown: Keys.ShiftPageDown, + Keys.Backspace: Keys.ShiftBackspace, } result.key = mapping.get(result.key, result.key) diff --git a/prompt_toolkit/key_binding/bindings/basic.py b/prompt_toolkit/key_binding/bindings/basic.py index 56efe5d69..6f272390a 100644 --- a/prompt_toolkit/key_binding/bindings/basic.py +++ b/prompt_toolkit/key_binding/bindings/basic.py @@ -88,6 +88,9 @@ def load_basic_bindings() -> KeyBindings: @handle("c-^") @handle("c-_") @handle("backspace") + @handle("s-backspace") + @handle("c-backspace") + @handle("c-s-backspace") @handle("up") @handle("down") @handle("right") @@ -103,6 +106,7 @@ def load_basic_bindings() -> KeyBindings: @handle("delete") @handle("s-delete") @handle("c-delete") + @handle("c-s-delete") @handle("pageup") @handle("pagedown") @handle("s-tab") @@ -146,6 +150,9 @@ def _ignore(event: E) -> None: handle("backspace", filter=insert_mode, save_before=if_no_repeat)( get_by_name("backward-delete-char") ) + handle("c-backspace", filter=insert_mode, save_before=if_no_repeat)( + get_by_name("backward-delete-char") + ) handle("delete", filter=insert_mode, save_before=if_no_repeat)( get_by_name("delete-char") ) diff --git a/prompt_toolkit/key_binding/bindings/emacs.py b/prompt_toolkit/key_binding/bindings/emacs.py index 35c8aa4e8..107e44242 100644 --- a/prompt_toolkit/key_binding/bindings/emacs.py +++ b/prompt_toolkit/key_binding/bindings/emacs.py @@ -58,6 +58,7 @@ def _esc(event: E) -> None: handle("c-a")(get_by_name("beginning-of-line")) handle("c-b")(get_by_name("backward-char")) handle("c-delete", filter=insert_mode)(get_by_name("kill-word")) + handle("c-backspace", filter=insert_mode)(get_by_name("backward-kill-word")) handle("c-e")(get_by_name("end-of-line")) handle("c-f")(get_by_name("forward-char")) handle("c-left")(get_by_name("backward-word")) diff --git a/prompt_toolkit/keys.py b/prompt_toolkit/keys.py index 58b2e4b7c..86fbade6c 100644 --- a/prompt_toolkit/keys.py +++ b/prompt_toolkit/keys.py @@ -75,6 +75,9 @@ class Keys(str, Enum): ControlSquareClose = "c-]" ControlCircumflex = "c-^" ControlUnderscore = "c-_" + ControlBackspace = "c-backspace" + ShiftBackspace = "s-backspace" + ControlShiftBackspace = "c-s-backspace" Left = "left" Right = "right"