diff --git a/processor/helpers.go b/processor/helpers.go index ad528dc..42484b3 100644 --- a/processor/helpers.go +++ b/processor/helpers.go @@ -4,9 +4,10 @@ package processor import ( "fmt" - str "github.com/boyter/cs/str" "os" "time" + + str "github.com/boyter/cs/str" ) // Returns the current time as a millisecond timestamp @@ -32,13 +33,6 @@ func makeFuzzyDistanceOne(term string) []string { return vals } - // This tends to produce bad results - // Split apart so turn "test" into "t" "est" then "te" "st" - //for i := 0; i < len(term); i++ { - // vals = append(vals, term[:i]) - // vals = append(vals, term[i:]) - //} - // Delete letters so turn "test" into "est" "tst" "tet" for i := 0; i < len(term); i++ { vals = append(vals, term[:i]+term[i+1:]) @@ -51,6 +45,13 @@ func makeFuzzyDistanceOne(term string) []string { } } + // Replace a letter or digit which effectively does transpose for us + for i := 0; i < len(term); i++ { + for _, b := range letterDigitFuzzyBytes { + vals = append(vals, term[:i]+string(b)+term[i+1:]) + } + } + // Insert a letter or digit for i := 0; i < len(term); i++ { for _, b := range letterDigitFuzzyBytes { diff --git a/processor/tui.go b/processor/tui.go index d15277a..0c69704 100644 --- a/processor/tui.go +++ b/processor/tui.go @@ -4,14 +4,15 @@ package processor import ( "fmt" - "github.com/boyter/cs/file" - str "github.com/boyter/cs/str" "runtime" "strconv" "strings" "sync" "time" + "github.com/boyter/cs/file" + str "github.com/boyter/cs/str" + "github.com/gdamore/tcell" "github.com/rivo/tview" ) @@ -51,6 +52,10 @@ func tuiSearch(app *tview.Application, textView *tview.TextView, searchTerm sear tuiFileWalker.Terminate() } + if tuiFileWalker != nil { + tuiFileWalker.Terminate() + } + // TODO still a race condition here to need to resolve as we call terminate multiple times // We lock here because we don't want another instance to run until // this one has terminated which should happen with the terminate call