forked from tslocum/cview
Split up shortcuts into primary and secondary
This commit is contained in:
parent
777d2f09fc
commit
8acccbefa7
|
@ -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()
|
||||
}
|
||||
|
|
12
grid.go
12
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++
|
||||
}
|
||||
})
|
||||
|
|
42
keys.go
42
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"},
|
||||
|
|
10
list.go
10
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)
|
||||
|
|
14
table.go
14
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)
|
||||
|
|
14
textview.go
14
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue