mirror of
https://github.com/nushell/nushell.git
synced 2025-01-23 14:50:09 +01:00
nu-explore: Fix repeated char issue in cmdline (#9139)
Must be fixed; (though I'd test it) Thanks for the reference [fdncred](https://github.com/fdncred). close #9128 --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
parent
7a945848de
commit
a5d02a0737
@ -3,7 +3,7 @@ use std::{
|
|||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossterm::event::{poll, read, Event, KeyEvent};
|
use crossterm::event::{poll, read, Event, KeyEvent, KeyEventKind};
|
||||||
|
|
||||||
pub struct UIEvents {
|
pub struct UIEvents {
|
||||||
tick_rate: Duration,
|
tick_rate: Duration,
|
||||||
@ -37,14 +37,20 @@ impl UIEvents {
|
|||||||
match poll(self.tick_rate) {
|
match poll(self.tick_rate) {
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
if let Event::Key(event) = read()? {
|
if let Event::Key(event) = read()? {
|
||||||
Ok(Some(event))
|
// We are only interested in Pressed events;
|
||||||
} else {
|
// It's crucial because there are cases where terminal MIGHT produce false events;
|
||||||
|
// 2 events 1 for release 1 for press.
|
||||||
|
// Want to react only on 1 of them so we do.
|
||||||
|
if event.kind == KeyEventKind::Press {
|
||||||
|
return Ok(Some(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let time_spent = now.elapsed();
|
let time_spent = now.elapsed();
|
||||||
let rest = self.tick_rate - time_spent;
|
let rest = self.tick_rate - time_spent;
|
||||||
|
|
||||||
Self { tick_rate: rest }.next()
|
Self { tick_rate: rest }.next()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(false) => Ok(None),
|
Ok(false) => Ok(None),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
@ -53,7 +59,7 @@ impl UIEvents {
|
|||||||
pub fn try_next(&self) -> Result<Option<KeyEvent>> {
|
pub fn try_next(&self) -> Result<Option<KeyEvent>> {
|
||||||
match poll(Duration::default()) {
|
match poll(Duration::default()) {
|
||||||
Ok(true) => match read()? {
|
Ok(true) => match read()? {
|
||||||
Event::Key(event) => Ok(Some(event)),
|
Event::Key(event) if event.kind == KeyEventKind::Press => Ok(Some(event)),
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
},
|
},
|
||||||
Ok(false) => Ok(None),
|
Ok(false) => Ok(None),
|
||||||
|
Loading…
Reference in New Issue
Block a user