From 357bc32ac3899e263b2d8a7451dd89aff39db81e Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 16 Sep 2024 16:43:02 -0600 Subject: [PATCH] Fixed focus issue - 2 --- Terminal.Gui/View/View.Hierarchy.cs | 15 ++++++--------- Terminal.Gui/View/View.Navigation.cs | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Terminal.Gui/View/View.Hierarchy.cs b/Terminal.Gui/View/View.Hierarchy.cs index 24215eb44..984724d1a 100644 --- a/Terminal.Gui/View/View.Hierarchy.cs +++ b/Terminal.Gui/View/View.Hierarchy.cs @@ -160,6 +160,10 @@ public partial class View // SuperView/SubView hierarchy management (SuperView, Rectangle touched = view.Frame; bool hadFocus = view.HasFocus; + bool couldFocus = view.CanFocus; + + view.CanFocus = false; // If view had focus, this will ensure it doesn't and it stays that way + Debug.Assert (!view.HasFocus); _subviews.Remove (view); view._superView = null; @@ -175,20 +179,13 @@ public partial class View // SuperView/SubView hierarchy management (SuperView, } } + view.CanFocus = couldFocus; // Restore to previous value + if (_previouslyFocused == view) { _previouslyFocused = null; } - if (hadFocus) - { - // Access _hasFocus directly; don't use HasFocus because it will try to find the focused view - view._hasFocus = false; - AdvanceFocus (NavigationDirection.Forward, null); - } - - Debug.Assert (!view.HasFocus); - OnRemoved (new (this, view)); return view; diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index 205183fe9..610b4eb27 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -477,9 +477,6 @@ public partial class View // Focus and cross-view navigation management (TabStop if (!AdvanceFocus (NavigationDirection.Forward, null)) { // Couldn't advance, so we're the most focused view in the application - _previouslyFocused = null; - - Application.Navigation?.SetFocused (this); } } } @@ -497,6 +494,9 @@ public partial class View // Focus and cross-view navigation management (TabStop } } + _previouslyFocused = null; + Application.Navigation?.SetFocused (this); + if (Arrangement.HasFlag (ViewArrangement.Overlapped)) { SuperView?.MoveSubviewToEnd (this);