Skip to content

Commit 5d446f5

Browse files
committed
Render hyperlinks in last line of view if it doesn't end with a line feed
Previously we would render hyperlinks only when seeing a newline; but for some views, the last line doesn't end in a newline (e.g. lazygit's confirmation panels), so hyperlinks were never rendered in the last line for those.
1 parent b376cb0 commit 5d446f5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

view.go

+2
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ func (v *View) writeRunes(p []rune) {
822822

823823
if v.pendingNewline {
824824
finishLine()
825+
} else {
826+
v.autoRenderHyperlinksInCurrentLine()
825827
}
826828

827829
v.updateSearchPositions()

view_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ func TestUpdatedCursorAndOrigin(t *testing.T) {
117117
}
118118
}
119119

120+
func TestAutoRenderingHyperlinks(t *testing.T) {
121+
v := NewView("name", 0, 0, 10, 10, OutputNormal)
122+
v.AutoRenderHyperLinks = true
123+
124+
v.writeRunes([]rune("htt"))
125+
// No hyperlinks are generated for incomplete URLs
126+
assert.Equal(t, "", v.lines[0][0].hyperlink)
127+
// Writing more characters to the same line makes the link complete (even
128+
// though we didn't see a newline yet)
129+
v.writeRunes([]rune("ps://example.com"))
130+
assert.Equal(t, "https://example.com", v.lines[0][0].hyperlink)
131+
132+
v.Clear()
133+
// Valid but incomplete URL
134+
v.writeRunes([]rune("https://exa"))
135+
assert.Equal(t, "https://exa", v.lines[0][0].hyperlink)
136+
// Writing more characters to the same fixes the link
137+
v.writeRunes([]rune("mple.com"))
138+
assert.Equal(t, "https://example.com", v.lines[0][0].hyperlink)
139+
}
140+
120141
func TestContainsColoredText(t *testing.T) {
121142
hexColor := func(text string, hexStr string) []cell {
122143
cells := make([]cell, len(text))

0 commit comments

Comments
 (0)