Using a Unique Function
Previously the bug that I mentioned here `f7c2283355/utils/utils.go (L147)
` was caused due to the
replication of matched Indexes.
Hence using the utils.Unique function to only get the unique elements in the slice.
This commit is contained in:
parent
f7c2283355
commit
a3c5af06c8
@ -16,14 +16,14 @@ func UpdateBuffSearchView(inputTable *tview.Table, m fuzzy.Matches, f []FileNode
|
|||||||
} else {
|
} else {
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
if len(f[v.Index].Children) != 0 {
|
if len(f[v.Index].Children) != 0 {
|
||||||
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(v.MatchedIndexes, f[v.Index].Path, "[#0000ff:-:bi]")).
|
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[#0000ff:-:bi]")).
|
||||||
SetAlign(tview.AlignLeft).
|
SetAlign(tview.AlignLeft).
|
||||||
SetStyle(tcell.StyleDefault.
|
SetStyle(tcell.StyleDefault.
|
||||||
Foreground(tcell.ColorYellow).
|
Foreground(tcell.ColorYellow).
|
||||||
Background(tcell.ColorBlack).
|
Background(tcell.ColorBlack).
|
||||||
Bold(true)))
|
Bold(true)))
|
||||||
} else {
|
} else {
|
||||||
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(v.MatchedIndexes, f[v.Index].Title, "[#fbff00:-:bi]")).
|
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[#fbff00:-:bi]")).
|
||||||
SetAlign(tview.AlignLeft).
|
SetAlign(tview.AlignLeft).
|
||||||
SetStyle(tcell.StyleDefault.
|
SetStyle(tcell.StyleDefault.
|
||||||
Foreground(tcell.ColorGreen).
|
Foreground(tcell.ColorGreen).
|
||||||
|
@ -169,3 +169,15 @@ func GetMatchedString(a []int, s, color string) string {
|
|||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Unique(intSlice []int) []int {
|
||||||
|
keys := make(map[int]bool)
|
||||||
|
list := []int{}
|
||||||
|
for _, entry := range intSlice {
|
||||||
|
if _, exists := keys[entry]; !exists {
|
||||||
|
keys[entry] = true
|
||||||
|
list = append(list, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user