From c79e17a06fb0dbc1b058a464d0549aba03bf70d2 Mon Sep 17 00:00:00 2001 From: RainBus Date: Thu, 17 Oct 2024 23:13:41 +0800 Subject: [PATCH] Input backspace --- src/view/component/input.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/view/component/input.rs b/src/view/component/input.rs index 6b7f813..70f1bd9 100644 --- a/src/view/component/input.rs +++ b/src/view/component/input.rs @@ -48,9 +48,20 @@ impl Component for InputComponent { self.cursor += 1; } (Backspace, &KeyModifiers::NONE) => { - if self.value.pop().is_some() { + if self.cursor > 0 { + self.value.remove(self.cursor - 1); self.cursor -= 1; - }; + } + } + (Left, &KeyModifiers::NONE) => { + if self.cursor > 0 { + self.cursor -= 1; + } + } + (Right, &KeyModifiers::NONE) => { + if self.cursor < self.value.len() { + self.cursor += 1; + } } _ => {} }