From e3757f97ed9321590c981b17096397852b47bc4b Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 6 May 2022 17:01:50 -0500 Subject: [PATCH] only trigger onmousemove if the position has changed --- packages/tui/src/hooks.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/tui/src/hooks.rs b/packages/tui/src/hooks.rs index 658229fae..38ab6659b 100644 --- a/packages/tui/src/hooks.rs +++ b/packages/tui/src/hooks.rs @@ -242,23 +242,25 @@ impl InnerInputState { { // mousemove - let mut will_bubble = FxHashSet::default(); - for node in dom.get_listening_sorted("mousemove") { - let node_layout = layout.layout(node.state.layout.node.unwrap()).unwrap(); - let previously_contained = old_pos - .filter(|pos| layout_contains_point(node_layout, *pos)) - .is_some(); - let currently_contains = layout_contains_point(node_layout, new_pos); + if old_pos != Some(new_pos) { + let mut will_bubble = FxHashSet::default(); + for node in dom.get_listening_sorted("mousemove") { + let node_layout = layout.layout(node.state.layout.node.unwrap()).unwrap(); + let previously_contained = old_pos + .filter(|pos| layout_contains_point(node_layout, *pos)) + .is_some(); + let currently_contains = layout_contains_point(node_layout, new_pos); - if currently_contains && previously_contained { - try_create_event( - "mousemove", - Arc::new(prepare_mouse_data(mouse_data, node_layout)), - &mut will_bubble, - resolved_events, - node, - dom, - ); + if currently_contains && previously_contained { + try_create_event( + "mousemove", + Arc::new(prepare_mouse_data(mouse_data, node_layout)), + &mut will_bubble, + resolved_events, + node, + dom, + ); + } } } }