Fix regression in forward-single-char

This crashes if the autosuggesion is exhausted.  C++ used

    autosuggestion.text.substr(pos, 1)

which throws if pos is OOB but not if pos + 1 is.
This commit is contained in:
Johannes Altmanninger
2024-02-14 10:50:56 +01:00
parent 2137467f0b
commit 4cb766324b
2 changed files with 18 additions and 6 deletions

View File

@@ -3944,12 +3944,14 @@ fn accept_autosuggestion(
self.autosuggestion.text.clone(),
);
} else if single {
self.replace_substring(
EditableLineTag::Commandline,
self.command_line.len()..self.command_line.len(),
self.autosuggestion.text[self.command_line.len()..self.command_line.len() + 1]
.to_owned(),
);
let pos = self.command_line.len();
if pos + 1 < self.autosuggestion.text.len() {
self.replace_substring(
EditableLineTag::Commandline,
pos..pos,
self.autosuggestion.text[pos..pos + 1].to_owned(),
);
}
} else {
// Accept characters according to the specified style.
let mut state = MoveWordStateMachine::new(style);

View File

@@ -84,3 +84,13 @@ isolated-tmux send-keys 'echo sug' C-w C-z
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 6> echo suggest this
isolated-tmux send-keys C-u 'bind \cs forward-single-char' Enter C-l
isolated-tmux send-keys 'echo suggest thi'
tmux-sleep
isolated-tmux send-keys C-s
tmux-sleep
isolated-tmux send-keys C-s
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 7> echo suggest this