aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2017-12-09 21:55:01 +0100
committerJon Leighton <j@jonathanleighton.com>2018-01-26 19:50:52 +0100
commit648bfbeb022d02fca3fb6da14a6247390d0f070b (patch)
tree504cbf464894782d281acb4ee0b12836493001bd /components/script/dom
parent02883a6f5408f1fbbe23a63e5dc4d820e220a071 (diff)
downloadservo-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/dom')
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs5
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs4
2 files changed, 4 insertions, 5 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 2e26d7fe53f..cd476a47f2b 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -52,7 +52,7 @@ use std::ops::Range;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style::str::split_commas;
-use textinput::{Direction, Selection, SelectionDirection, TextInput};
+use textinput::{SelectionDirection, TextInput};
use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction};
use textinput::Lines::Single;
@@ -563,8 +563,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
self.sanitize_value();
// Step 5.
if *self.textinput.borrow().single_line_content() != old_value {
- self.textinput.borrow_mut()
- .adjust_horizontal_to_limit(Direction::Forward, Selection::NotSelected);
+ self.textinput.borrow_mut().clear_selection_to_limit();
}
}
ValueMode::Default |
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index a2b52ce3087..b2e78e083c0 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -35,7 +35,7 @@ use std::default::Default;
use std::ops::Range;
use style::attr::AttrValue;
use style::element_state::ElementState;
-use textinput::{Direction, KeyReaction, Lines, Selection, SelectionDirection, TextInput};
+use textinput::{KeyReaction, Lines, SelectionDirection, TextInput};
#[dom_struct]
pub struct HTMLTextAreaElement {
@@ -257,7 +257,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
if old_value != textinput.get_content() {
// Step 4
- textinput.adjust_horizontal_to_limit(Direction::Forward, Selection::NotSelected);
+ textinput.clear_selection_to_limit();
} else {
textinput.selection_origin = old_selection;
}