mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
Demonstrate that a wrapped selection is reported by segment
The lines a selection covers are asked for by view line, which counts the segments a wrapping view breaks a line into, and then used to index the content, whose lines are unwrapped. The two agree only for a view whose content doesn't wrap. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
cfbbf18656
commit
2d72ca889b
@@ -820,3 +820,32 @@ func TestApplySelTextColor(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A view that wraps draws one line of its content as several view lines, and the
|
||||
// cursor and the range anchor count those. What is asked about a selection is
|
||||
// which lines of the content it covers, so those are what it has to be reported
|
||||
// in.
|
||||
func TestSelectedLinesOfWrappedContent(t *testing.T) {
|
||||
v := NewView("name", 0, 0, 11, 10, OutputNormal) // InnerWidth 10
|
||||
v.Wrap = true
|
||||
v.Highlight = true
|
||||
|
||||
// "a line that wraps" takes two view lines, so the four lines of content are
|
||||
// drawn as five: "one", "two", "a line th", "at wraps", "four".
|
||||
v.writeString("one\ntwo\na line that wraps\nfour\n")
|
||||
assert.Equal(t, 5, v.ViewLinesHeight())
|
||||
|
||||
// The cursor on the wrapped line's second half is on that line.
|
||||
v.FocusPoint(0, 3, false)
|
||||
/* EXPECTED:
|
||||
assert.Equal(t, "a line that wraps", v.SelectedLine())
|
||||
ACTUAL: */
|
||||
assert.Equal(t, "four", v.SelectedLine())
|
||||
|
||||
// A range over both halves of the wrapped line covers one line of content.
|
||||
v.SetRangeSelectStart(2)
|
||||
/* EXPECTED:
|
||||
assert.Equal(t, []string{"a line that wraps"}, v.SelectedLines())
|
||||
ACTUAL: */
|
||||
assert.Equal(t, []string{"a line that wraps", "four"}, v.SelectedLines())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user