diff options
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, |
