add isComposing support of KeyboardEvent
This commit is contained in:
1 parent
20241d8f20
commit
d3ded8c677
4 files changed
+26
No files matched your search
@@ -33,6 +33,7 @@ impl std::fmt::Debug for KeyboardData {
|
|||||||
.field("modifiers", &self.modifiers())
|
.field("modifiers", &self.modifiers())
|
||||||
.field("location", &self.location())
|
.field("location", &self.location())
|
||||||
.field("is_auto_repeating", &self.is_auto_repeating())
|
.field("is_auto_repeating", &self.is_auto_repeating())
|
||||||
|
.field("is_composing", &self.is_composing())
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +45,7 @@ impl PartialEq for KeyboardData {
|
|||||||
&& self.modifiers() == other.modifiers()
|
&& self.modifiers() == other.modifiers()
|
||||||
&& self.location() == other.location()
|
&& self.location() == other.location()
|
||||||
&& self.is_auto_repeating() == other.is_auto_repeating()
|
&& self.is_auto_repeating() == other.is_auto_repeating()
|
||||||
|
&& self.is_composing() == other.is_composing()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +77,11 @@ impl KeyboardData {
|
|||||||
self.inner.is_auto_repeating()
|
self.inner.is_auto_repeating()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Indicates whether the key is fired within a composition session.
|
||||||
|
pub fn is_composing(&self) -> bool {
|
||||||
|
self.inner.is_composing()
|
||||||
|
}
|
||||||
|
|
||||||
/// Downcast this KeyboardData to a concrete type.
|
/// Downcast this KeyboardData to a concrete type.
|
||||||
pub fn downcast<T: 'static>(&self) -> Option<&T> {
|
pub fn downcast<T: 'static>(&self) -> Option<&T> {
|
||||||
self.inner.as_any().downcast_ref::<T>()
|
self.inner.as_any().downcast_ref::<T>()
|
||||||
@@ -92,6 +99,7 @@ impl ModifiersInteraction for KeyboardData {
|
|||||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
||||||
pub struct SerializedKeyboardData {
|
pub struct SerializedKeyboardData {
|
||||||
char_code: u32,
|
char_code: u32,
|
||||||
|
is_composing: bool,
|
||||||
key: String,
|
key: String,
|
||||||
key_code: KeyCode,
|
key_code: KeyCode,
|
||||||
#[serde(deserialize_with = "resilient_deserialize_code")]
|
#[serde(deserialize_with = "resilient_deserialize_code")]
|
||||||
@@ -114,9 +122,11 @@ impl SerializedKeyboardData {
|
|||||||
location: Location,
|
location: Location,
|
||||||
is_auto_repeating: bool,
|
is_auto_repeating: bool,
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
|
is_composing: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
char_code: key.legacy_charcode(),
|
char_code: key.legacy_charcode(),
|
||||||
|
is_composing,
|
||||||
key: key.to_string(),
|
key: key.to_string(),
|
||||||
key_code: KeyCode::from_raw_code(
|
key_code: KeyCode::from_raw_code(
|
||||||
std::convert::TryInto::try_into(key.legacy_keycode())
|
std::convert::TryInto::try_into(key.legacy_keycode())
|
||||||
@@ -144,6 +154,7 @@ impl From<&KeyboardData> for SerializedKeyboardData {
|
|||||||
data.location(),
|
data.location(),
|
||||||
data.is_auto_repeating(),
|
data.is_auto_repeating(),
|
||||||
data.modifiers(),
|
data.modifiers(),
|
||||||
|
data.is_composing(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,6 +177,10 @@ impl HasKeyboardData for SerializedKeyboardData {
|
|||||||
self.repeat
|
self.repeat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_composing(&self) -> bool {
|
||||||
|
self.is_composing
|
||||||
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -236,6 +251,9 @@ pub trait HasKeyboardData: ModifiersInteraction + std::any::Any {
|
|||||||
/// `true` iff the key is being held down such that it is automatically repeating.
|
/// `true` iff the key is being held down such that it is automatically repeating.
|
||||||
fn is_auto_repeating(&self) -> bool;
|
fn is_auto_repeating(&self) -> bool;
|
||||||
|
|
||||||
|
/// Indicates whether the key is fired within a composition session.
|
||||||
|
fn is_composing(&self) -> bool;
|
||||||
|
|
||||||
/// return self as Any
|
/// return self as Any
|
||||||
fn as_any(&self) -> &dyn std::any::Any;
|
fn as_any(&self) -> &dyn std::any::Any;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ impl HasKeyboardData for KeyboardEvent {
|
|||||||
self.repeat()
|
self.repeat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_composing(&self) -> bool {
|
||||||
|
self.is_composing()
|
||||||
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,6 +351,7 @@ async function serialize_event(event) {
|
|||||||
case "keyup": {
|
case "keyup": {
|
||||||
let {
|
let {
|
||||||
charCode,
|
charCode,
|
||||||
|
isComposing,
|
||||||
key,
|
key,
|
||||||
altKey,
|
altKey,
|
||||||
ctrlKey,
|
ctrlKey,
|
||||||
@@ -364,6 +365,7 @@ async function serialize_event(event) {
|
|||||||
} = event;
|
} = event;
|
||||||
return {
|
return {
|
||||||
char_code: charCode,
|
char_code: charCode,
|
||||||
|
is_composing: isComposing,
|
||||||
key: key,
|
key: key,
|
||||||
alt_key: altKey,
|
alt_key: altKey,
|
||||||
ctrl_key: ctrlKey,
|
ctrl_key: ctrlKey,
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ impl InnerInputState {
|
|||||||
k.location(),
|
k.location(),
|
||||||
is_repeating,
|
is_repeating,
|
||||||
k.modifiers(),
|
k.modifiers(),
|
||||||
|
k.is_composing(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,6 +780,7 @@ fn translate_key_event(event: crossterm::event::KeyEvent) -> Option<EventData> {
|
|||||||
Location::Standard,
|
Location::Standard,
|
||||||
false,
|
false,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
false,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user