Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/textview/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions ui/textview/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading