diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2025-10-21 18:09:06 +0200 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2025-10-21 18:09:06 +0200 |
| commit | 8700f85ff826dd8fc428e2acd3c7c5ae18a4945d (patch) | |
| tree | 0456dccecaa4641ac9d0037592e584c5fdc7f3e2 /src/selection.rs | |
| parent | refactor: clean up text imports, cursor position code (diff) | |
| download | iced_selection-8700f85ff826dd8fc428e2acd3c7c5ae18a4945d.tar.gz | |
feat: implement triple-click + drag by-line selection
Diffstat (limited to '')
| -rw-r--r-- | src/selection.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/selection.rs b/src/selection.rs index b98a113..2c1e43d 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -208,6 +208,31 @@ impl Selection { self.select_range(start, end); } + /// Updates the current selection by setting a new end point, either to the end of a following + /// line, or the beginning of a previous one. + pub fn change_selection_by_line( + &mut self, + new_line: usize, + paragraph: &Paragraph, + ) { + if new_line < self.start.line { + self.direction = Direction::Left; + } else if new_line > self.end.line { + self.direction = Direction::Right; + } + + let (start, end) = if self.direction == Direction::Right { + let value = Value::new(paragraph.buffer().lines[new_line].text()); + + (self.start, SelectionEnd::new(new_line, value.len())) + } else { + (SelectionEnd::new(new_line, 0), self.end) + }; + + self.moving_line_index = None; + self.select_range(start, end); + } + /// Selects the word around the given grapheme position. pub fn select_word( &mut self, |
