diff --git a/app.go b/app.go index 2dac232e..f21343c4 100644 --- a/app.go +++ b/app.go @@ -9,6 +9,7 @@ import ( "os/exec" "os/signal" "path/filepath" + "slices" "strings" "syscall" "time" @@ -694,8 +695,9 @@ func (app *app) menuComplete(direction int) { app.menuCompInd = len(app.menuComps) - 1 } - app.menuCompTmp[len(app.menuCompTmp)-1] = app.menuComps[app.menuCompInd].result - app.ui.cmdAccLeft = []rune(strings.Join(app.menuCompTmp, " ")) + toks := slices.Clone(app.menuCompTmp) + toks[len(toks)-1] = app.menuComps[app.menuCompInd].result + app.ui.cmdAccLeft = []rune(strings.Join(toks, " ")) } app.ui.menu, app.ui.menuSelect = listMatches(app.ui.screen, app.menuComps, app.menuCompInd) } @@ -717,6 +719,10 @@ func (app *app) watchDir(dir *dir) { func (app *app) exportMode() { getMode := func() string { + if app.menuCompActive { + return "compmenu" + } + if strings.HasPrefix(app.ui.cmdPrefix, "delete") { return "delete" } diff --git a/complete.go b/complete.go index e8c6b2ac..980f2ede 100644 --- a/complete.go +++ b/complete.go @@ -109,6 +109,7 @@ var ( "cmd-left", "cmd-lowercase-word", "cmd-menu-accept", + "cmd-menu-discard", "cmd-menu-complete", "cmd-menu-complete-back", "cmd-right", diff --git a/doc.md b/doc.md index 15e06c1a..dc066da3 100644 --- a/doc.md +++ b/doc.md @@ -120,6 +120,7 @@ The following Command-line mode commands are provided by lf: cmd-menu-complete cmd-menu-complete-back cmd-menu-accept + cmd-menu-discard cmd-enter (default '' and '') cmd-interrupt (default '') cmd-history-next (default '' and '') @@ -654,6 +655,10 @@ You can use the assigned keys to display the menu and then cycle through complet Accept the currently selected match in menu completion and close the menu. +## cmd-menu-discard + +Discard the currently selected match in menu completion and close the menu. + ## cmd-enter (default `` and ``) Execute the current line. @@ -1240,7 +1245,7 @@ Value of the count associated with the current command. Current mode that `lf` is operating in. This is useful for customizing keybindings depending on what the current mode is. -Possible values are `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, `visual` and `unknown`. +Possible values are `compmenu`, `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, `visual` and `unknown`. # SPECIAL COMMANDS diff --git a/doc.txt b/doc.txt index 78f061f2..cf242880 100644 --- a/doc.txt +++ b/doc.txt @@ -110,6 +110,7 @@ The following Command-line mode commands are provided by lf: cmd-menu-complete cmd-menu-complete-back cmd-menu-accept + cmd-menu-discard cmd-enter (default '' and '') cmd-interrupt (default '') cmd-history-next (default '' and '') @@ -680,6 +681,11 @@ cmd-menu-accept Accept the currently selected match in menu completion and close the menu. +cmd-menu-discard + +Discard the currently selected match in menu completion and close the +menu. + cmd-enter (default and ) Execute the current line. @@ -1340,8 +1346,8 @@ lf_mode Current mode that lf is operating in. This is useful for customizing keybindings depending on what the current mode is. Possible values are -delete, rename, filter, find, mark, search, command, shell, pipe (when -running a shell-pipe command), normal, visual and unknown. +compmenu, delete, rename, filter, find, mark, search, command, shell, +pipe (when running a shell-pipe command), normal, visual and unknown. SPECIAL COMMANDS diff --git a/eval.go b/eval.go index 5b05312b..1eda0070 100644 --- a/eval.go +++ b/eval.go @@ -1850,6 +1850,13 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.menu = "" app.ui.menuSelect = nil app.menuCompActive = false + case "cmd-menu-discard": + if app.menuCompActive { + app.ui.cmdAccLeft = []rune(strings.Join(app.menuCompTmp, " ")) + } + app.ui.menu = "" + app.ui.menuSelect = nil + app.menuCompActive = false case "cmd-enter": s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)) if len(s) == 0 && app.ui.cmdPrefix != "filter: " && app.ui.cmdPrefix != ">" { @@ -2270,6 +2277,7 @@ func (e *callExpr) eval(app *app, args []string) { "cmd-menu-complete", "cmd-menu-complete-back", "cmd-menu-accept", + "cmd-menu-discard", "cmd-enter", "cmd-interrupt", "cmd-history-next", diff --git a/lf.1 b/lf.1 index 9567d24f..a840a21c 100644 --- a/lf.1 +++ b/lf.1 @@ -123,6 +123,7 @@ cmd\-complete (default \(aq\(aq) cmd\-menu\-complete cmd\-menu\-complete\-back cmd\-menu\-accept +cmd\-menu\-discard cmd\-enter (default \(aq\(aq and \(aq\(aq) cmd\-interrupt (default \(aq\(aq) cmd\-history\-next (default \(aq\(aq and \(aq\(aq) @@ -626,6 +627,9 @@ completion options. .SS cmd\-menu\-accept Accept the currently selected match in menu completion and close the menu. +.SS cmd\-menu\-discard +Discard the currently selected match in menu completion and close the +menu. .SS cmd\-enter (default \f[CR]\f[R] and \f[CR]\f[R]) Execute the current line. .SS cmd\-interrupt (default \f[CR]\f[R]) @@ -1151,11 +1155,11 @@ Value of the count associated with the current command. Current mode that \f[CR]lf\f[R] is operating in. This is useful for customizing keybindings depending on what the current mode is. -Possible values are \f[CR]delete\f[R], \f[CR]rename\f[R], -\f[CR]filter\f[R], \f[CR]find\f[R], \f[CR]mark\f[R], \f[CR]search\f[R], -\f[CR]command\f[R], \f[CR]shell\f[R], \f[CR]pipe\f[R] (when running a -shell\-pipe command), \f[CR]normal\f[R], \f[CR]visual\f[R] and -\f[CR]unknown\f[R]. +Possible values are \f[CR]compmenu\f[R], \f[CR]delete\f[R], +\f[CR]rename\f[R], \f[CR]filter\f[R], \f[CR]find\f[R], \f[CR]mark\f[R], +\f[CR]search\f[R], \f[CR]command\f[R], \f[CR]shell\f[R], \f[CR]pipe\f[R] +(when running a shell\-pipe command), \f[CR]normal\f[R], +\f[CR]visual\f[R] and \f[CR]unknown\f[R]. .SH SPECIAL COMMANDS This section shows information about special shell commands. .SS open