X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fview.go;h=22a304c31c111b6d44e324bfaa23863fedb6581f;hb=116b247439cbda6f1f1ceeb9707ee6a6af720368;hp=078177b318d187b7ebc4cb547f631a7117980ea2;hpb=0673396335d0adf117c836838ecbce3949e9c6e4;p=micro.git diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 078177b3..22a304c3 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -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)