Browse Source

Fix null reference exception when OnLeave event handlers clear focus.

tznind 2 years ago
parent
commit
656fe727f0
1 changed files with 3 additions and 2 deletions
  1. 3 2
      Terminal.Gui/Core/View.cs

+ 3 - 2
Terminal.Gui/Core/View.cs

@@ -1321,8 +1321,9 @@ namespace Terminal.Gui {
 
 			// Remove focus down the chain of subviews if focus is removed
 			if (!value && focused != null) {
-				focused.OnLeave (view);
-				focused.SetHasFocus (false, view);
+				var f = focused;
+				f.OnLeave (view);
+				f.SetHasFocus (false, view);
 				focused = null;
 			}
 		}