Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Terminal.Gui/Application/Application.Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public static bool RaiseKeyDownEvent (Key key)
// }
//#endif

// TODO: This should match standard event patterns
KeyDown?.Invoke (null, key);
KeyDown?.Invoke (Top?.MostFocused, key);

if (key.Handled)
{
Expand Down Expand Up @@ -97,17 +96,11 @@ public static bool RaiseKeyDownEvent (Key key)
}
else
{
// BUGBUG: this seems unneeded.
if (!KeyBindings.TryGet (key, out KeyBinding keybinding))
{
return null;
}

bool? toReturn = null;

foreach (Command command in keybinding.Commands)
foreach (Command command in binding.Commands)
{
toReturn = InvokeCommand (command, key, keybinding);
toReturn = InvokeCommand (command, key, binding);
}

handled = toReturn ?? true;
Expand All @@ -118,7 +111,7 @@ public static bool RaiseKeyDownEvent (Key key)
}

/// <summary>
/// Invokes an Application-bound commmand.
/// Invokes an Application-bound command.
/// </summary>
/// <param name="command">The Command to invoke</param>
/// <param name="key">The Application-bound Key that was pressed.</param>
Expand Down Expand Up @@ -178,7 +171,7 @@ public static bool RaiseKeyUpEvent (Key key)
return true;
}

KeyUp?.Invoke (null, key);
KeyUp?.Invoke (Top?.MostFocused, key);

if (key.Handled)
{
Expand Down
5 changes: 1 addition & 4 deletions Terminal.Gui/View/View.Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ private void SetupCommands ()
return true;
}

SetFocus ();

// QUESTION: Why do we always return true here?
return true;
return SetFocus ();
});

// Space or single-click - Raise Selecting
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/View/View.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)
if (direction == NavigationDirection.Backward && focused == focusChain [0])
{
// We're at the bottom of the focus chain
View [] views = GetFocusChain (NavigationDirection.Forward, TabBehavior.TabGroup);
View [] views = GetFocusChain (NavigationDirection.Backward, TabBehavior.TabGroup);

if (views.Length > 0)
{
Expand Down Expand Up @@ -531,7 +531,7 @@ public bool SetFocus ()
// throw new InvalidOperationException (@"Do not SetFocus on a view that is already MostFocused.");
//}

return (false, false);
return (_hasFocus, false);
}

if (currentFocusedView is { HasFocus: false })
Expand Down
6 changes: 3 additions & 3 deletions Terminal.Gui/Views/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public override Rune HotKeySpecifier

if (CanFocus)
{
SetFocus ();
return SetFocus ();

// QUESTION: Why do we always return true here?
return true;
//// QUESTION: Why do we always return true here?
//return true;
}

if (HotKey.IsValid)
Expand Down
34 changes: 34 additions & 0 deletions Tests/IntegrationTests/FluentTests/BasicFluentAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,38 @@ public void ContextMenu_OpenSubmenu (V2TestDriver d)
.WriteOutLogs (_out);
Assert.True (clicked);
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void Toplevel_TabGroup_Forward_Backward (V2TestDriver d)
{
var v1 = new View { Id = "v1", CanFocus = true };
var v2 = new View { Id = "v2", CanFocus = true };

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var w1 = new Window { Id = "w1" };
w1.Add (v1);
var w2 = new Window { Id = "w2" };
w2.Add (v2);
Toplevel top = Application.Top!;
Application.Top!.Add (w1, w2);
})
.WaitIteration ()
.Then (() => Assert.True (v2.HasFocus))
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v1.HasFocus))
.RaiseKeyDownEvent (Key.F6)
.Then (() => Assert.True (v2.HasFocus))
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v1.HasFocus))
.RaiseKeyDownEvent (Key.F6.WithShift)
.Then (() => Assert.True (v2.HasFocus))
.WriteOutLogs (_out)
.Stop ();
Assert.False (v1.HasFocus);
Assert.False (v2.HasFocus);
}
}