Skip to content

Commit f2ffae1

Browse files
committed
Set TabStop as TabGroup which allow F6 shortcut.
1 parent d4f061d commit f2ffae1

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

Terminal.Gui/Views/TabView/TabRowView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public TabRowView (TabView host)
1313
Id = "tabRowView";
1414

1515
CanFocus = true;
16+
TabStop = TabBehavior.TabGroup;
1617
Width = Dim.Fill ();
1718

1819
_rightScrollIndicator = new View

UnitTests/Views/TabViewTests.cs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border ()
365365
}
366366

367367
[Fact]
368-
[AutoInitShutdown]
369-
public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
368+
[SetupFakeDriver]
369+
public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 ()
370370
{
371-
TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
371+
TabView tv = GetTabView (out Tab tab1, out Tab tab2);
372372

373373
tv.Width = 7;
374374
tv.Height = 5;
@@ -393,7 +393,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
393393
Assert.Equal (tv.SelectedTab.View, top.Focused.MostFocused);
394394

395395
// Press the cursor up key to focus the selected tab
396-
Application.RaiseKeyDownEvent (Key.CursorUp);
396+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
397397
Application.LayoutAndDraw ();
398398

399399
// Is the selected tab focused
@@ -411,7 +411,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
411411
};
412412

413413
// Press the cursor right key to select the next tab
414-
Application.RaiseKeyDownEvent (Key.CursorRight);
414+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorRight));
415415
Application.LayoutAndDraw ();
416416
Assert.Equal (tab1, oldChanged);
417417
Assert.Equal (tab2, newChanged);
@@ -420,7 +420,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
420420
Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
421421

422422
// Press the cursor down key. Since the selected tab has no focusable views, the focus should move to the next view in the toplevel
423-
Application.RaiseKeyDownEvent (Key.CursorDown);
423+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
424424
Assert.Equal (tab2, tv.SelectedTab);
425425
Assert.Equal (btn, top.MostFocused);
426426

@@ -436,40 +436,55 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
436436
Assert.False (tv.SelectedTab.View.CanFocus);
437437

438438
// Press cursor up. Should focus the subview in the selected tab.
439-
Application.RaiseKeyDownEvent (Key.CursorUp);
439+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
440440
Assert.Equal (tab2, tv.SelectedTab);
441441
Assert.NotEqual (btnSubView, top.MostFocused);
442442
Assert.Equal (tab2, top.MostFocused);
443443

444444
tv.SelectedTab.View.CanFocus = true;
445-
Application.RaiseKeyDownEvent (Key.CursorDown);
445+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
446446
Assert.Equal (tab2, tv.SelectedTab);
447447
Assert.Equal (btnSubView, top.MostFocused);
448448

449-
Application.RaiseKeyDownEvent (Key.CursorUp);
449+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
450+
// TabRowView now has TabGroup which only F6 is allowed
451+
Assert.NotEqual (tab2, top.MostFocused);
452+
Assert.Equal (btn, top.MostFocused);
453+
454+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
455+
Assert.Equal (btnSubView, top.MostFocused);
456+
457+
Assert.True (Application.RaiseKeyDownEvent (Key.F6));
450458
Assert.Equal (tab2, top.MostFocused);
451459

452460
// Press the cursor down key twice.
453-
Application.RaiseKeyDownEvent (Key.CursorDown);
454-
Application.RaiseKeyDownEvent (Key.CursorDown);
461+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
462+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
455463
Assert.Equal (btn, top.MostFocused);
456464

457465
// Press the cursor down key again will focus next view in the toplevel, which is the TabView
458-
Application.RaiseKeyDownEvent (Key.CursorDown);
466+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown));
459467
Assert.Equal (tab2, tv.SelectedTab);
460468
Assert.Equal (tv, top.Focused);
461469
// Due to the RestoreFocus method prioritize the _previouslyFocused, so btnSubView will be focused again
462470
Assert.Equal (btnSubView, tv.MostFocused);
463471

464472
// Press the cursor up key to focus the selected tab which it's the only way to do that
465-
Application.RaiseKeyDownEvent (Key.CursorUp);
473+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
466474
Assert.Equal (tab2, tv.SelectedTab);
475+
Assert.Equal (btn, top.Focused);
476+
477+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
478+
Assert.Equal (tv, top.Focused);
479+
Assert.Equal (btnSubView, top.MostFocused);
480+
481+
Assert.True (Application.RaiseKeyDownEvent (Key.F6));
467482
Assert.Equal (tv, top.Focused);
468483
Assert.Equal (tab2, top.Focused.MostFocused);
469484
Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
470485

471486
// Press the cursor left key to select the previous tab
472-
Application.RaiseKeyDownEvent (Key.CursorLeft);
487+
Assert.True (Application.RaiseKeyDownEvent (Key.CursorLeft));
473488
Application.LayoutAndDraw ();
474489
Assert.Equal (tab2, oldChanged);
475490
Assert.Equal (tab1, newChanged);
@@ -479,7 +494,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
479494
Assert.Equal (tab1, top.Focused.MostFocused);
480495

481496
// Press the end key to select the last tab
482-
Application.RaiseKeyDownEvent (Key.End);
497+
Assert.True (Application.RaiseKeyDownEvent (Key.End));
483498
Application.LayoutAndDraw ();
484499
Assert.Equal (tab1, oldChanged);
485500
Assert.Equal (tab2, newChanged);
@@ -488,7 +503,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
488503
Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
489504

490505
// Press the home key to select the first tab
491-
Application.RaiseKeyDownEvent (Key.Home);
506+
Assert.True (Application.RaiseKeyDownEvent (Key.Home));
492507
Application.LayoutAndDraw ();
493508
Assert.Equal (tab2, oldChanged);
494509
Assert.Equal (tab1, newChanged);
@@ -497,7 +512,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
497512
Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
498513

499514
// Press the page down key to select the next set of tabs
500-
Application.RaiseKeyDownEvent (Key.PageDown);
515+
Assert.True (Application.RaiseKeyDownEvent (Key.PageDown));
501516
Application.LayoutAndDraw ();
502517
Assert.Equal (tab1, oldChanged);
503518
Assert.Equal (tab2, newChanged);
@@ -506,7 +521,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp ()
506521
Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
507522

508523
// Press the page up key to select the previous set of tabs
509-
Application.RaiseKeyDownEvent (Key.PageUp);
524+
Assert.True (Application.RaiseKeyDownEvent (Key.PageUp));
510525
Application.LayoutAndDraw ();
511526
Assert.Equal (tab2, oldChanged);
512527
Assert.Equal (tab1, newChanged);
@@ -1455,6 +1470,26 @@ public void Add_Three_TabsOnBottom_ChangesTab ()
14551470
);
14561471
}
14571472

1473+
[Fact]
1474+
[SetupFakeDriver]
1475+
public void Tab_Get_Focus_By_Press_F6 ()
1476+
{
1477+
TabView tv = GetTabView (out Tab tab1, out Tab tab2);
1478+
1479+
tv.Width = 20;
1480+
tv.Height = 5;
1481+
1482+
Toplevel top = new ();
1483+
top.Add (tv);
1484+
Application.Begin (top);
1485+
1486+
Assert.False (tab1.HasFocus);
1487+
1488+
Assert.True (Application.RaiseKeyDownEvent (Key.F6));
1489+
Assert.True (tab1.HasFocus);
1490+
top.Dispose ();
1491+
}
1492+
14581493
private TabView GetTabView () { return GetTabView (out _, out _); }
14591494

14601495
private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true)

0 commit comments

Comments
 (0)