diff options
author | Pyfisch <pyfisch@gmail.com> | 2018-10-17 22:39:37 +0200 |
---|---|---|
committer | Pyfisch <pyfisch@gmail.com> | 2018-10-17 22:39:37 +0200 |
commit | c2ea135c490f9dfcd4a30fffcb52b9bf9b2d7aae (patch) | |
tree | 116a0ade8ed50adca317a7715223b13ecc5434bc /components/script/textinput.rs | |
parent | 9a0404ac5fc1c463aa68bb0c68d709a61157c2bf (diff) | |
download | servo-c2ea135c490f9dfcd4a30fffcb52b9bf9b2d7aae.tar.gz servo-c2ea135c490f9dfcd4a30fffcb52b9bf9b2d7aae.zip |
Correctly determine text selection direction
Add some debug! output.
Closes #21891
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index dfa469c1a08..7b7a7beb493 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -293,6 +293,12 @@ impl<T: ClipboardProvider> TextInput<T> { // Check that the selection is valid. fn assert_ok_selection(&self) { + debug!( + "edit_point: {:?}, selection_origin: {:?}, direction: {:?}", + self.edit_point, + self.selection_origin, + self.selection_direction + ); if let Some(begin) = self.selection_origin { debug_assert!(begin.line < self.lines.len()); debug_assert!(begin.index <= self.lines[begin.line].len()); @@ -506,11 +512,6 @@ impl<T: ClipboardProvider> TextInput<T> { if self.selection_origin.is_none() { self.selection_origin = Some(self.edit_point); } - - self.selection_direction = match adjust { - Direction::Backward => SelectionDirection::Backward, - Direction::Forward => SelectionDirection::Forward, - }; } else { if self.has_selection() { self.edit_point = match adjust { @@ -524,6 +525,23 @@ impl<T: ClipboardProvider> TextInput<T> { false } + /// Update the field selection_direction. + /// + /// When the edit_point (or focus) is before the selection_origin (or anchor) + /// you have a backward selection. Otherwise you have a forward selection. + fn update_selection_direction(&mut self) { + debug!( + "edit_point: {:?}, selection_origin: {:?}", + self.edit_point, + self.selection_origin + ); + self.selection_direction = if Some(self.edit_point) < self.selection_origin { + SelectionDirection::Backward + } else { + SelectionDirection::Forward + } + } + fn perform_horizontal_adjustment(&mut self, adjust: isize, select: Selection) { if adjust < 0 { let remaining = self.edit_point.index; @@ -548,6 +566,7 @@ impl<T: ClipboardProvider> TextInput<T> { ); } } + self.update_selection_direction(); self.assert_ok_selection(); } |