diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-12 17:25:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-12 17:25:10 -0700 |
commit | 496e45b190edc3b7f6ebb42e0a849a3d55a184d6 (patch) | |
tree | 19eac00c91f584890c5bbae8b1708797138be11c | |
parent | 3c3c32f95e7e125117b0dc5d6e7eacea3422749c (diff) | |
parent | 6c7e8129663024329e30e6905573fb76bdb96e0a (diff) | |
download | servo-496e45b190edc3b7f6ebb42e0a849a3d55a184d6.tar.gz servo-496e45b190edc3b7f6ebb42e0a849a3d55a184d6.zip |
Auto merge of #12301 - ConnorGBrewster:selection_direction, r=asajeffrey
Take selection direction into account when setting selection
<!-- Please describe your changes on the following line: -->
r? @asajeffrey
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #12300 (github issue number if applicable).
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12301)
<!-- Reviewable:end -->
-rw-r--r-- | components/script/textinput.rs | 13 | ||||
-rw-r--r-- | tests/unit/script/textinput.rs | 23 |
2 files changed, 34 insertions, 2 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 871af9637c0..5beee247f96 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -651,8 +651,17 @@ impl<T: ClipboardProvider> TextInput<T> { start = end; } - self.selection_begin = Some(self.get_text_point_for_absolute_point(start)); - self.edit_point = self.get_text_point_for_absolute_point(end); + match self.selection_direction { + SelectionDirection::None | + SelectionDirection::Forward => { + self.selection_begin = Some(self.get_text_point_for_absolute_point(start)); + self.edit_point = self.get_text_point_for_absolute_point(end); + }, + SelectionDirection::Backward => { + self.selection_begin = Some(self.get_text_point_for_absolute_point(end)); + self.edit_point = self.get_text_point_for_absolute_point(start); + } + } self.assert_ok_selection(); } diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index d5e9c1268d6..01d8931ff67 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -458,3 +458,26 @@ fn test_textinput_cursor_position_correct_after_clearing_selection() { assert_eq!(textinput.edit_point.index, 0); assert_eq!(textinput.edit_point.line, 0); } + + +#[test] +fn test_textinput_set_selection_with_direction() { + let mut textinput = text_input(Lines::Single, "abcdef"); + textinput.selection_direction = SelectionDirection::Forward; + textinput.set_selection_range(2, 6); + assert_eq!(textinput.edit_point.line, 0); + assert_eq!(textinput.edit_point.index, 6); + + assert!(textinput.selection_begin.is_some()); + assert_eq!(textinput.selection_begin.unwrap().line, 0); + assert_eq!(textinput.selection_begin.unwrap().index, 2); + + textinput.selection_direction = SelectionDirection::Backward; + textinput.set_selection_range(2, 6); + assert_eq!(textinput.edit_point.line, 0); + assert_eq!(textinput.edit_point.index, 2); + + assert!(textinput.selection_begin.is_some()); + assert_eq!(textinput.selection_begin.unwrap().line, 0); + assert_eq!(textinput.selection_begin.unwrap().index, 6); +} |