Skip to content

Commit a9ddd51

Browse files
arkus7ogoffart
authored andcommitted
Fix macOS move text shortcuts on wasm
- Replaced the previous macOS-specific check with a more flexible platform detection using `cfg_if` to identify Apple devices across different environments (macOS, iOS, iPadOS, and WebAssembly). - Introduced a boolean variable `is_apple` to streamline the logic for determining modifier keys based on the platform. - Ensured that the shortcut behavior remains consistent for Apple devices by adjusting the modifier key checks accordingly.
1 parent 0bda0a6 commit a9ddd51

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

internal/core/input.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,24 @@ impl KeyEvent {
354354
pub fn text_shortcut(&self) -> Option<TextShortcut> {
355355
let keycode = self.text.chars().next()?;
356356

357-
let move_mod = if cfg!(target_os = "macos") {
357+
cfg_if::cfg_if!(
358+
if #[cfg(target_vendor = "apple")] {
359+
let is_apple = true;
360+
} else if #[cfg(target_family = "wasm")] {
361+
let is_apple = web_sys::window()
362+
.and_then(|window| window.navigator().platform().ok())
363+
.is_some_and(|platform| {
364+
let platform = platform.to_ascii_lowercase();
365+
platform.contains("mac")
366+
|| platform.contains("iphone")
367+
|| platform.contains("ipad")
368+
});
369+
} else {
370+
let is_apple = false;
371+
}
372+
);
373+
374+
let move_mod = if is_apple {
358375
self.modifiers.alt && !self.modifiers.control && !self.modifiers.meta
359376
} else {
360377
self.modifiers.control && !self.modifiers.alt && !self.modifiers.meta
@@ -399,8 +416,7 @@ impl KeyEvent {
399416
}
400417
}
401418

402-
#[cfg(target_os = "macos")]
403-
{
419+
if is_apple {
404420
if self.modifiers.control {
405421
match keycode {
406422
key_codes::LeftArrow => {

0 commit comments

Comments
 (0)