mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-14 02:53:34 +08:00
Stop saving autosuggestions that we can't restore
Sorry, commit 51adba6ee0
(Restore autosuggestion after corrected
typo, 2025-01-10) was pushed too early. One issue is that it saves
autosuggestions also when we edit in the middle, where we can't
restore it. We'd still restore it in some cases, even though it
doesn't apply. This breaks invariants that may cause various problems
when interacting with the autosuggestion.
Fix it by only saving the autosuggestion when we will be able to
restore it correctly.
This commit is contained in:
parent
3d797b9eb8
commit
ba4ead6ead
|
@ -1257,11 +1257,9 @@ impl ReaderData {
|
|||
use AutosuggestionUpdate::*;
|
||||
match autosuggestion_update {
|
||||
Preserve => (),
|
||||
Remove => {
|
||||
if !self.autosuggestion.is_empty() {
|
||||
self.saved_autosuggestion =
|
||||
Some(std::mem::take(&mut self.autosuggestion))
|
||||
}
|
||||
Remove => self.autosuggestion.clear(),
|
||||
RemoveAndSave => {
|
||||
self.saved_autosuggestion = Some(std::mem::take(&mut self.autosuggestion))
|
||||
}
|
||||
Restore => {
|
||||
self.autosuggestion = saved_autosuggestion.unwrap();
|
||||
|
@ -1669,6 +1667,7 @@ impl<'a> Reader<'a> {
|
|||
enum AutosuggestionUpdate {
|
||||
Preserve,
|
||||
Remove,
|
||||
RemoveAndSave,
|
||||
Restore,
|
||||
}
|
||||
|
||||
|
@ -1807,6 +1806,13 @@ impl ReaderData {
|
|||
let preserves_autosuggestion = self.try_apply_edit_to_autosuggestion(&edit);
|
||||
if preserves_autosuggestion {
|
||||
autosuggestion_update = AutosuggestionUpdate::Preserve
|
||||
} else if !self.autosuggestion.is_empty()
|
||||
&& edit.range.start == self.autosuggestion.search_string_range.end
|
||||
&& edit.range.is_empty()
|
||||
&& !edit.replacement.is_empty()
|
||||
{
|
||||
// When inserting at the autosuggestion something that doesn't match, save it.
|
||||
autosuggestion_update = AutosuggestionUpdate::RemoveAndSave;
|
||||
} else if self
|
||||
.saved_autosuggestion
|
||||
.as_ref()
|
||||
|
|
|
@ -31,8 +31,17 @@ tmux-sleep
|
|||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 2> : ./COMPL
|
||||
|
||||
isolated-tmux send-keys C-u 'ech {' Left Left
|
||||
tmux-sleep
|
||||
isolated-tmux send-keys o C-e C-h 'still alive' Enter
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt {{\d+}}> echo still alive
|
||||
# CHECK: still alive
|
||||
# CHECK: prompt {{\d+}}>
|
||||
|
||||
isolated-tmux send-keys C-u 'echo (echo)' Enter
|
||||
isolated-tmux send-keys C-l 'echo ('
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 3> echo (echo)
|
||||
# CHECK: prompt {{\d+}}> echo (echo)
|
||||
|
|
Loading…
Reference in New Issue
Block a user