diff --git a/ui/textview/view.go b/ui/textview/view.go index 8b446902..172f9add 100644 --- a/ui/textview/view.go +++ b/ui/textview/view.go @@ -275,6 +275,8 @@ func (v *View) Declare(c ui.C, spec Spec) ui.Box { state.Content = max(state.Content, height) target := spec.PadY + float32(index)*v.lineH - (state.Viewport-v.lineH)/2 state.ScrollTo(min(max(target, 0), max(state.Content-state.Viewport, 0))) + // The area was declared before the request. Lay out this paint at the new offset. + outer.N().Scroll = state.Offset } } height = max(height, state.Viewport) diff --git a/ui/textview/view_test.go b/ui/textview/view_test.go index 7fb44f73..f43456ef 100644 --- a/ui/textview/view_test.go +++ b/ui/textview/view_test.go @@ -117,6 +117,22 @@ func (o *output) chord(character rune) { const trace = "Exception in thread \"main\" java.lang.IllegalStateException: boom" +func TestScrollToPaintsTheRequestedLineImmediately(t *testing.T) { + lines := make([]string, 128) + for i := range lines { + lines[i] = "output" + } + o := openOutput(t, lines...) + for _, target := range []int{115, 4} { + if _, visible := o.view.PointOf(textview.Point{Line: target}); visible { + t.Fatalf("line %d was already visible", target) + } + o.view.ScrollTo(target) + o.must(o.driver.Paint()) + o.at(target, 0) + } +} + // A drag selects from where it was pressed to where it was released, across lines, and // Primary+C copies exactly that text; a click selects nothing and Escape drops a selection. func TestDragAcrossLinesCopiesTheTextBetween(t *testing.T) {