diff --git a/button.go b/button.go index ec0ba1c..75fa34f 100644 --- a/button.go +++ b/button.go @@ -151,7 +151,7 @@ func (b *Button) Draw(screen tcell.Screen) { func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { return b.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { // Process key event. - if HitShortcut(event, Keys.Select) { + if HitShortcut(event, Keys.Select, Keys.SelectAlt) { if b.selected != nil { b.selected() } diff --git a/grid.go b/grid.go index 542ac8a..f866353 100644 --- a/grid.go +++ b/grid.go @@ -324,17 +324,17 @@ func (g *Grid) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit g.Lock() defer g.Unlock() - if HitShortcut(event, Keys.MoveFirst) { + if HitShortcut(event, Keys.MoveFirst, Keys.MoveFirst2) { g.rowOffset, g.columnOffset = 0, 0 - } else if HitShortcut(event, Keys.MoveLast) { + } else if HitShortcut(event, Keys.MoveLast, Keys.MoveLast2) { g.rowOffset = math.MaxInt32 - } else if HitShortcut(event, Keys.MoveUp, Keys.MovePreviousField) { + } else if HitShortcut(event, Keys.MoveUp, Keys.MoveUp2, Keys.MovePreviousField) { g.rowOffset-- - } else if HitShortcut(event, Keys.MoveDown, Keys.MoveNextField) { + } else if HitShortcut(event, Keys.MoveDown, Keys.MoveDown2, Keys.MoveNextField) { g.rowOffset++ - } else if HitShortcut(event, Keys.MoveLeft) { + } else if HitShortcut(event, Keys.MoveLeft, Keys.MoveLeft2) { g.columnOffset-- - } else if HitShortcut(event, Keys.MoveRight) { + } else if HitShortcut(event, Keys.MoveRight, Keys.MoveRight2) { g.columnOffset++ } }) diff --git a/keys.go b/keys.go index b4a9d30..26a9d23 100644 --- a/keys.go +++ b/keys.go @@ -6,18 +6,26 @@ import ( ) // Key defines the keyboard shortcuts of an application. +// Secondary shortcuts apply when not focusing a text input. type Key struct { Select []string - SelectAlt []string // SelectAlt is also used when not focusing a text input. + SelectAlt []string Cancel []string - MoveUp []string - MoveDown []string - MoveLeft []string - MoveRight []string + MoveUp []string + MoveUp2 []string + MoveDown []string + MoveDown2 []string + MoveLeft []string + MoveLeft2 []string + MoveRight []string + MoveRight2 []string + + MoveFirst []string + MoveFirst2 []string + MoveLast []string + MoveLast2 []string - MoveFirst []string - MoveLast []string MovePreviousField []string MoveNextField []string MovePreviousPage []string @@ -27,18 +35,26 @@ type Key struct { } // Keys defines the keyboard shortcuts of an application. +// Secondary shortcuts apply when not focusing a text input. var Keys = Key{ Select: []string{"Enter", "Ctrl+J"}, // Ctrl+J = keypad enter SelectAlt: []string{"Space"}, Cancel: []string{"Escape"}, - MoveUp: []string{"Up", "k"}, - MoveDown: []string{"Down", "j"}, - MoveLeft: []string{"Left", "h"}, - MoveRight: []string{"Right", "l"}, + MoveUp: []string{"Up"}, + MoveUp2: []string{"k"}, + MoveDown: []string{"Down"}, + MoveDown2: []string{"j"}, + MoveLeft: []string{"Left"}, + MoveLeft2: []string{"h"}, + MoveRight: []string{"Right"}, + MoveRight2: []string{"l"}, + + MoveFirst: []string{"Home", "Ctrl+A"}, + MoveFirst2: []string{"g"}, + MoveLast: []string{"End", "Ctrl+E"}, + MoveLast2: []string{"G"}, - MoveFirst: []string{"Home", "g"}, - MoveLast: []string{"End", "G"}, MovePreviousField: []string{"Backtab"}, MoveNextField: []string{"Tab"}, MovePreviousPage: []string{"PageUp", "Ctrl+B"}, diff --git a/list.go b/list.go index e0c8b4a..1274879 100644 --- a/list.go +++ b/list.go @@ -867,7 +867,7 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit l.Unlock() } return - } else if HitShortcut(event, Keys.Select) { + } else if HitShortcut(event, Keys.Select, Keys.SelectAlt) { if l.currentItem >= 0 && l.currentItem < len(l.items) { item := l.items[l.currentItem] if item.Enabled { @@ -939,13 +939,13 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit } if !matchesShortcut { - if HitShortcut(event, Keys.MoveFirst) { + if HitShortcut(event, Keys.MoveFirst, Keys.MoveFirst2) { l.transform(TransformFirstItem) - } else if HitShortcut(event, Keys.MoveLast) { + } else if HitShortcut(event, Keys.MoveLast, Keys.MoveLast2) { l.transform(TransformLastItem) - } else if HitShortcut(event, Keys.MoveUp, Keys.MovePreviousField) { + } else if HitShortcut(event, Keys.MoveUp, Keys.MoveUp2, Keys.MovePreviousField) { l.transform(TransformPreviousItem) - } else if HitShortcut(event, Keys.MoveDown, Keys.MoveNextField) { + } else if HitShortcut(event, Keys.MoveDown, Keys.MoveDown2, Keys.MoveNextField) { l.transform(TransformNextItem) } else if HitShortcut(event, Keys.MovePreviousPage) { l.transform(TransformPreviousPage) diff --git a/table.go b/table.go index 6ddcb86..eb21083 100644 --- a/table.go +++ b/table.go @@ -1379,23 +1379,23 @@ func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primi } ) - if HitShortcut(event, Keys.MoveFirst) { + if HitShortcut(event, Keys.MoveFirst, Keys.MoveFirst2) { home() - } else if HitShortcut(event, Keys.MoveLast) { + } else if HitShortcut(event, Keys.MoveLast, Keys.MoveLast2) { end() - } else if HitShortcut(event, Keys.MoveUp, Keys.MovePreviousField) { + } else if HitShortcut(event, Keys.MoveUp, Keys.MoveUp2, Keys.MovePreviousField) { up() - } else if HitShortcut(event, Keys.MoveDown, Keys.MoveNextField) { + } else if HitShortcut(event, Keys.MoveDown, Keys.MoveDown2, Keys.MoveNextField) { down() - } else if HitShortcut(event, Keys.MoveLeft) { + } else if HitShortcut(event, Keys.MoveLeft, Keys.MoveLeft2) { left() - } else if HitShortcut(event, Keys.MoveRight) { + } else if HitShortcut(event, Keys.MoveRight, Keys.MoveRight2) { right() } else if HitShortcut(event, Keys.MovePreviousPage) { pageUp() } else if HitShortcut(event, Keys.MoveNextPage) { pageDown() - } else if HitShortcut(event, Keys.Select) { + } else if HitShortcut(event, Keys.Select, Keys.SelectAlt) { if (t.rowsSelectable || t.columnsSelectable) && t.selected != nil { t.Unlock() t.selected(t.selectedRow, t.selectedColumn) diff --git a/textview.go b/textview.go index f47602a..856b042 100644 --- a/textview.go +++ b/textview.go @@ -1172,7 +1172,7 @@ func (t *TextView) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { key := event.Key() - if HitShortcut(event, Keys.Cancel, Keys.Select, Keys.MovePreviousField, Keys.MoveNextField) { + if HitShortcut(event, Keys.Cancel, Keys.Select, Keys.SelectAlt, Keys.MovePreviousField, Keys.MoveNextField) { if t.done != nil { t.done(key) } @@ -1186,21 +1186,21 @@ func (t *TextView) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr return } - if HitShortcut(event, Keys.MoveFirst) { + if HitShortcut(event, Keys.MoveFirst, Keys.MoveFirst2) { t.trackEnd = false t.lineOffset = 0 t.columnOffset = 0 - } else if HitShortcut(event, Keys.MoveLast) { + } else if HitShortcut(event, Keys.MoveLast, Keys.MoveLast2) { t.trackEnd = true t.columnOffset = 0 - } else if HitShortcut(event, Keys.MoveUp) { + } else if HitShortcut(event, Keys.MoveUp, Keys.MoveUp2) { t.trackEnd = false t.lineOffset-- - } else if HitShortcut(event, Keys.MoveDown) { + } else if HitShortcut(event, Keys.MoveDown, Keys.MoveDown2) { t.lineOffset++ - } else if HitShortcut(event, Keys.MoveLeft) { + } else if HitShortcut(event, Keys.MoveLeft, Keys.MoveLeft2) { t.columnOffset-- - } else if HitShortcut(event, Keys.MoveRight) { + } else if HitShortcut(event, Keys.MoveRight, Keys.MoveRight2) { t.columnOffset++ } else if HitShortcut(event, Keys.MovePreviousPage) { t.trackEnd = false diff --git a/treeview.go b/treeview.go index 475f8bb..8105d98 100644 --- a/treeview.go +++ b/treeview.go @@ -895,13 +895,13 @@ func (t *TreeView) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr t.done(event.Key()) t.Lock() } - } else if HitShortcut(event, Keys.MoveFirst) { + } else if HitShortcut(event, Keys.MoveFirst, Keys.MoveFirst2) { t.movement = treeHome - } else if HitShortcut(event, Keys.MoveLast) { + } else if HitShortcut(event, Keys.MoveLast, Keys.MoveLast2) { t.movement = treeEnd - } else if HitShortcut(event, Keys.MoveUp, Keys.MovePreviousField) { + } else if HitShortcut(event, Keys.MoveUp, Keys.MoveUp2, Keys.MovePreviousField) { t.movement = treeUp - } else if HitShortcut(event, Keys.MoveDown, Keys.MoveNextField) { + } else if HitShortcut(event, Keys.MoveDown, Keys.MoveDown2, Keys.MoveNextField) { t.movement = treeDown } else if HitShortcut(event, Keys.MovePreviousPage) { t.movement = treePageUp