diff options
author | Jon Leighton <j@jonathanleighton.com> | 2017-12-09 20:17:49 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2018-01-26 19:50:50 +0100 |
commit | 02883a6f5408f1fbbe23a63e5dc4d820e220a071 (patch) | |
tree | 94884d5236a8f0aa6c3c681d539b3ddb85ef881b /components/script/dom/htmltextareaelement.rs | |
parent | 0148e9705b9e6dad41dd1895313c57f2acca3c56 (diff) | |
download | servo-02883a6f5408f1fbbe23a63e5dc4d820e220a071.tar.gz servo-02883a6f5408f1fbbe23a63e5dc4d820e220a071.zip |
Fix selection{Start,End} when selectionDirection is "backward"
Per the spec, selectionStart and selectionEnd should return the same
values regardless of the selectionDirection. (That is, selectionStart is
always less than or equal to selectionEnd; the direction then implies
which of selectionStart or selectionEnd is the cursor position.)
There was no explicit WPT test for this, so I added one.
This bug was initially quite hard to wrap my head around, and I think
part of the problem is the code in TextInput. Therefore, in the process
of fixing it I have refactored the implementation of TextInput:
* Rename selection_begin to selection_origin. This value doesn't
necessarily correspond directly to the selectionStart DOM value - in
the case of a backward selection, it corresponds to selectionEnd.
I feel that "origin" doesn't imply a specific ordering as strongly as
"begin" (or "start" for that matter) does.
* In various other cases where "begin" is used as a synonym for "start",
just use "start" for consistency.
* Implement selection_start() and selection_end() methods (and their
_offset() variants) which directly correspond to their DOM
equivalents.
* Rename other related methods to make them less wordy and more
consistent / intention-revealing.
* Add assertions to assert_ok_selection() to ensure that our assumptions
about the ordering of selection_origin and edit_point are met. This
then revealed a bug in adjust_selection_for_horizontal_change() where
the value of selection_direction was not maintained correctly (causing
a unit test failure when the new assertion failed).
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rwxr-xr-x | components/script/dom/htmltextareaelement.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index e0388011b0f..a2b52ce3087 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -81,7 +81,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<HTMLTextAreaElement> { return None; } let textinput = (*self.unsafe_get()).textinput.borrow_for_layout(); - Some(textinput.get_absolute_selection_range()) + Some(textinput.sorted_selection_offsets_range()) } #[allow(unsafe_code)] @@ -247,7 +247,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { // Step 1 let old_value = textinput.get_content(); - let old_selection = textinput.selection_begin; + let old_selection = textinput.selection_origin; // Step 2 textinput.set_content(value); @@ -259,7 +259,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { // Step 4 textinput.adjust_horizontal_to_limit(Direction::Forward, Selection::NotSelected); } else { - textinput.selection_begin = old_selection; + textinput.selection_origin = old_selection; } self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); |