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 view.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ func (v *View) writeRunes(p []rune) {

if v.pendingNewline {
finishLine()
} else {
v.autoRenderHyperlinksInCurrentLine()
}

v.updateSearchPositions()
Expand Down
21 changes: 21 additions & 0 deletions view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ func TestUpdatedCursorAndOrigin(t *testing.T) {
}
}

func TestAutoRenderingHyperlinks(t *testing.T) {
v := NewView("name", 0, 0, 10, 10, OutputNormal)
v.AutoRenderHyperLinks = true

v.writeRunes([]rune("htt"))
// No hyperlinks are generated for incomplete URLs
assert.Equal(t, "", v.lines[0][0].hyperlink)
// Writing more characters to the same line makes the link complete (even
// though we didn't see a newline yet)
v.writeRunes([]rune("ps://example.com"))
assert.Equal(t, "https://example.com", v.lines[0][0].hyperlink)

v.Clear()
// Valid but incomplete URL
v.writeRunes([]rune("https://exa"))
assert.Equal(t, "https://exa", v.lines[0][0].hyperlink)
// Writing more characters to the same fixes the link
v.writeRunes([]rune("mple.com"))
assert.Equal(t, "https://example.com", v.lines[0][0].hyperlink)
}

func TestContainsColoredText(t *testing.T) {
hexColor := func(text string, hexStr string) []cell {
cells := make([]cell, len(text))
Expand Down