From 3dc472c044b07aa0bf88ab030292245a7e8b3bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=95=E4=B8=8E=E5=B0=86=E5=86=9B=E8=A7=A3=E6=88=98?= =?UTF-8?q?=E8=A2=8D?= <72246322+a1393323447@users.noreply.github.com> Date: Fri, 3 Feb 2023 23:32:17 +0800 Subject: [PATCH] Read input only when key was pressed --- examples/user_input.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/user_input.rs b/examples/user_input.rs index 330d502..911ccf1 100644 --- a/examples/user_input.rs +++ b/examples/user_input.rs @@ -10,7 +10,7 @@ /// * Pressing Enter pushes the current input in the history of previous /// messages use crossterm::{ - event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, + event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind}, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; @@ -93,7 +93,7 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( } _ => {} }, - InputMode::Editing => match key.code { + InputMode::Editing if key.kind == KeyEventKind::Press => match key.code { KeyCode::Enter => { app.messages.push(app.input.drain(..).collect()); } @@ -108,6 +108,7 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( } _ => {} }, + _ => {} } } }