Skip to content

Commit

Permalink
tui: remove duplicated links
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 26, 2023
1 parent 38ac070 commit 05280b7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/tui/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (i item) FilterValue() string { return "" }

func getItems(text string) []list.Item {
links := xurls.Strict.FindAllString(text, -1)
links = removeDuplicates(links)

urls := make([]*url.URL, len(links))
for i, link := range links {
Expand Down Expand Up @@ -134,3 +135,14 @@ func getItems(text string) []list.Item {
}
return items
}

func removeDuplicates(dups []string) (uniq []string) {
hash := map[string]bool{}
for _, dup := range dups {
if !hash[dup] {
hash[dup] = true
uniq = append(uniq, dup)
}
}
return
}

0 comments on commit 05280b7

Please sign in to comment.