Skip to content

Commit

Permalink
fix: avoid duplicate key input on windows (#203).
Browse files Browse the repository at this point in the history
On Windows, key-states like press/release/repeat are made available
separately, which means we should avoid responding to key-releases
as it would incorrectly double the actual user inputs.
  • Loading branch information
Byron committed Dec 26, 2023
1 parent 90b65d5 commit b5b8aa2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::interactive::{
SortMode,
};
use anyhow::Result;
use crosstermion::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crosstermion::crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use crosstermion::input::{input_channel, Event};
use dua::{
traverse::{EntryData, Traversal},
Expand Down Expand Up @@ -115,7 +115,7 @@ impl AppState {

for event in events {
let key = match event {
Event::Key(key) => key,
Event::Key(key) if key.kind != KeyEventKind::Release => key,
Event::Resize(_, _) => refresh_key(),
_ => continue,
};
Expand Down
4 changes: 4 additions & 0 deletions src/interactive/widgets/glob.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, Context, Result};
use bstr::BString;
use crosstermion::crossterm::event::KeyEventKind;
use crosstermion::input::Key;
use dua::traverse::{Tree, TreeIndex};
use petgraph::Direction;
Expand Down Expand Up @@ -37,6 +38,9 @@ pub struct GlobPane {
impl GlobPane {
pub fn process_events(&mut self, key: Key) {
use crosstermion::crossterm::event::KeyCode::*;
if key.kind == KeyEventKind::Release {
return;
}
match key.code {
Char(to_insert) => {
self.enter_char(to_insert);
Expand Down
5 changes: 4 additions & 1 deletion src/interactive/widgets/help.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::interactive::CursorDirection;
pub use crosstermion::crossterm::event::KeyCode::*;
use crosstermion::crossterm::event::KeyModifiers;
use crosstermion::crossterm::event::{KeyEventKind, KeyModifiers};
use crosstermion::input::Key;
use std::{borrow::Borrow, cell::RefCell};
use tui::{
Expand Down Expand Up @@ -36,6 +36,9 @@ fn margin(r: Rect, margin: u16) -> Rect {

impl HelpPane {
pub fn process_events(&mut self, key: Key) {
if key.kind == KeyEventKind::Release {
return;
}
match key.code {
Char('H') => self.scroll_help(CursorDirection::ToTop),
Char('G') => self.scroll_help(CursorDirection::ToBottom),
Expand Down
5 changes: 4 additions & 1 deletion src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::interactive::{
app::tree_view::TreeView, fit_string_graphemes_with_ellipsis, widgets::entry_color,
CursorDirection,
};
use crosstermion::crossterm::event::KeyModifiers;
use crosstermion::crossterm::event::{KeyEventKind, KeyModifiers};
use crosstermion::input::Key;
use dua::{traverse::TreeIndex, ByteFormat};
use itertools::Itertools;
Expand Down Expand Up @@ -117,6 +117,9 @@ impl MarkPane {
pub fn process_events(mut self, key: Key) -> Option<(Self, Option<MarkMode>)> {
use crosstermion::crossterm::event::KeyCode::*;
let action = None;
if key.kind == KeyEventKind::Release {
return Some((self, action));
}
match key.code {
Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
return Some(self.prepare_deletion(MarkMode::Delete))
Expand Down

0 comments on commit b5b8aa2

Please sign in to comment.