Skip to content

Commit

Permalink
Merge pull request #113 from Kavantix/modshift
Browse files Browse the repository at this point in the history
Add support for Shift modifier on keys like arrow keys
  • Loading branch information
mjarkk authored Jan 13, 2022
2 parents df3d389 + 4a24126 commit 9bbecca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions keybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,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)
)
6 changes: 3 additions & 3 deletions tcell_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
} 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
Expand Down

0 comments on commit 9bbecca

Please sign in to comment.