From b551d14a593258901291ee55b0ae2edd472ac771 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 6 May 2024 13:03:49 +0200 Subject: [PATCH] avm2: Ensure the focus is dropped when it's removed The logic of dropping the focus when it's removed applies not only to TextFields but for every InteractiveObject. This patch ensures that any focus is dropped when its parent is removed. --- core/src/display_object.rs | 4 ++++ core/src/display_object/edit_text.rs | 10 ---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/core/src/display_object.rs b/core/src/display_object.rs index d4d0b7bf9..9c13fc6f5 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -1594,6 +1594,10 @@ pub trait TDisplayObject<'gc>: let parent_removed = had_parent && !has_parent; if parent_removed { + if let Some(int) = self.as_interactive() { + int.drop_focus(context); + } + self.on_parent_removed(context); } } diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index bf21968fe..2d24fb014 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -2114,16 +2114,6 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> { self.0.write(context.gc_context).object = Some(to.into()); } - fn on_parent_removed(&self, context: &mut UpdateContext<'_, 'gc>) { - if self.movie().is_action_script_3() { - let had_focus = self.has_focus(); - if had_focus { - let tracker = context.focus_tracker; - tracker.set(None, context); - } - } - } - fn self_bounds(&self) -> Rectangle { self.0.read().bounds.clone() }