Skip to content

Create proper Ctrl+Backspace shortcut in TextBox #259

@ArrowCase

Description

@ArrowCase

In Windows, Ctrl+Backspace commonly serves as a shortcut to delete the word immediately preceding the cursor. It is equivalent to Ctrl+Shift+Left followed by Backspace.

In WinForms, this shortcut works only in single-line TextBox controls which have autocomplete enabled. This is actually built into SHAutoComplete somewhere in the win32 API, and is a "rogue feature" with no documentation (some history here). If the TextBox is multi-line or doesn't have autocomplete on, Ctrl+Backspace inserts a DELETE character (ASCII 127) instead.

Note: The Ctrl+Delete shortcut (which deletes the word following the cursor) works in all relevant WinForms controls.

Outside of WinForms, the Ctrl+Backspace shortcut is nearly ubiquitous on Windows (as of October 2018, even Notepad finally has it!). As such, I propose properly implementing it in WinForms controls such as TextBoxBase and ComboBox with a custom handler for Ctrl+Backspace.


I've submitted a PR with one approach to add this shortcut, namely using SendInput sending native messages to simulate the aforementioned Ctrl+Shift+Left, Backspace keystrokes. I believe this is the right approach — as even the current autocomplete TextBox "feature" seems to be selecting the text and then deleting it if you watch closely.

Another possibility would be to use internal text selection functions rather than sending keystrokes. However, that requires replicating the logic dealing with word boundaries/punctuation currently used by Ctrl+Shift+Left, which is a bit quirky, not to mention wildly inconsistent between different Windows programs. We can consider this approach if the current PR is lacking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions