diff --git a/editor/animation/animation_track_editor.cpp b/editor/animation/animation_track_editor.cpp index 5abf088fd67..b825279e510 100644 --- a/editor/animation/animation_track_editor.cpp +++ b/editor/animation/animation_track_editor.cpp @@ -3921,8 +3921,13 @@ void AnimationTrackEditor::remove_track_edit_plugin(const Ref &p_anim, bool p_read_only) { - if (animation != p_anim && _get_track_selected() >= 0) { - track_edits[_get_track_selected()]->release_focus(); + if (animation != p_anim) { + for (int i = 0; i < track_edits.size(); i++) { + if (track_edits[i]->has_focus()) { + track_edits[i]->release_focus(); + break; + } + } } if (animation.is_valid()) { animation->disconnect_changed(callable_mp(this, &AnimationTrackEditor::_animation_changed)); @@ -4191,7 +4196,11 @@ void AnimationTrackEditor::_animation_track_remove_request(int p_track, Ref(get_viewport()->gui_get_focus_owner())) { - track_edits[p_track]->grab_focus(); + for (int i = 0; i < track_edits.size(); i++) { + if (track_edits[i]->get_track() == p_track) { + track_edits[i]->grab_focus(); + } + } } } @@ -5704,7 +5713,7 @@ void AnimationTrackEditor::_timeline_value_changed(double) { int AnimationTrackEditor::_get_track_selected() { for (int i = 0; i < track_edits.size(); i++) { if (track_edits[i]->has_focus()) { - return i; + return track_edits[i]->get_track(); } }