From ea4d0646b2fa71d839cc6fae855c277836c0a802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Bj=C3=B6rkstr=C3=B6m?= Date: Mon, 9 Jul 2018 22:59:36 +0300 Subject: [PATCH] Fix for setting and removing focus when using mouse. - Ensure focus is always sent up the chain of subviews. - Ensure that removed focus is sent down the chain of subviews. --- Terminal.Gui/Core.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 9a9c65fb4..ace30b8f1 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -728,8 +728,15 @@ namespace Terminal.Gui { if (base.HasFocus != value) SetNeedsDisplay (); base.HasFocus = value; + + // Remove focus down the chain of subviews if focus is removed + if (value == false && focused != null) { + focused.HasFocus = false; + focused = null; + } } } + /// /// Returns the currently focused view inside this view, or null if nothing is focused. /// @@ -847,9 +854,13 @@ namespace Terminal.Gui { if (focused != null) focused.HasFocus = false; + focused = view; focused.HasFocus = true; focused.EnsureFocus (); + + // Send focus upwards + SuperView?.SetFocus(this); } /// Contains the details about the key that produced the event. @@ -1752,7 +1763,7 @@ namespace Terminal.Gui { if (view != null) { if (!view.WantMousePositionReports && me.Flags == MouseFlags.ReportMousePosition) return; - + var nme = new MouseEvent () { X = rx, Y = ry,