From 052e764f29ab1a123ed0e7643c396c3fe805ebcc Mon Sep 17 00:00:00 2001 From: diniamo Date: Tue, 9 Jul 2024 02:16:21 +0200 Subject: [PATCH] accept-autosuggestion to return false if there was no autosuggestion to accept Example usage: bind ctrl-space accept-autosuggestion and execute Closes #10608 --- CHANGELOG.rst | 1 + doc_src/cmds/bind.rst | 2 +- src/reader.rs | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d7b5ab407..9921345a3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -180,6 +180,7 @@ New or improved bindings - New special input functions: - ``forward-char-passive`` and ``backward-char-passive`` are like their non-passive variants but do not accept autosuggestions or move focus in the completion pager (:issue:`10398`). - ``forward-token``, ``backward-token``, ``kill-token``, and ``backward-kill-token`` are similar to the ``*-bigword`` variants but for the whole argument token which includes escaped spaces (:issue:`2014`). +- The ``accept-autosuggestion`` special input function now returns false when there was nothing to accept. - Vi mode has seen some improvements but continues to suffer from the lack of people working on it. - Insert-mode :kbd:`ctrl-n` accepts autosuggestions (:issue:`10339`). - Outside insert mode, the cursor will no longer be placed beyond the last character on the commandline. diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index f67dd62f3..a68a5f02f 100644 --- a/doc_src/cmds/bind.rst +++ b/doc_src/cmds/bind.rst @@ -112,7 +112,7 @@ The following special input functions are available: only execute the next function if the previous succeeded (note: only some functions report success) ``accept-autosuggestion`` - accept the current autosuggestion + accept the current autosuggestion. Returns false when there was nothing to accept. ``backward-char`` move one character to the left. diff --git a/src/reader.rs b/src/reader.rs index b99d4b7c4..4c7b5556e 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2984,7 +2984,9 @@ impl<'a> Reader<'a> { self.input_data.function_set_status(success); } rl::AcceptAutosuggestion => { + let success = !self.autosuggestion.is_empty(); self.accept_autosuggestion(true, false, MoveWordStyle::Punctuation); + self.input_data.function_set_status(success); } rl::TransposeChars => { let (elt, el) = self.active_edit_line();