зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-07 16:05:50 +03:00
ignore crossterm's press event only on Windows (#14)
Этот коммит содержится в:
@@ -1,13 +1,13 @@
|
|||||||
use super::{Input, Key};
|
use super::{Input, Key};
|
||||||
use crate::crossterm::event::{
|
#[cfg(target_os = "windows")]
|
||||||
Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseEvent, MouseEventKind,
|
use crate::crossterm::event::KeyEventKind;
|
||||||
};
|
use crate::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||||
|
|
||||||
impl From<Event> for Input {
|
impl From<Event> for Input {
|
||||||
/// Convert [`crossterm::event::Event`] to [`Input`].
|
/// Convert [`crossterm::event::Event`] to [`Input`].
|
||||||
fn from(event: Event) -> Self {
|
fn from(event: Event) -> Self {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(key) if key.kind != KeyEventKind::Release => Self::from(key),
|
Event::Key(key) => Self::from(key),
|
||||||
Event::Mouse(mouse) => Self::from(mouse),
|
Event::Mouse(mouse) => Self::from(mouse),
|
||||||
_ => Self::default(),
|
_ => Self::default(),
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,12 @@ impl From<Event> for Input {
|
|||||||
impl From<KeyEvent> for Input {
|
impl From<KeyEvent> for Input {
|
||||||
/// Convert [`crossterm::event::KeyEvent`] to [`Input`].
|
/// Convert [`crossterm::event::KeyEvent`] to [`Input`].
|
||||||
fn from(key: KeyEvent) -> Self {
|
fn from(key: KeyEvent) -> Self {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
if key.kind == KeyEventKind::Release {
|
||||||
|
// On Windows, handle only button press events (#14)
|
||||||
|
return Self::default();
|
||||||
|
}
|
||||||
|
|
||||||
let ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
|
let ctrl = key.modifiers.contains(KeyModifiers::CONTROL);
|
||||||
let alt = key.modifiers.contains(KeyModifiers::ALT);
|
let alt = key.modifiers.contains(KeyModifiers::ALT);
|
||||||
let key = match key.code {
|
let key = match key.code {
|
||||||
@@ -37,6 +43,7 @@ impl From<KeyEvent> for Input {
|
|||||||
KeyCode::F(x) => Key::F(x),
|
KeyCode::F(x) => Key::F(x),
|
||||||
_ => Key::Null,
|
_ => Key::Null,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self { key, ctrl, alt }
|
Self { key, ctrl, alt }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user