From 88d6ee4e57d324076ae6b41aacc49241ad980ca5 Mon Sep 17 00:00:00 2001 From: verse91 Date: Sun, 10 May 2026 01:02:43 +0700 Subject: [PATCH] fix(history): fuzzy search shows commands that no one need --- integration/history.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/integration/history.go b/integration/history.go index d3d37c2..cfe6dd0 100644 --- a/integration/history.go +++ b/integration/history.go @@ -140,10 +140,24 @@ func SearchHistory(query string) ([]HistResult, error) { return results, nil } - matches := searcherCache.SearchWithScores(query, &fuzzy.SearchOptions{Limit: 100}) + matches := searcherCache.SearchWithScores(query, &fuzzy.SearchOptions{Limit: 200}) + + // when query has a clear first word, only keep history entries that share the same first word + // this prevents e.g. curl commands from showing up when typing "git ..." + queryFirstWord := "" + if fields := strings.Fields(query); len(fields) > 0 { + queryFirstWord = strings.ToLower(fields[0]) + } var results []HistResult for _, m := range matches { + if queryFirstWord != "" { + if fields := strings.Fields(m.Str); len(fields) > 0 { + if strings.ToLower(fields[0]) != queryFirstWord { + continue + } + } + } results = append(results, HistResult{ ID: idMapCache[m.Str], Cmd: m.Str,