Deduplicate command line update step when accepting autosuggestions

This commit is contained in:
Johannes Altmanninger
2024-12-25 17:09:29 +01:00
parent 8bb6597b9b
commit 1d620356f8

View File

@@ -4551,24 +4551,20 @@ fn accept_autosuggestion(&mut self, amount: AutosuggestionPortion) {
self.clear_pager();
// Accept the autosuggestion.
match amount {
let (range, replacement) = match amount {
AutosuggestionPortion::Count(count) => {
let pos = self.command_line.len();
if count == usize::MAX {
self.data.replace_substring(
EditableLineTag::Commandline,
0..self.command_line.len(),
self.autosuggestion.text.clone(),
);
(0..self.command_line.len(), self.autosuggestion.text.clone())
} else {
let count = count.min(self.autosuggestion.text.len() - pos);
if count != 0 {
self.data.replace_substring(
EditableLineTag::Commandline,
pos..pos,
self.autosuggestion.text[pos..pos + count].to_owned(),
);
if count == 0 {
return;
}
(
pos..pos,
self.autosuggestion.text[pos..pos + count].to_owned(),
)
}
}
AutosuggestionPortion::PerMoveWordStyle(style) => {
@@ -4583,13 +4579,11 @@ fn accept_autosuggestion(&mut self, amount: AutosuggestionPortion) {
want += 1;
}
let have = self.command_line.len();
self.data.replace_substring(
EditableLineTag::Commandline,
have..have,
self.autosuggestion.text[have..want].to_owned(),
);
(have..have, self.autosuggestion.text[have..want].to_owned())
}
}
};
self.data
.replace_substring(EditableLineTag::Commandline, range, replacement);
}
}