mirror of https://github.com/gdamore/tcell.git
fixes #117 Add PGUP, PGDN, HOME, and END key handling to TextArea
This commit is contained in:
parent
c3e5bc256f
commit
ad43f8729b
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue