fix: better suggestion and overlay movement on key presses (#12)
- support history suggestions for aliases https://github.com/versenilvis/IRIS/commit/0ae25d05ce0faf8ff2eeee9aa3fbb5889d9ad511 - merge spec and history results (https://github.com/versenilvis/IRIS/commit/315c94f12bb689ad6b39b1f0ce5e0bdef71f38d5) - add 25ms pty throttle and optimize ctrl+l (https://github.com/versenilvis/IRIS/commit/1e603d74c208be00f6b2cb79a628416455711c3a) - align suggestion menu to col 1 (https://github.com/versenilvis/IRIS/commit/e307b210849af65276e93e1cff8895f3b54937ff) - resolve zsh ipc fd mismatch and generate autocomplete hooks (https://github.com/versenilvis/IRIS/pull/12/commits/2199607fad8122ec441ff4b99e562ca62bd948ff) - fix: eliminate prompt duplication and freeze UI movement during menu navigation https://github.com/versenilvis/IRIS/pull/12/commits/6783989a49f0a68d01bad542588983a5c7b597a2
This commit is contained in:
+41
-33
@@ -12,53 +12,61 @@ import (
|
||||
// mergeResults collects and dedupes suggestions for a query and mode
|
||||
// example: mergeResults("git ", "spec")
|
||||
func MergeResults(query string, mode string) []core.Suggestion {
|
||||
if query == "" && mode != "history" {
|
||||
debugLog("[Merge] Query empty, returning nil")
|
||||
return nil
|
||||
}
|
||||
|
||||
maxSugg := config.Get().UI.MaxSuggestions
|
||||
normalizedQuery := strings.TrimSpace(query)
|
||||
seen := make(map[string]bool)
|
||||
deduped := []core.Suggestion{}
|
||||
|
||||
if mode == "history" {
|
||||
histResults, _ := integration.SearchHistory(query)
|
||||
for _, h := range histResults {
|
||||
normalizedCmd := strings.TrimSpace(h.Cmd)
|
||||
if seen[normalizedCmd] {
|
||||
continue
|
||||
}
|
||||
seen[normalizedCmd] = true
|
||||
deduped = append(deduped, core.Suggestion{
|
||||
Cmd: h.Cmd,
|
||||
Desc: " history",
|
||||
Icon: fmt.Sprintf("%d", h.ID),
|
||||
})
|
||||
if len(deduped) >= maxSugg {
|
||||
break
|
||||
}
|
||||
}
|
||||
debugLog("[Merge] History mode found %d items", len(deduped))
|
||||
return deduped
|
||||
// always call lookup to scan aliases and get spec suggestions
|
||||
var cmdResults []core.Suggestion
|
||||
if query != "" {
|
||||
debugLog("[Merge] Calling Lookup for '%s'", query)
|
||||
cmdResults = core.Lookup(query)
|
||||
}
|
||||
|
||||
debugLog("[Merge] Calling Lookup for '%s'", query)
|
||||
cmdResults := core.Lookup(query)
|
||||
debugLog("[Merge] Lookup returned %d raw items", len(cmdResults))
|
||||
// search history if in history mode
|
||||
var histResults []integration.HistResult
|
||||
if mode == "history" {
|
||||
aliases := core.GetAliasesCopy()
|
||||
histResults, _ = integration.SearchHistory(query, aliases)
|
||||
}
|
||||
|
||||
for _, s := range cmdResults {
|
||||
normalizedQuery := strings.TrimSpace(query)
|
||||
|
||||
// add suggestion helper to deduplicate
|
||||
addSuggestion := func(s core.Suggestion) {
|
||||
normalizedCmd := strings.TrimSpace(s.Cmd)
|
||||
if normalizedCmd == normalizedQuery { // filter exact matches to avoid loops
|
||||
debugLog("[Merge] Filtered EXACT MATCH: '%s'", normalizedCmd)
|
||||
continue
|
||||
if normalizedCmd == "" {
|
||||
return
|
||||
}
|
||||
// filter exact match to avoid loops and redundant suggestions
|
||||
if normalizedCmd == normalizedQuery {
|
||||
return
|
||||
}
|
||||
|
||||
if !seen[s.Cmd] {
|
||||
seen[s.Cmd] = true
|
||||
deduped = append(deduped, s)
|
||||
}
|
||||
}
|
||||
|
||||
if mode == "history" {
|
||||
// history mode: history first, then spec/alias
|
||||
for _, h := range histResults {
|
||||
addSuggestion(core.Suggestion{
|
||||
Cmd: h.Cmd,
|
||||
Desc: " history",
|
||||
Icon: fmt.Sprintf("%d", h.ID),
|
||||
})
|
||||
}
|
||||
for _, s := range cmdResults {
|
||||
addSuggestion(s)
|
||||
}
|
||||
} else {
|
||||
// spec mode: spec/alias only
|
||||
for _, s := range cmdResults {
|
||||
addSuggestion(s)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deduped) > maxSugg {
|
||||
deduped = deduped[:maxSugg]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user