diff options
author | Jon Leighton <j@jonathanleighton.com> | 2017-12-09 21:55:01 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2018-01-26 19:50:52 +0100 |
commit | 648bfbeb022d02fca3fb6da14a6247390d0f070b (patch) | |
tree | 504cbf464894782d281acb4ee0b12836493001bd /components/script/textinput.rs | |
parent | 02883a6f5408f1fbbe23a63e5dc4d820e220a071 (diff) | |
download | servo-648bfbeb022d02fca3fb6da14a6247390d0f070b.tar.gz servo-648bfbeb022d02fca3fb6da14a6247390d0f070b.zip |
Fix clearing the selection when value is changed
The implementation of adjust_horizontal_to_limit() is written with UI in
mind. As such, when there's a selection and we "adjust horizontal", the
selection will be cleared and the cursor will and up at the start/end of
the previous selection. This is what happens when you have a selection
and you press an arrow key on your keyboard, but it isn't the behaviour
we want when programmatically changing the value.
Instead, we need to first clear the selection, and then move the cursor
to the end. (We also need to reset the selection direction when clearing
the selection.)
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index b4e39eab3f8..d703ccee987 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -513,6 +513,13 @@ impl<T: ClipboardProvider> TextInput<T> { /// Remove the current selection. pub fn clear_selection(&mut self) { self.selection_origin = None; + self.selection_direction = SelectionDirection::None; + } + + /// Remove the current selection and set the edit point to the end of the content. + pub fn clear_selection_to_limit(&mut self) { + self.clear_selection(); + self.adjust_horizontal_to_limit(Direction::Forward, Selection::NotSelected); } pub fn adjust_horizontal_by_word(&mut self, direction: Direction, select: Selection) { |