From 9c8c1cb479c1b66d98f143f2e4a2840edbbc1fae Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 18 Aug 2026 17:22:54 +0200 Subject: [PATCH] Demonstrate that resizing a wrapping view moves its selection The scroll offset, the cursor and a range's anchor are all view lines, which count the segments each line of the content is wrapped into. A change of width wraps the content differently, so every one of them ends up on a different line than the one it was put on. Co-authored-by: Claude Opus 5 (1M context) --- pkg/gocui/view_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/gocui/view_test.go b/pkg/gocui/view_test.go index 2b2d50fd2..6fc33bbbd 100644 --- a/pkg/gocui/view_test.go +++ b/pkg/gocui/view_test.go @@ -843,3 +843,33 @@ func TestSelectedLinesOfWrappedContent(t *testing.T) { v.SetRangeSelectStart(2) assert.Equal(t, []string{"a line that wraps"}, v.SelectedLines()) } + +// Resizing a view throws away the wrapping of its content and wraps it again for +// the new width, which moves every line of it to a different view line. The +// positions into the view count view lines, so they all have to come along. +func TestResizingAWrappingViewKeepsItsPlaceInTheContent(t *testing.T) { + g := &Gui{} + v, _ := g.SetView("name", 0, 0, 11, 10, 0) // InnerWidth 10 + v.Wrap = true + v.Highlight = true + + // Two wrapping lines, with a single line between them: eight view lines for + // five lines of content. + v.writeString("one\na line that wraps\ntwo\nanother wrapping line\nthree\n") + assert.Equal(t, 8, v.ViewLinesHeight()) + + // A range over the whole of the second wrapping line, which is drawn as view + // lines 4 to 6. + v.SetRangeSelectStart(4) + v.FocusPoint(0, 6, false) + assert.Equal(t, []string{"another wrapping line"}, v.SelectedLines()) + + // Widen the view so that nothing wraps any more. + _, _ = g.SetView("name", 0, 0, 31, 10, 0) // InnerWidth 30 + assert.Equal(t, 5, v.ViewLinesHeight()) + + /* EXPECTED: + assert.Equal(t, []string{"another wrapping line"}, v.SelectedLines()) + ACTUAL: */ + assert.Equal(t, []string{"three"}, v.SelectedLines()) +}