summaryrefslogtreecommitdiffstats
path: root/widget/src/text_input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/text_input.rs')
-rw-r--r--widget/src/text_input.rs81
1 files changed, 61 insertions, 20 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index e9f07838..2c951c12 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -876,6 +876,54 @@ where
update_cache(state, &self.value);
}
+ keyboard::Key::Named(key::Named::Home) => {
+ if modifiers.shift() {
+ state.cursor.select_range(
+ state.cursor.start(&self.value),
+ 0,
+ );
+ } else {
+ state.cursor.move_to(0);
+ }
+ }
+ keyboard::Key::Named(key::Named::End) => {
+ if modifiers.shift() {
+ state.cursor.select_range(
+ state.cursor.start(&self.value),
+ self.value.len(),
+ );
+ } else {
+ state.cursor.move_to(self.value.len());
+ }
+ }
+ keyboard::Key::Named(key::Named::ArrowLeft)
+ if platform::is_macos_command_pressed(
+ modifiers,
+ ) =>
+ {
+ if modifiers.shift() {
+ state.cursor.select_range(
+ state.cursor.start(&self.value),
+ 0,
+ );
+ } else {
+ state.cursor.move_to(0);
+ }
+ }
+ keyboard::Key::Named(key::Named::ArrowRight)
+ if platform::is_macos_command_pressed(
+ modifiers,
+ ) =>
+ {
+ if modifiers.shift() {
+ state.cursor.select_range(
+ state.cursor.start(&self.value),
+ self.value.len(),
+ );
+ } else {
+ state.cursor.move_to(self.value.len());
+ }
+ }
keyboard::Key::Named(key::Named::ArrowLeft) => {
if platform::is_jump_modifier_pressed(modifiers)
&& !self.is_secure
@@ -914,26 +962,6 @@ where
state.cursor.move_right(&self.value);
}
}
- keyboard::Key::Named(key::Named::Home) => {
- if modifiers.shift() {
- state.cursor.select_range(
- state.cursor.start(&self.value),
- 0,
- );
- } else {
- state.cursor.move_to(0);
- }
- }
- keyboard::Key::Named(key::Named::End) => {
- if modifiers.shift() {
- state.cursor.select_range(
- state.cursor.start(&self.value),
- self.value.len(),
- );
- } else {
- state.cursor.move_to(self.value.len());
- }
- }
keyboard::Key::Named(key::Named::Escape) => {
state.is_focused = None;
state.is_dragging = false;
@@ -1291,6 +1319,19 @@ mod platform {
modifiers.control()
}
}
+
+ /// Whether the command key is pressed on a macOS device.
+ ///
+ /// This is relevant for actions like ⌘ + ArrowLeft to move to the beginning of the
+ /// line where the equivalent behavior for `modifiers.command()` is instead a jump on
+ /// other platforms.
+ pub fn is_macos_command_pressed(modifiers: keyboard::Modifiers) -> bool {
+ if cfg!(target_os = "macos") {
+ modifiers.logo()
+ } else {
+ false
+ }
+ }
}
fn offset<P: text::Paragraph>(