From 12f0b029efcd15bc1129682ad0d6efad1b6c685d Mon Sep 17 00:00:00 2001 From: Pieter van Loon Date: Sun, 2 Jan 2022 12:27:15 +0100 Subject: [PATCH 1/2] Add support for Shift modifier on keys like arrow keys --- keybinding.go | 12 ++++++++---- tcell_driver.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/keybinding.go b/keybinding.go index 683423b..870dc9f 100644 --- a/keybinding.go +++ b/keybinding.go @@ -286,8 +286,12 @@ const ( // Modifiers. const ( - ModNone Modifier = Modifier(0) - ModAlt = Modifier(tcell.ModAlt) - ModMouseShift = Modifier(tcell.ModShift) - ModMouseCtrl = Modifier(tcell.ModCtrl) + ModNone Modifier = Modifier(0) + ModAlt = Modifier(tcell.ModAlt) + + // ModShift only makes sense on keys that are not characters like the + // arrow keys and any mouse keys + // Character keys will instead be triggerd as their translated variant. + ModShift = Modifier(tcell.ModShift) + ModMouseCtrl = Modifier(tcell.ModCtrl) ) diff --git a/tcell_driver.go b/tcell_driver.go index 38c15ba..468dcd7 100644 --- a/tcell_driver.go +++ b/tcell_driver.go @@ -159,7 +159,7 @@ func pollEvent() gocuiEvent { mod = 0 ch = rune(0) k = tcell.KeyCtrlSpace - } else if mod == tcell.ModCtrl || mod == tcell.ModShift { + } else if mod == tcell.ModCtrl || mod == tcell.ModShift && ch != 0 { // remove Ctrl or Shift if specified // - shift - will be translated to the final code of rune // - ctrl - is translated in the key From 4a24126852499f4278b87adc7a1f11a63275dcac Mon Sep 17 00:00:00 2001 From: Pieter van Loon Date: Mon, 10 Jan 2022 13:48:28 +0100 Subject: [PATCH 2/2] Always remove shift modifier for KeySpace --- tcell_driver.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcell_driver.go b/tcell_driver.go index 468dcd7..1e8402b 100644 --- a/tcell_driver.go +++ b/tcell_driver.go @@ -149,17 +149,17 @@ func pollEvent() gocuiEvent { ch = tev.Rune() if ch == ' ' { // special handling for spacebar - k = 32 // tcell keys ends at 31 or starts at 256 + k = tcell.Key(KeySpace) // tcell keys ends at 31 or starts at 256 ch = rune(0) } } mod := tev.Modifiers() // remove control modifier and setup special handling of ctrl+spacebar, etc. - if mod == tcell.ModCtrl && k == 32 { + if mod == tcell.ModCtrl && k == tcell.Key(KeySpace) { mod = 0 ch = rune(0) k = tcell.KeyCtrlSpace - } else if mod == tcell.ModCtrl || mod == tcell.ModShift && ch != 0 { + } else if mod == tcell.ModCtrl || mod == tcell.ModShift && (ch != 0 || k == tcell.Key(KeySpace)) { // remove Ctrl or Shift if specified // - shift - will be translated to the final code of rune // - ctrl - is translated in the key