diff --git a/Terminal.Gui/Application/Application.Keyboard.cs b/Terminal.Gui/Application/Application.Keyboard.cs index 0c8b2544c..9a9d43736 100644 --- a/Terminal.Gui/Application/Application.Keyboard.cs +++ b/Terminal.Gui/Application/Application.Keyboard.cs @@ -365,7 +365,7 @@ public static partial class Application // Keyboard handling View? viewToArrange = Navigation?.GetFocused (); // Go up the superview hierarchy and find the first that is not ViewArrangement.Fixed - while (viewToArrange?.SuperView is { } && viewToArrange.Arrangement == ViewArrangement.Fixed) + while (viewToArrange is { SuperView: { }, Arrangement: ViewArrangement.Fixed }) { viewToArrange = viewToArrange.SuperView; } diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 1155b1d1b..5ce52fc2b 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -748,9 +748,6 @@ public class Border : Adornment return false; } - CanFocus = true; - SetFocus (); - Debug.Assert (_arrangeButton is null); _arrangeButton = new Button { @@ -764,6 +761,9 @@ public class Border : Adornment }; Add (_arrangeButton); + CanFocus = true; + //_arrangeButton.SetFocus (); + AddCommand (Command.Quit, EndArrange); AddCommand (Command.Up, @@ -834,34 +834,8 @@ public class Border : Adornment return true; }); - AddCommand (Command.Tab, - () => - { - // TODO: Move arrangement focus to next side - if (Parent!.Arrangement.HasFlag (ViewArrangement.Resizable)) - { - _arranging = ViewArrangement.Resizable; - _arrangeButton.X = Pos.AnchorEnd (); - _arrangeButton.Y = Pos.AnchorEnd (); - - return true; - } - return true; - }); - - AddCommand (Command.BackTab, - () => - { - // TODO: Move arrangement focus to prev side - if (Parent!.Arrangement.HasFlag (ViewArrangement.Movable)) - { - _arranging = ViewArrangement.Movable; - _arrangeButton.X = 0; - _arrangeButton.Y = 0; - return true; - } - return true; - }); + AddCommand (Command.Tab, Navigate); + AddCommand (Command.BackTab, Navigate); KeyBindings.Add (Key.Esc, KeyBindingScope.HotKey, Command.Quit); KeyBindings.Add (Application.ArrangeKey, KeyBindingScope.HotKey, Command.Quit); @@ -895,18 +869,43 @@ public class Border : Adornment // Hack for now EndArrange (); return false; + + bool? Navigate () + { + if (_arranging == ViewArrangement.Movable) + { + if (Parent!.Arrangement.HasFlag (ViewArrangement.Resizable)) + { + _arranging = ViewArrangement.Resizable; + _arrangeButton.X = Pos.AnchorEnd (); + _arrangeButton.Y = Pos.AnchorEnd (); + } + } + else if (_arranging == ViewArrangement.Resizable) + { + if (Parent!.Arrangement.HasFlag (ViewArrangement.Movable)) + { + _arranging = ViewArrangement.Movable; + _arrangeButton.X = 0; + _arrangeButton.Y = 0; + } + } + + return true; + } } private bool? EndArrange () { _arranging = ViewArrangement.Fixed; CanFocus = false; - KeyBindings.Clear (); - Remove (_arrangeButton); _arrangeButton.Dispose (); _arrangeButton = null; + KeyBindings.Clear (); + + return true; } } diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index 77b9b8cbc..f6d5aa56a 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -587,6 +587,16 @@ public partial class View // Focus and cross-view navigation management (TabStop return; } + // Are we an Adornment? + if (this is Adornment ad) + { + if (ad.Parent is {} && ad.Parent.RestoreFocus ()) + { + // The above will cause SetHasFocusFalse, so we can return + return; + } + } + if (Application.Navigation is { } && Application.Current is { }) { // Temporarily ensure this view can't get focus diff --git a/UICatalog/Scenarios/Navigation.cs b/UICatalog/Scenarios/Navigation.cs index 14bba45c7..d2c0c27a6 100644 --- a/UICatalog/Scenarios/Navigation.cs +++ b/UICatalog/Scenarios/Navigation.cs @@ -225,7 +225,7 @@ public class Navigation : Scenario BorderStyle = LineStyle.Double, CanFocus = true, // Can't drag without this? BUGBUG TabStop = TabBehavior.TabGroup, - Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped + Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped | ViewArrangement.Resizable }; Button button = new ()