Repository: microsoft/terminal (language: cpp)

Issue:
Tab title text sometimes becomes invisible when using the Light theme
### Windows Terminal version

Commit 72d0566fa6d681291799e59a69168fc0483d8277

### Windows build number

10.0.19045.2728

### Other Software

_No response_

### Steps to reproduce

1. Build Windows Terminal from a recent commit.
2. Start with all default settings (just to confirm that nothing else is a factor).
3. Switch the application Theme to _Light_.
4. Open a couple of cmd tabs (any shell will probably suffice).
5. Click on the tab titles to switch between the tabs.


### Expected Behavior

The tab title should remain visible when switching tabs.

### Actual Behavior

As soon as the mouse button is released (after clicking on a tab), the tab title becomes invisible, possibly just rendered as black on black.

![image](https://user-images.githubusercontent.com/4181424/232168351-7c39a15e-54dd-4d9d-b7b4-ddba6024d6ca.png)

If you move the mouse, it should become visible again. But if you move the mouse off the tab fast enough, while it's still invisible, it can remain stuck in that invisible state.

Switching focus to another application also seems make the active tab title invisible.

I don't have this issue in the 1.17.1023 preview build.


Discussion / hints:
~I can't help but think this is somehow related to #15150. Somehow.~

No, it's not that
Theory 2: Something fucky with tab colors post 2.8. Maybe a new resource key. Maybe a different order of application of the `.Foreground()` property on the tab.

It does look like
* deselected pointer over: black ✅
* pointer pressed: white ✅
* selected, Pointer over: black ❌
* selected (no pointer over): white ✅

Interesting that this isn't applying to the close button. Interesting. 
![](https://user-images.githubusercontent.com/18356694/233431020-f998879d-5a0d-4de4-8d65-75064ecbf830.png)

that ain't right. There's no... Children? for the TabViewItem? That can't possibly be right. 

<hr>

Okay this is a dumb lead, but I originally was reproing this _constantly_ on 1825ca1 but wait that was _after_ 9b960bc. hmm. Not a lead after all. 

On `main` (ffda8c4), I can only repro this with closing the last, active tab, which causes the previous tab to become activated, without the pointer being over it. Interesting. 


![](https://media.tenor.com/OghEspcGUhEAAAAC/its-so-dumb-so-dumb.gif)

Fix patch:
diff --git a/src/cascadia/TerminalApp/TabBase.cpp b/src/cascadia/TerminalApp/TabBase.cpp
index 08b696e175e..32627a3b925 100644
--- a/src/cascadia/TerminalApp/TabBase.cpp
+++ b/src/cascadia/TerminalApp/TabBase.cpp
@@ -558,17 +558,35 @@ namespace winrt::TerminalApp::implementation
     // BODGY
     // - Toggles the requested theme of the tab view item,
     //   so that changes to the tab color are reflected immediately
-    // - Prior to MUX 2.8, we toggled the visual state here, but that seemingly
+    // - Prior to MUX 2.8, we only toggled the visual state here, but that seemingly
     //   doesn't work in 2.8.
+    // - Just changing the Theme also doesn't seem to work by itself - there
+    //   seems to be a way for the tab to set the deselected foreground onto
+    //   itself as it becomes selected. If the mouse isn't over the tab, that
+    //   can result in mismatched fg/bg's (see GH#15184). So that's right, we
+    //   need to do both.
     // Arguments:
     // - <none>
     // Return Value:
     // - <none>
     void TabBase::_RefreshVisualState()
     {
+        const auto& item{ TabViewItem() };
+
         const auto& reqTheme = TabViewItem().RequestedTheme();
-        TabViewItem().RequestedTheme(ElementTheme::Light);
-        TabViewItem().RequestedTheme(ElementTheme::Dark);
-        TabViewItem().RequestedTheme(reqTheme);
+        item.RequestedTheme(ElementTheme::Light);
+        item.RequestedTheme(ElementTheme::Dark);
+        item.RequestedTheme(reqTheme);
+
+        if (TabViewItem().IsSelected())
+        {
+            VisualStateManager::GoToState(item, L"Normal", true);
+            VisualStateManager::GoToState(item, L"Selected", true);
+        }
+        else
+        {
+            VisualStateManager::GoToState(item, L"Selected", true);
+            VisualStateManager::GoToState(item, L"Normal", true);
+        }
     }
 }


Test patch: