fixes #117 Add PGUP, PGDN, HOME, and END key handling to TextArea

This commit is contained in:
Garrett D'Amore 2016-05-24 01:26:09 -07:00
parent c3e5bc256f
commit ad43f8729b
1 changed files with 54 additions and 0 deletions

View File

@ -129,6 +129,48 @@ func (a *CellView) keyRight() {
a.MakeCursorVisible()
}
func (a *CellView) keyPgUp() {
_, vy := a.port.Size()
if _, _, en, _ := a.model.GetCursor(); !en {
a.port.ScrollUp(vy)
return
}
a.model.MoveCursor(0, -vy)
a.MakeCursorVisible()
}
func (a *CellView) keyPgDn() {
_, vy := a.port.Size()
if _, _, en, _ := a.model.GetCursor(); !en {
a.port.ScrollDown(vy)
return
}
a.model.MoveCursor(0, +vy)
a.MakeCursorVisible()
}
func (a *CellView) keyHome() {
vx, vy := a.model.GetBounds()
if _, _, en, _ := a.model.GetCursor(); !en {
a.port.ScrollUp(vy)
a.port.ScrollLeft(vx)
return
}
a.model.SetCursor(0, 0)
a.MakeCursorVisible()
}
func (a *CellView) keyEnd() {
vx, vy := a.model.GetBounds()
if _, _, en, _ := a.model.GetCursor(); !en {
a.port.ScrollDown(vy)
a.port.ScrollRight(vx)
return
}
a.model.SetCursor(vx, vy)
a.MakeCursorVisible()
}
// MakeCursorVisible ensures that the cursor is visible, panning the ViewPort
// as necessary, if the cursor is enabled.
func (a *CellView) MakeCursorVisible() {
@ -162,6 +204,18 @@ func (a *CellView) HandleEvent(e tcell.Event) bool {
case tcell.KeyLeft, tcell.KeyCtrlB:
a.keyLeft()
return true
case tcell.KeyPgDn:
a.keyPgDn()
return true
case tcell.KeyPgUp:
a.keyPgUp()
return true
case tcell.KeyEnd:
a.keyEnd()
return true
case tcell.KeyHome:
a.keyHome()
return true
}
}
return false