From 175aa299029e797b7288f51b4d95c2d53a45fce9 Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Sun, 6 Oct 2024 11:31:36 +0200 Subject: [PATCH] fix: Skip updated but also removed accessibility nodes (#964) * fix: Skip updated but also removed accessibility nodes * fix: lint --- crates/common/src/accessibility.rs | 4 ++-- crates/core/src/accessibility/tree.rs | 24 +++++++++++++----------- crates/core/src/dom/mutations_writer.rs | 5 ++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/common/src/accessibility.rs b/crates/common/src/accessibility.rs index 2ee331f2b..a8d51a7b8 100644 --- a/crates/common/src/accessibility.rs +++ b/crates/common/src/accessibility.rs @@ -25,8 +25,8 @@ impl AccessibilityDirtyNodes { self.added_or_updated.insert(node_id); } - pub fn remove(&mut self, node_id: NodeId, ancestor_node_id: NodeId) { - self.removed.insert(node_id, ancestor_node_id); + pub fn remove(&mut self, node_id: NodeId, parent_id: NodeId) { + self.removed.insert(node_id, parent_id); } pub fn clear(&mut self) { diff --git a/crates/core/src/accessibility/tree.rs b/crates/core/src/accessibility/tree.rs index f54c61f18..1c2f424f4 100644 --- a/crates/core/src/accessibility/tree.rs +++ b/crates/core/src/accessibility/tree.rs @@ -149,6 +149,19 @@ impl AccessibilityTree { ); } + // Remove all the removed nodes from the update list + for (node_id, _) in removed_ids.iter() { + added_or_updated_ids.remove(node_id); + self.map.retain(|_, id| id != node_id); + } + + // Mark the parent of the removed nodes as updated + for (_, parent_id) in removed_ids.iter() { + if !removed_ids.contains_key(parent_id) { + added_or_updated_ids.insert(*parent_id); + } + } + // Mark the ancestors as modified for node_id in added_or_updated_ids.clone() { let node_ref = rdom.get(node_id).unwrap(); @@ -158,17 +171,6 @@ impl AccessibilityTree { .insert(node_ref.get_accessibility_id().unwrap(), node_id); } - // Mark the still existing ancenstors as modified - for (_, ancestor_node_id) in removed_ids.iter() { - added_or_updated_ids.insert(*ancestor_node_id); - } - - // Remove all the deleted noeds from the added_or_update list - for (node_id, _) in removed_ids { - added_or_updated_ids.remove(&node_id); - self.map.retain(|_, id| *id != node_id); - } - // Create the updated nodes let mut nodes = Vec::new(); for node_id in added_or_updated_ids { diff --git a/crates/core/src/dom/mutations_writer.rs b/crates/core/src/dom/mutations_writer.rs index aeb1d59be..84ccf29ba 100644 --- a/crates/core/src/dom/mutations_writer.rs +++ b/crates/core/src/dom/mutations_writer.rs @@ -90,11 +90,10 @@ impl<'a> MutationsWriter<'a> { // Remove from the accessibility tree if node.get_accessibility_id().is_some() { - let closed_accessibility_node_id = node + let parent_id = node .parent_id() .unwrap_or(self.native_writer.rdom.root_id()); - self.accessibility_dirty_nodes - .remove(node.id(), closed_accessibility_node_id); + self.accessibility_dirty_nodes.remove(node.id(), parent_id); } // Unite the removed area with the dirty area