summaryrefslogtreecommitdiffstats
path: root/native/src/widget
diff options
context:
space:
mode:
authorLibravatar FabianLars <fabianlars@fabianlars.de>2020-02-25 17:03:52 +0100
committerLibravatar FabianLars <fabianlars@fabianlars.de>2020-02-25 17:03:52 +0100
commit0d8d236be65abf98a09a13b2e22b677f3d95f195 (patch)
tree0c50325a2b439f7679293a14d9e2f5ccb3083ebf /native/src/widget
parentc47e30e960a403631b6dff7a522a775050d59f87 (diff)
downloadiced-0d8d236be65abf98a09a13b2e22b677f3d95f195.tar.gz
iced-0d8d236be65abf98a09a13b2e22b677f3d95f195.tar.bz2
iced-0d8d236be65abf98a09a13b2e22b677f3d95f195.zip
More selection actions: (Ctrl +) Shift + Left/Right, Shift + Home/End
Diffstat (limited to 'native/src/widget')
-rw-r--r--native/src/widget/text_input.rs44
-rw-r--r--native/src/widget/text_input/cursor.rs6
2 files changed, 45 insertions, 5 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index cadef11d..b39c2ee8 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -374,7 +374,13 @@ where
if platform::is_jump_modifier_pressed(modifiers)
&& !self.is_secure
{
- self.state.cursor.move_left_by_words(&self.value);
+ if modifiers.shift {
+ self.state.cursor.select_left_by_words(&self.value);
+ } else {
+ self.state.cursor.move_left_by_words(&self.value);
+ }
+ } else if modifiers.shift {
+ self.state.cursor.select_left()
} else {
self.state.cursor.move_left();
}
@@ -383,16 +389,37 @@ where
if platform::is_jump_modifier_pressed(modifiers)
&& !self.is_secure
{
- self.state.cursor.move_right_by_words(&self.value);
+ if modifiers.shift {
+ self.state
+ .cursor
+ .select_right_by_words(&self.value);
+ } else {
+ self.state.cursor.move_right_by_words(&self.value);
+ }
+ } else if modifiers.shift {
+ self.state.cursor.select_right(&self.value)
} else {
self.state.cursor.move_right(&self.value);
}
}
keyboard::KeyCode::Home => {
- self.state.cursor.move_to(0);
+ if modifiers.shift {
+ self.state
+ .cursor
+ .select_range(self.state.cursor.start(), 0);
+ } else {
+ self.state.cursor.move_to(0);
+ }
}
keyboard::KeyCode::End => {
- self.state.cursor.move_to(self.value.len());
+ if modifiers.shift {
+ self.state.cursor.select_range(
+ self.state.cursor.start(),
+ self.value.len(),
+ );
+ } else {
+ self.state.cursor.move_to(self.value.len());
+ }
}
keyboard::KeyCode::V => {
if platform::is_copy_paste_modifier_pressed(modifiers) {
@@ -438,6 +465,15 @@ where
self.state.is_pasting = None;
}
}
+ // I think this doesn't work with the current version of the clipboard lib
+ /*keyboard::KeyCode::C => {
+ if platform::is_copy_paste_modifier_pressed(modifiers) {
+ match self.state.cursor.selection_position() {
+ None => (),
+ Some((left, right)) => ()
+ }
+ }
+ }*/
keyboard::KeyCode::A => {
if platform::is_copy_paste_modifier_pressed(modifiers) {
self.state.cursor.select_all(&self.value);
diff --git a/native/src/widget/text_input/cursor.rs b/native/src/widget/text_input/cursor.rs
index bbf5448b..307040eb 100644
--- a/native/src/widget/text_input/cursor.rs
+++ b/native/src/widget/text_input/cursor.rs
@@ -58,7 +58,11 @@ impl Cursor {
/* expand/shrink selection */
// TODO: (whole section): Return State::Cursor if start == end after operation
pub fn select_range(&mut self, start: usize, end: usize) {
- self.state = State::Selection { start, end };
+ if start != end {
+ self.state = State::Selection { start, end };
+ } else {
+ self.state = State::Index(start);
+ }
}
pub fn select_left(&mut self) {