Fixed focus issue

This commit is contained in:
Tig
2024-09-11 09:45:19 -06:00
parent 889c59c7be
commit 8cf6cdeb87
4 changed files with 44 additions and 35 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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 ()