You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When user needs to distinguish between physically hitting backspace key and ctrl+h combo, the key events coming from tcell are hard to reason about. It is complex enough to make test cases for all combinations.
// redacted tests for brevity
type giveKey struct {
Type tcell.Key
Char rune
Mods tcell.ModMask
}
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModNone}, // actual "Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModAlt}, // actual "Alt+Backspace" keystroke
giveKey{tcell.KeyDEL, rune(tcell.KeyDEL), tcell.ModCtrl}, // actual "Ctrl+Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift}, // actual "Shift+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt}, // actual "Ctrl+Alt+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModShift}, // actual "Ctrl+Shift+Backspace" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift | tcell.ModAlt}, // actual "Shift+Alt+Backspace" keystroke
// actual "Ctrl+Shift+Alt+Backspace" keystroke
giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt | tcell.ModShift},
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl}, // actual "Ctrl+H" keystroke
giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModShift}, // actual "Ctrl+Shift+H" keystroke
So it turn out that there is a reason this is hard to reason about -- generally the underlying terminals (outside of Windows which is a special case) send CTRL-H as Backspace (or Delete, which is another confusing thing).
On Windows we get to know precisely which keys you pressed, but we also want the code to portable to other platforms. However, because with Windows we get the modifier keys we do actually send the modifiers we get.
When user needs to distinguish between physically hitting backspace key and ctrl+h combo, the key events coming from tcell are hard to reason about. It is complex enough to make test cases for all combinations.
https://github.com/junegunn/fzf/blob/5fc78e4584eface9f2055ee7c31c2ae8c5cedc87/src/tui/tcell_test.go#L113-L123
The text was updated successfully, but these errors were encountered: