summaryrefslogtreecommitdiffstats
path: root/widget/src/text_input.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-05-31 16:32:12 +0200
committerLibravatar GitHub <noreply@github.com>2024-05-31 16:32:12 +0200
commit06ff17fcf87495663a295d1548df1c2ac03dafbd (patch)
tree5dbfe97e50662cdaf396427d7793c4f03fc159c6 /widget/src/text_input.rs
parent12f4b875cfb0eeb0bac5416921c6cec40edd420c (diff)
parent3312dc808012e2c049fb2f178d51bfe0b4e30399 (diff)
downloadiced-06ff17fcf87495663a295d1548df1c2ac03dafbd.tar.gz
iced-06ff17fcf87495663a295d1548df1c2ac03dafbd.tar.bz2
iced-06ff17fcf87495663a295d1548df1c2ac03dafbd.zip
Merge pull request #2315 from Brady-Simon/macos-command-input-behavior
Add Command + ArrowLeft/Right input behavior for macOS
Diffstat (limited to '')
-rw-r--r--widget/src/text_input.rs88
1 files changed, 48 insertions, 40 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index e9f07838..941e9bde 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -826,7 +826,7 @@ where
}
}
keyboard::Key::Named(key::Named::Backspace) => {
- if platform::is_jump_modifier_pressed(modifiers)
+ if modifiers.jump()
&& state.cursor.selection(&self.value).is_none()
{
if self.is_secure {
@@ -850,7 +850,7 @@ where
update_cache(state, &self.value);
}
keyboard::Key::Named(key::Named::Delete) => {
- if platform::is_jump_modifier_pressed(modifiers)
+ if modifiers.jump()
&& state.cursor.selection(&self.value).is_none()
{
if self.is_secure {
@@ -876,10 +876,52 @@ 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 modifiers.macos_command() =>
+ {
+ 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 modifiers.macos_command() =>
+ {
+ 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
- {
+ if modifiers.jump() && !self.is_secure {
if modifiers.shift() {
state
.cursor
@@ -896,9 +938,7 @@ where
}
}
keyboard::Key::Named(key::Named::ArrowRight) => {
- if platform::is_jump_modifier_pressed(modifiers)
- && !self.is_secure
- {
+ if modifiers.jump() && !self.is_secure {
if modifiers.shift() {
state
.cursor
@@ -914,26 +954,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;
@@ -1281,18 +1301,6 @@ impl<P: text::Paragraph> operation::TextInput for State<P> {
}
}
-mod platform {
- use crate::core::keyboard;
-
- pub fn is_jump_modifier_pressed(modifiers: keyboard::Modifiers) -> bool {
- if cfg!(target_os = "macos") {
- modifiers.alt()
- } else {
- modifiers.control()
- }
- }
-}
-
fn offset<P: text::Paragraph>(
text_bounds: Rectangle,
value: &Value,