diff options
author | Denis Merigoux <denis.merigoux@gmail.com> | 2018-12-14 14:21:50 +0100 |
---|---|---|
committer | Denis Merigoux <denis.merigoux@gmail.com> | 2018-12-22 17:50:24 +0100 |
commit | e1ea8fbd35b7be9d6de20977349f18a080570e43 (patch) | |
tree | 724cbcb140128d8bb40e17106c6ced226d2d998a /components/script/textinput.rs | |
parent | 9ca6768a56cf29ce6563af932b9e8a9150963d39 (diff) | |
download | servo-e1ea8fbd35b7be9d6de20977349f18a080570e43.tar.gz servo-e1ea8fbd35b7be9d6de20977349f18a080570e43.zip |
Fixed bug in textinput::adjust_vertical concerning selection_origin update
This bug was discovered using the F* formal verification framework.
Style changes (match -> if let)
Replace if let Some(_) by .is_some()
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 2f36b08dbd9..54bc7131f48 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -442,12 +442,23 @@ impl<T: ClipboardProvider> TextInput<T> { let target_line: isize = self.edit_point.line as isize + adjust; if target_line < 0 { - self.edit_point.index = 0; self.edit_point.line = 0; + self.edit_point.index = 0; + if self.selection_origin.is_some() && + (self.selection_direction == SelectionDirection::None || + self.selection_direction == SelectionDirection::Forward) + { + self.selection_origin = Some(TextPoint { line: 0, index: 0 }); + } return; } else if target_line as usize >= self.lines.len() { self.edit_point.line = self.lines.len() - 1; self.edit_point.index = self.current_line_length(); + if self.selection_origin.is_some() && + (self.selection_direction == SelectionDirection::Backward) + { + self.selection_origin = Some(self.edit_point); + } return; } @@ -456,6 +467,16 @@ impl<T: ClipboardProvider> TextInput<T> { .count(); self.edit_point.line = target_line as usize; self.edit_point.index = len_of_first_n_chars(&self.lines[self.edit_point.line], col); + if let Some(origin) = self.selection_origin { + if ((self.selection_direction == SelectionDirection::None || + self.selection_direction == SelectionDirection::Forward) && + self.edit_point <= origin) || + (self.selection_direction == SelectionDirection::Backward && + origin <= self.edit_point) + { + self.selection_origin = Some(self.edit_point); + } + } self.assert_ok_selection(); } |