aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/textcontrol.rs
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2017-12-09 22:23:47 +0100
committerJon Leighton <j@jonathanleighton.com>2018-01-26 19:50:53 +0100
commite34f7c58c933494be4f4af3fdfa45601c225d75f (patch)
tree671646a37eeb0d9f11b30a899aa809add60159a4 /components/script/dom/textcontrol.rs
parent648bfbeb022d02fca3fb6da14a6247390d0f070b (diff)
downloadservo-e34f7c58c933494be4f4af3fdfa45601c225d75f.tar.gz
servo-e34f7c58c933494be4f4af3fdfa45601c225d75f.zip
Don't fire select event when selection hasn't changed
Diffstat (limited to 'components/script/dom/textcontrol.rs')
-rw-r--r--components/script/dom/textcontrol.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/components/script/dom/textcontrol.rs b/components/script/dom/textcontrol.rs
index 4770b1ae18d..85211a7990d 100644
--- a/components/script/dom/textcontrol.rs
+++ b/components/script/dom/textcontrol.rs
@@ -136,6 +136,9 @@ pub trait TextControl: DerivedFrom<EventTarget> + DerivedFrom<Node> {
// https://html.spec.whatwg.org/multipage/#set-the-selection-range
fn set_selection_range(&self, start: Option<u32>, end: Option<u32>, direction: Option<SelectionDirection>) {
+ let mut textinput = self.textinput().borrow_mut();
+ let original_selection_state = textinput.selection_state();
+
// Step 1
let start = start.unwrap_or(0);
@@ -143,16 +146,18 @@ pub trait TextControl: DerivedFrom<EventTarget> + DerivedFrom<Node> {
let end = end.unwrap_or(0);
// Steps 3-5
- self.textinput().borrow_mut().set_selection_range(start, end, direction.unwrap_or(SelectionDirection::None));
+ textinput.set_selection_range(start, end, direction.unwrap_or(SelectionDirection::None));
// Step 6
- let window = window_from_node(self);
- let _ = window.user_interaction_task_source().queue_event(
- &self.upcast::<EventTarget>(),
- atom!("select"),
- EventBubbles::Bubbles,
- EventCancelable::NotCancelable,
- &window);
+ if textinput.selection_state() != original_selection_state {
+ let window = window_from_node(self);
+ window.user_interaction_task_source().queue_event(
+ &self.upcast::<EventTarget>(),
+ atom!("select"),
+ EventBubbles::Bubbles,
+ EventCancelable::NotCancelable,
+ &window);
+ }
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}