From ee6936d689b1c4f2ef6eedfd063ff31f6e0f8dd9 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 19 Jun 2021 17:46:41 -0400 Subject: [PATCH] Fixes a minibuffer/cmdline completion bug If the user opened the cmdline and typed "help ", four completions would be correctly offered for help subarguments. But if the user then hit tab, the cmdline expanded incorrectly to "help help". --- ui/ui.go | 5 ----- widgets/minibuffer/minibuffer.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ui/ui.go b/ui/ui.go index 65f264fc..59a08543 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -1353,11 +1353,6 @@ func lastLineMode(app gowid.IApp) { return nil })) - MiniBuffer.Register("help", minibufferFn(func(gowid.IApp, ...string) error { - OpenTemplatedDialog(appView, "UIHelp", app) - return nil - })) - MiniBuffer.Register("no-theme", minibufferFn(func(app gowid.IApp, s ...string) error { mode := theme.Mode(app.GetColorMode()).String() // more concise termshark.DeleteConf(fmt.Sprintf("main.theme-%s", mode)) diff --git a/widgets/minibuffer/minibuffer.go b/widgets/minibuffer/minibuffer.go index 42d21e50..41663526 100644 --- a/widgets/minibuffer/minibuffer.go +++ b/widgets/minibuffer/minibuffer.go @@ -294,10 +294,14 @@ func (w *Widget) handleSelection(keyIsEnter bool, app gowid.IApp) { extraPrefix += string(c) } longestPrefixPartial := partials[selectedIdx] - // e.g. "cl" + "ear-" from ["clear-packets", "clear-filter"] - longestPrefixPartial.qword = words[len(words)-1] + extraPrefix - w.ed.SetText(longestPrefixPartial.Line(), app) - w.ed.SetCursorPos(longestPrefixPartial.CursorPos(), app) + // if the user types e.g. "help " then hits tab, extraPrefix will be "" (no characters typed + // to start selection of next argument) so don't complete. + if extraPrefix != "" { + // e.g. "cl" + "ear-" from ["clear-packets", "clear-filter"] + longestPrefixPartial.qword = words[len(words)-1] + extraPrefix + w.ed.SetText(longestPrefixPartial.Line(), app) + w.ed.SetCursorPos(longestPrefixPartial.CursorPos(), app) + } } } }