Fix panic on empty command history when browsing history

memfd
Manos Pitsidianakis 2020-07-25 16:34:53 +03:00
parent 8b90c7fcb6
commit 4aaa784d8f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 6 additions and 0 deletions

View File

@ -1102,6 +1102,9 @@ impl Component for StatusBar {
self.dirty = true; self.dirty = true;
} }
UIEvent::CmdInput(Key::Ctrl('p')) => { UIEvent::CmdInput(Key::Ctrl('p')) => {
if self.cmd_history.is_empty() {
return true;
}
let pos = self.ex_buffer_cmd_history_pos.map(|p| p + 1).unwrap_or(0); let pos = self.ex_buffer_cmd_history_pos.map(|p| p + 1).unwrap_or(0);
let pos = Some(std::cmp::min(pos, self.cmd_history.len().saturating_sub(1))); let pos = Some(std::cmp::min(pos, self.cmd_history.len().saturating_sub(1)));
if pos != self.ex_buffer_cmd_history_pos { if pos != self.ex_buffer_cmd_history_pos {
@ -1121,6 +1124,9 @@ impl Component for StatusBar {
return true; return true;
} }
UIEvent::CmdInput(Key::Ctrl('n')) => { UIEvent::CmdInput(Key::Ctrl('n')) => {
if self.cmd_history.is_empty() {
return true;
}
if Some(0) == self.ex_buffer_cmd_history_pos { if Some(0) == self.ex_buffer_cmd_history_pos {
self.ex_buffer_cmd_history_pos = None; self.ex_buffer_cmd_history_pos = None;
self.ex_buffer.clear(); self.ex_buffer.clear();