From 0ca8573982f90699082c0b91af7798d0e41acbb7 Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 4 Oct 2022 17:25:32 +0900 Subject: [PATCH] fix panic when max history is zero (fix #4) --- src/history.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/history.rs b/src/history.rs index 9c89a16..b27762e 100644 --- a/src/history.rs +++ b/src/history.rs @@ -110,9 +110,13 @@ impl History { } pub fn push(&mut self, edit: Edit) { + if self.max_items == 0 { + return; + } + if self.edits.len() == self.max_items { self.edits.pop_front(); - self.index -= 1; + self.index = self.index.saturating_sub(1); } if self.index < self.edits.len() {