Keep undo history across prompts

After abandoning a commandline (for example with ctrl-c) it's nice to be
able to restore it. There is little reason to discard the requisite undo
information, so keep it.
This commit is contained in:
Johannes Altmanninger 2024-04-29 09:16:07 +02:00
parent 3afe0bb569
commit 964d3fff15
3 changed files with 5 additions and 8 deletions

View File

@ -60,6 +60,7 @@ Notable improvements and fixes
Any key argument that starts with an ASCII control character (like ``\e`` or ``\cX``) or is up to 3 characters long and not a named key and does not contain ``,`` or ``-`` will be interpreted in the old syntax to keep compatibility for the majority of bindings. This should cover the majority of bindings in use. Any key argument that starts with an ASCII control character (like ``\e`` or ``\cX``) or is up to 3 characters long and not a named key and does not contain ``,`` or ``-`` will be interpreted in the old syntax to keep compatibility for the majority of bindings. This should cover the majority of bindings in use.
- A new function ``fish_should_add_to_history`` can be overridden to decide whether a command should be added to the history (:issue:`10302`). - A new function ``fish_should_add_to_history`` can be overridden to decide whether a command should be added to the history (:issue:`10302`).
- :kbd:`ctrl-c` during command input no longer prints ``^C`` and a new prompt but merely clears the command line. This restores the behavior from version 2.2. To revert to the old behavior use ``bind ctrl-c __fish_cancel_commandline`` (:issue:`10213`). - :kbd:`ctrl-c` during command input no longer prints ``^C`` and a new prompt but merely clears the command line. This restores the behavior from version 2.2. To revert to the old behavior use ``bind ctrl-c __fish_cancel_commandline`` (:issue:`10213`).
- Undo history is no longer truncated after every command but kept for the lifetime of the shell process.
- The :kbd:`ctrl-r` history search now uses glob syntax (:issue:`10131`). - The :kbd:`ctrl-r` history search now uses glob syntax (:issue:`10131`).
- The :kbd:`ctrl-r` history search now operates only on the line at cursor, making it easier to quickly compose a multi-line command by recalling previous commands. - The :kbd:`ctrl-r` history search now operates only on the line at cursor, making it easier to quickly compose a multi-line command by recalling previous commands.
- Abbreviations can now be restricted to specific commands. For instance:: - Abbreviations can now be restricted to specific commands. For instance::

View File

@ -160,17 +160,13 @@ impl EditableLine {
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.undo_history.clear();
if self.is_empty() { if self.is_empty() {
return; return;
} }
let len = self.len(); self.push_edit(
apply_edit( Edit::new(0..self.len(), L!("").to_owned()),
&mut self.text, /*allow_coalesce=*/ false,
&mut self.colors,
&Edit::new(0..len, L!("").to_owned()),
); );
self.set_position(0);
} }
/// Modify the commandline according to @edit. Most modifications to the /// Modify the commandline according to @edit. Most modifications to the

View File

@ -625,8 +625,8 @@ fn read_i(parser: &Parser) -> i32 {
continue; continue;
} }
data.update_buff_pos(EditableLineTag::Commandline, Some(0));
data.command_line.clear(); data.command_line.clear();
data.update_buff_pos(EditableLineTag::Commandline, None);
data.command_line_changed(EditableLineTag::Commandline); data.command_line_changed(EditableLineTag::Commandline);
data.screen.write_bytes(b"\x1b]133;C\x07"); data.screen.write_bytes(b"\x1b]133;C\x07");
event::fire_generic(parser, L!("fish_preexec").to_owned(), vec![command.clone()]); event::fire_generic(parser, L!("fish_preexec").to_owned(), vec![command.clone()]);