From d2909d93aaeee6667d2d0c042126b05fd7eb7dee Mon Sep 17 00:00:00 2001 From: verse91 Date: Mon, 27 Apr 2026 15:03:21 +0700 Subject: [PATCH] fix: wrong suggestion on chmod command --- commands/core/filegen.go | 37 ++++++++++++++++--------------------- commands/core/lookup.go | 5 +---- root/wrapper.go | 6 +++++- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/commands/core/filegen.go b/commands/core/filegen.go index 09f32c6..851205e 100644 --- a/commands/core/filegen.go +++ b/commands/core/filegen.go @@ -84,32 +84,27 @@ func FileGenerator(filters ...string) GeneratorFunc { fullPath := pathPrefix + name if entry.IsDir() { - results = append(results, Suggestion{ - Cmd: prefix + " " + fullPath + "/", - Desc: "directory", - }) - } else { - if dirOnly { + if dirOnly || len(filterSet) == 0 { + results = append(results, Suggestion{ + Cmd: fullPath + "/", + Desc: "directory", + }) + } + continue + } + // if filters are set, only show matching extensions + if len(filterSet) > 0 { + ext := strings.ToLower(filepath.Ext(name)) + if !filterSet[ext] { continue } - // if filters are set, only show matching extensions - if len(filterSet) > 0 { - ext := strings.ToLower(filepath.Ext(name)) - if !filterSet[ext] { - continue - } - } - results = append(results, Suggestion{ - Cmd: prefix + " " + fullPath, - Desc: fileDesc(), - }) } + results = append(results, Suggestion{ + Cmd: fullPath, + Desc: "file", + }) } return results } } - -func fileDesc() string { - return "file" -} diff --git a/commands/core/lookup.go b/commands/core/lookup.go index 7142c6d..c525c47 100644 --- a/commands/core/lookup.go +++ b/commands/core/lookup.go @@ -179,10 +179,7 @@ func Lookup(input string) []Suggestion { } finalCmd := g.Cmd - cleanLinePrefix := strings.TrimSpace(linePrefix) - if cleanLinePrefix != "" && !strings.HasPrefix(finalCmd, cleanLinePrefix) && !strings.HasPrefix(finalCmd, rootCmdName) { - finalCmd = cleanLinePrefix + " " + g.Cmd - } + finalCmd = strings.TrimSpace(linePrefix) + " " + g.Cmd newTokens := tokenize(finalCmd) if len(newTokens) > 0 { diff --git a/root/wrapper.go b/root/wrapper.go index 60db7e4..bad1135 100644 --- a/root/wrapper.go +++ b/root/wrapper.go @@ -380,7 +380,11 @@ func runWrapper() { ptmx.Write([]byte{0x15}) // ctrl+u to clear line ptmx.Write([]byte(selected)) - shouldOverlayDraw = false + overlay.Cursor = 0 // this prevents when you tab, it switchs between suggestions non-stop + + shouldOverlayDraw = true // <- rerender after tab to choose, if you set to false, + // when you press tab continuely, it will print all folder from menu suggestions + // and make the cursor jump to next line } continue }