v.Buf = buf
v.matches = Match(v)
v.Cursor.Relocate()
- v.Relocate()
+ v.Relocate(0)
}
}
// Relocate moves the view window so that the cursor is in view
// This is useful if the user has scrolled far away, and then starts typing
-func (v *View) Relocate() bool {
+func (v *View) Relocate(x int) bool {
ret := false
cy := v.Cursor.y
- if cy < v.Topline {
+ if cy < v.Topline+x && cy > x-1 {
+ v.Topline = cy - x
+ ret = true
+ } else if cy < v.Topline {
v.Topline = cy
ret = true
}
- if cy > v.Topline+v.height-1 {
- v.Topline = cy - v.height + 1
+ if cy > v.Topline+v.height-1-x {
+ v.Topline = cy - v.height + 1 + x
ret = true
}
// This bool determines whether the view is relocated at the end of the function
// By default it's true because most events should cause a relocate
relocate := true
+ scrollmargin := int(settings["scrollmargin"].(float64))
switch e := event.(type) {
case *tcell.EventResize:
}
case tcell.WheelUp:
// Scroll up
- scrollSpeed := int(settings["scrollSpeed"].(float64))
- v.ScrollUp(scrollSpeed)
+ scrollspeed := int(settings["scrollspeed"].(float64))
+ v.ScrollUp(scrollspeed)
case tcell.WheelDown:
// Scroll down
- scrollSpeed := int(settings["scrollSpeed"].(float64))
- v.ScrollDown(scrollSpeed)
+ scrollspeed := int(settings["scrollspeed"].(float64))
+ v.ScrollDown(scrollspeed)
}
}
if relocate {
- v.Relocate()
+ v.Relocate(scrollmargin)
}
if settings["syntax"].(bool) {
v.matches = Match(v)