]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/view.go
Add scrollmargin option, rename scrollSpeed to scrollspeed for consistency, make...
[micro.git] / cmd / micro / view.go
index 078177b318d187b7ebc4cb547f631a7117980ea2..22a304c31c111b6d44e324bfaa23863fedb6581f 100644 (file)
@@ -196,21 +196,24 @@ func (v *View) ReOpen() {
                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
        }
 
@@ -257,6 +260,7 @@ func (v *View) HandleEvent(event tcell.Event) {
        // 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:
@@ -368,17 +372,17 @@ func (v *View) HandleEvent(event tcell.Event) {
                        }
                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)