diff options
| author | 2020-02-23 00:26:15 +0100 | |
|---|---|---|
| committer | 2020-02-23 00:26:15 +0100 | |
| commit | f72b1f8c45b55c48210161568ee8a916706ec00a (patch) | |
| tree | 931f8e88e5932ab15f2ac6fec86cba688e34f063 /native | |
| parent | 33ca29f3954960800da2f5e35068b31fe6c1c586 (diff) | |
| download | iced-f72b1f8c45b55c48210161568ee8a916706ec00a.tar.gz iced-f72b1f8c45b55c48210161568ee8a916706ec00a.tar.bz2 iced-f72b1f8c45b55c48210161568ee8a916706ec00a.zip | |
double click for word selection
3 clicks to select all
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/text_input.rs | 40 | 
1 files changed, 39 insertions, 1 deletions
| diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 4aed2767..96f9d96f 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -209,7 +209,34 @@ where                      let text_layout = layout.children().next().unwrap();                      let target = cursor_position.x - text_layout.bounds().x; -                    if target > 0.0 { +                    if cursor_position +                        == self +                            .state +                            .last_position +                            .unwrap_or(Point { x: 0.0, y: 0.0 }) +                        && self.state.click_count < 2 +                    { +                        self.state.click_count += 1; + +                        if self.state.click_count == 1 { +                            let current = +                                self.state.cursor_position(&self.value); + +                            self.state.cursor_position = Cursor::Selection { +                                start: self +                                    .value +                                    .previous_start_of_word(current.left()), +                                end: self +                                    .value +                                    .next_end_of_word(current.right()), +                            } +                        } else if self.state.click_count == 2 { +                            self.state.cursor_position = Cursor::Selection { +                                start: 0, +                                end: self.value.len(), +                            } +                        } +                    } else if target > 0.0 {                          let value = if self.is_secure {                              self.value.secure()                          } else { @@ -236,7 +263,13 @@ where                                  self.value.len(),                                  self.font,                              )); +                        self.state.click_count = 0; +                        self.state.last_position = +                            Option::from(cursor_position);                      } else { +                        self.state.click_count = 0; +                        self.state.last_position = +                            Option::from(cursor_position);                          self.state.cursor_position = Cursor::Index(0);                      }                  } @@ -601,6 +634,9 @@ pub struct State {      is_pressed: bool,      is_pasting: Option<Value>,      cursor_position: Cursor, +    /// Double- / Tripleclick +    click_count: usize, +    last_position: Option<Point>,      // TODO: Add stateful horizontal scrolling offset  } @@ -686,6 +722,8 @@ impl State {              is_pressed: false,              is_pasting: None,              cursor_position: Cursor::Index(usize::MAX), +            click_count: 0, +            last_position: None,          }      } | 
