diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-17 19:01:02 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-17 19:45:57 +1100 |
commit | d672b7342f12c64112cd6b59fb5e4286a7cb92b4 (patch) | |
tree | 4b4c51680b05217708ce7ca596b6a47ffc170838 /pkg/gui/tasks_adapter.go | |
parent | e7c27b6f4aef44a2391dd207e1321008b5d1dcff (diff) |
stop resetting scroll all the time
Diffstat (limited to 'pkg/gui/tasks_adapter.go')
-rw-r--r-- | pkg/gui/tasks_adapter.go | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/pkg/gui/tasks_adapter.go b/pkg/gui/tasks_adapter.go index 71cde5b00..8d1f289db 100644 --- a/pkg/gui/tasks_adapter.go +++ b/pkg/gui/tasks_adapter.go @@ -9,9 +9,10 @@ import ( ) func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error { + cmdStr := strings.Join(cmd.Args, " ") gui.Log.WithField( "command", - strings.Join(cmd.Args, " "), + cmdStr, ).Debug("RunCommand") _, height := view.Size() @@ -29,17 +30,7 @@ func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error return err } - if err := manager.NewTask(manager.NewCmdTask(r, cmd, prefix, height+oy+10, nil)); err != nil { - return err - } - - return nil -} - -func (gui *Gui) newTask(view *gocui.View, f func(chan struct{}) error) error { - manager := gui.getManager(view) - - if err := manager.NewTask(f); err != nil { + if err := manager.NewTask(manager.NewCmdTask(r, cmd, prefix, height+oy+10, nil), cmdStr); err != nil { return err } @@ -47,29 +38,24 @@ func (gui *Gui) newTask(view *gocui.View, f func(chan struct{}) error) error { } func (gui *Gui) newStringTask(view *gocui.View, str string) error { - manager := gui.getManager(view) - - f := func(stop chan struct{}) error { - gui.renderString(view, str) - return nil - } - - if err := manager.NewTask(f); err != nil { - return err - } - - return nil + // using str so that if rendering the exact same thing we don't reset the origin + return gui.newStringTaskWithKey(view, str, str) } func (gui *Gui) newStringTaskWithoutScroll(view *gocui.View, str string) error { + // using empty key so that on subsequent calls we won't reset the view's origin + return gui.newStringTaskWithKey(view, str, "") +} + +func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) error { manager := gui.getManager(view) f := func(stop chan struct{}) error { - gui.setViewContent(view, str) + gui.renderString(view, str) return nil } - if err := manager.NewTask(f); err != nil { + if err := manager.NewTask(f, key); err != nil { return err } @@ -97,8 +83,29 @@ func (gui *Gui) getManager(view *gocui.View) *tasks.ViewBufferManager { }) }, func() { + // Need to check if the content of the view is well past the origin. + // It would be better to use .ViewLinesHeight here (given it considers + // wrapping) but when this function is called they haven't been written to yet. + linesHeight := view.LinesHeight() + _, height := view.Size() + _, originY := view.Origin() + if linesHeight < originY { + newOriginY := linesHeight - height + if newOriginY < 0 { + newOriginY = 0 + } + err := view.SetOrigin(0, newOriginY) + if err != nil { + panic(err) + } + + } + view.FlushStaleCells() }, + func() { + _ = view.SetOrigin(0, 0) + }, ) gui.viewBufferManagerMap[view.Name()] = manager } |