Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Shift modifier on keys like arrow keys #113

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions keybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
dankox marked this conversation as resolved.
Show resolved Hide resolved
)
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