From 301e4d497e09c7257f6e4f75f92256c1fab6483b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 27 Apr 2024 09:04:05 +0200 Subject: [PATCH] Make shift-delete also delete current autosuggestion This is a bit more convenient than using "history delete". --- CHANGELOG.rst | 1 + src/reader.rs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ad5ed45da..6bc5bfd20 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -138,6 +138,7 @@ New or improved bindings For example, ``commandline -f yank -f yank-pop`` inserts the last-but-one entry from the kill ring. - When the cursor is on a command that resolves to an executable script, :kbd:`alt-o` will now open that script in your editor (:issue:`10266`). - During up-arrow history search, :kbd:`shift-delete` will delete the current search item and move to the next older item. Previously this was only supported in the history pager. + Same for autosuggestions. - Some improvements to the :kbd:`alt-e` binding which edits the commandline in an external editor: - The editor's cursor position is copied back to fish. This is currently supported for Vim and Kakoune. - Cursor position synchronization is only supported for a set of known editors. This has been extended by also resolving aliases. For example use ``complete --wraps my-vim vim`` to synchronize cursors when `EDITOR=my-vim`. diff --git a/src/reader.rs b/src/reader.rs index fc625f1ad..c507727b2 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2579,11 +2579,20 @@ impl ReaderData { } rl::HistoryPagerDelete => { // Also applies to ordinary history search. - if !self.history_search.is_at_end() { - self.history.remove(self.history_search.current_result()); + let is_history_search = !self.history_search.is_at_end(); + if is_history_search || !self.autosuggestion.is_empty() { + self.history.remove(if is_history_search { + self.history_search.current_result() + } else { + &self.autosuggestion.text + }); self.history.save(); - self.history_search.handle_deletion(); - self.update_command_line_from_history_search(); + if is_history_search { + self.history_search.handle_deletion(); + self.update_command_line_from_history_search(); + } else { + self.autosuggestion.clear(); + } self.inputter.function_set_status(true); return; }