From 7053a7d757c1c9c8e284b45d0794358e6d60694c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 14 Jun 2023 11:10:57 -0300 Subject: [PATCH] feat(deps): update fuzzy library (#379) --- go.mod | 2 +- go.sum | 4 ++-- list/list.go | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7df7cfa..52266da 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mattn/go-runewidth v0.0.14 github.com/muesli/reflow v0.3.0 github.com/muesli/termenv v0.15.1 - github.com/sahilm/fuzzy v0.1.0 + github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f ) require ( diff --git a/go.sum b/go.sum index 04f3e5b..016700e 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4AN github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= -github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y= +github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/list/list.go b/list/list.go index f286274..428d775 100644 --- a/list/list.go +++ b/list/list.go @@ -87,7 +87,7 @@ type Rank struct { // DefaultFilter uses the sahilm/fuzzy to filter through the list. // This is set by default. func DefaultFilter(term string, targets []string) []Rank { - var ranks = fuzzy.Find(term, targets) + ranks := fuzzy.Find(term, targets) sort.Stable(ranks) result := make([]Rank, len(ranks)) for i, r := range ranks { @@ -99,6 +99,20 @@ func DefaultFilter(term string, targets []string) []Rank { return result } +// UnsortedFilter uses the sahilm/fuzzy to filter through the list. It does not +// sort the results. +func UnsortedFilter(term string, targets []string) []Rank { + ranks := fuzzy.FindNoSort(term, targets) + result := make([]Rank, len(ranks)) + for i, r := range ranks { + result[i] = Rank{ + Index: r.Index, + MatchedIndexes: r.MatchedIndexes, + } + } + return result +} + type statusMessageTimeoutMsg struct{} // FilterState describes the current filtering state on the model.