forked from sloum/bombadillo
Added page up, page down, home, and end to hot keys
This commit is contained in:
parent
5cba1bf907
commit
a19bc2c6d8
|
@ -111,3 +111,69 @@ func (w *Window) ScrollUp() {
|
|||
fmt.Print("\a")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) PageDown() {
|
||||
var borderThickness int
|
||||
if w.drawBox {
|
||||
borderThickness = -1
|
||||
} else {
|
||||
borderThickness = 1
|
||||
}
|
||||
|
||||
height := w.Box.row2 - w.Box.row1 + borderThickness
|
||||
contentLength := len(w.Content)
|
||||
if w.Scrollposition < contentLength-height {
|
||||
w.Scrollposition += height
|
||||
if w.Scrollposition > contentLength-height {
|
||||
w.Scrollposition = contentLength-height
|
||||
}
|
||||
} else {
|
||||
fmt.Print("\a")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) PageUp() {
|
||||
var borderThickness int
|
||||
if w.drawBox {
|
||||
borderThickness = -1
|
||||
} else {
|
||||
borderThickness = 1
|
||||
}
|
||||
|
||||
height := w.Box.row2 - w.Box.row1 + borderThickness
|
||||
contentLength := len(w.Content)
|
||||
if w.Scrollposition > 0 && height < contentLength {
|
||||
w.Scrollposition -= height
|
||||
if w.Scrollposition < 0 {
|
||||
w.Scrollposition = 0
|
||||
}
|
||||
} else {
|
||||
fmt.Print("\a")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) ScrollHome() {
|
||||
if w.Scrollposition > 0 {
|
||||
w.Scrollposition = 0
|
||||
} else {
|
||||
fmt.Print("\a")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) ScrollEnd() {
|
||||
var borderThickness int
|
||||
if w.drawBox {
|
||||
borderThickness = -1
|
||||
} else {
|
||||
borderThickness = 1
|
||||
}
|
||||
|
||||
height := w.Box.row2 - w.Box.row1 + borderThickness
|
||||
|
||||
contentLength := len(w.Content)
|
||||
if w.Scrollposition < contentLength-height {
|
||||
w.Scrollposition = contentLength-height
|
||||
} else {
|
||||
fmt.Print("\a")
|
||||
}
|
||||
}
|
||||
|
|
12
main.go
12
main.go
|
@ -487,6 +487,18 @@ func main() {
|
|||
screen.ReflashScreen(false)
|
||||
case 'q', 'Q':
|
||||
cui.Exit()
|
||||
case 'g':
|
||||
screen.Windows[screen.Activewindow].ScrollHome()
|
||||
screen.ReflashScreen(false)
|
||||
case 'G':
|
||||
screen.Windows[screen.Activewindow].ScrollEnd()
|
||||
screen.ReflashScreen(false)
|
||||
case 'd':
|
||||
screen.Windows[screen.Activewindow].PageDown()
|
||||
screen.ReflashScreen(false)
|
||||
case 'u':
|
||||
screen.Windows[screen.Activewindow].PageUp()
|
||||
screen.ReflashScreen(false)
|
||||
case 'b':
|
||||
success := history.GoBack()
|
||||
if success {
|
||||
|
|
Loading…
Reference in New Issue