From 1d1803f348225dfe3ecb331e69730b3e80299e29 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 27 Jun 2024 22:13:40 +0800 Subject: [PATCH] Fix Input keybinding on Windows. --- crates/ui/src/input.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/ui/src/input.rs b/crates/ui/src/input.rs index ce2f8e4b..7de22120 100644 --- a/crates/ui/src/input.rs +++ b/crates/ui/src/input.rs @@ -40,15 +40,30 @@ pub fn init(cx: &mut AppContext) { KeyBinding::new("right", Right, None), KeyBinding::new("shift-left", SelectLeft, None), KeyBinding::new("shift-right", SelectRight, None), - KeyBinding::new("cmd-a", SelectAll, None), KeyBinding::new("home", Home, None), KeyBinding::new("end", End, None), + #[cfg(target_os = "macos")] KeyBinding::new("ctrl-cmd-space", ShowCharacterPalette, None), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-a", SelectAll, None), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-a", SelectAll, None), + #[cfg(target_os = "macos")] KeyBinding::new("cmd-c", Copy, None), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-c", Copy, None), + #[cfg(target_os = "macos")] KeyBinding::new("cmd-x", Cut, None), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-x", Cut, None), + #[cfg(target_os = "macos")] KeyBinding::new("cmd-v", Paste, None), - KeyBinding::new("ctrl-a", MoveToStartOfLine, None), - KeyBinding::new("ctrl-e", MoveToEndOfLine, None), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-v", Paste, None), + #[cfg(target_os = "macos")] + KeyBinding::new("ctrl-a", Home, None), + #[cfg(target_os = "macos")] + KeyBinding::new("ctrl-e", End, None), ]); } @@ -195,14 +210,6 @@ impl TextInput { } } - fn move_to_start_of_line(&mut self, _: &MoveToStartOfLine, cx: &mut ViewContext) { - self.move_to(0, cx); - } - - fn move_to_end_of_line(&mut self, _: &MoveToEndOfLine, cx: &mut ViewContext) { - self.move_to(self.text.len(), cx); - } - fn move_to(&mut self, offset: usize, cx: &mut ViewContext) { self.selected_range = offset..offset; cx.notify() @@ -579,8 +586,6 @@ impl Render for TextInput { .on_action(cx.listener(Self::copy)) .on_action(cx.listener(Self::paste)) .on_action(cx.listener(Self::cut)) - .on_action(cx.listener(Self::move_to_start_of_line)) - .on_action(cx.listener(Self::move_to_end_of_line)) // Double click to select all .on_double_click(cx.listener(|view, _, cx| { view.select_all(&SelectAll, cx);