diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index fe239f0c..75f7a924 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -55,7 +55,9 @@ actions!( SelectAll, Home, End, - SelectToHome, + SelectToStartOfLine, + SelectToEndOfLine, + SelectToStart, SelectToEnd, ShowCharacterPalette, Copy, @@ -65,6 +67,8 @@ actions!( Redo, MoveToStartOfLine, MoveToEndOfLine, + MoveToStart, + MoveToEnd, TextChanged, ] ); @@ -98,16 +102,16 @@ pub fn init(cx: &mut AppContext) { KeyBinding::new("shift-down", SelectDown, Some(CONTEXT)), KeyBinding::new("home", Home, Some(CONTEXT)), KeyBinding::new("end", End, Some(CONTEXT)), - KeyBinding::new("shift-home", SelectToHome, Some(CONTEXT)), - KeyBinding::new("shift-end", SelectToEnd, Some(CONTEXT)), + KeyBinding::new("shift-home", SelectToStartOfLine, Some(CONTEXT)), + KeyBinding::new("shift-end", SelectToEndOfLine, Some(CONTEXT)), #[cfg(target_os = "macos")] - KeyBinding::new("ctrl-shift-a", SelectToHome, Some(CONTEXT)), + KeyBinding::new("ctrl-shift-a", SelectToStartOfLine, Some(CONTEXT)), #[cfg(target_os = "macos")] - KeyBinding::new("ctrl-shift-e", SelectToEnd, Some(CONTEXT)), + KeyBinding::new("ctrl-shift-e", SelectToEndOfLine, Some(CONTEXT)), #[cfg(target_os = "macos")] - KeyBinding::new("shift-cmd-left", SelectToHome, Some(CONTEXT)), + KeyBinding::new("shift-cmd-left", SelectToStartOfLine, Some(CONTEXT)), #[cfg(target_os = "macos")] - KeyBinding::new("shift-cmd-right", SelectToEnd, Some(CONTEXT)), + KeyBinding::new("shift-cmd-right", SelectToEndOfLine, Some(CONTEXT)), #[cfg(target_os = "macos")] KeyBinding::new("ctrl-cmd-space", ShowCharacterPalette, Some(CONTEXT)), #[cfg(target_os = "macos")] @@ -138,6 +142,14 @@ pub fn init(cx: &mut AppContext) { KeyBinding::new("cmd-z", Undo, Some(CONTEXT)), #[cfg(target_os = "macos")] KeyBinding::new("cmd-shift-z", Redo, Some(CONTEXT)), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-up", MoveToStart, Some(CONTEXT)), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-down", MoveToEnd, Some(CONTEXT)), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-shift-up", SelectToStart, Some(CONTEXT)), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-shift-down", SelectToEnd, Some(CONTEXT)), #[cfg(not(target_os = "macos"))] KeyBinding::new("ctrl-z", Undo, Some(CONTEXT)), #[cfg(not(target_os = "macos"))] @@ -615,12 +627,30 @@ impl TextInput { self.move_to(offset, cx); } - fn select_to_home(&mut self, _: &SelectToHome, cx: &mut ViewContext) { + fn move_to_start(&mut self, _: &MoveToStart, cx: &mut ViewContext) { + self.move_to(0, cx); + } + + fn move_to_end(&mut self, _: &MoveToEnd, cx: &mut ViewContext) { + let end = self.text.len(); + self.move_to(end, cx); + } + + fn select_to_start(&mut self, _: &SelectToStart, cx: &mut ViewContext) { + self.select_to(0, cx); + } + + fn select_to_end(&mut self, _: &SelectToEnd, cx: &mut ViewContext) { + let end = self.text.len(); + self.select_to(end, cx); + } + + fn select_to_start_of_line(&mut self, _: &SelectToStartOfLine, cx: &mut ViewContext) { let offset = self.start_of_line(cx); self.select_to(offset, cx); } - fn select_to_end(&mut self, _: &SelectToEnd, cx: &mut ViewContext) { + fn select_to_end_of_line(&mut self, _: &SelectToEndOfLine, cx: &mut ViewContext) { let offset = self.end_of_line(cx); self.select_to(offset, cx); } @@ -1323,10 +1353,14 @@ impl Render for TextInput { .on_action(cx.listener(Self::select_down)) }) .on_action(cx.listener(Self::select_all)) - .on_action(cx.listener(Self::select_to_home)) - .on_action(cx.listener(Self::select_to_end)) + .on_action(cx.listener(Self::select_to_start_of_line)) + .on_action(cx.listener(Self::select_to_end_of_line)) .on_action(cx.listener(Self::home)) .on_action(cx.listener(Self::end)) + .on_action(cx.listener(Self::move_to_start)) + .on_action(cx.listener(Self::move_to_end)) + .on_action(cx.listener(Self::select_to_start)) + .on_action(cx.listener(Self::select_to_end)) .on_action(cx.listener(Self::show_character_palette)) .on_action(cx.listener(Self::copy)) .on_action(cx.listener(Self::paste))