Repository: microsoft/terminal (language: cpp)

Issue:
The color scheme preview in the settings UI no longer works
### Windows Terminal version

Commit 094273b995352ff9d80f36279c297488b756df1d

### Windows build number

10.0.19041.1348

### Other Software

_No response_

### Steps to reproduce

1. Open the Settings UI
2. Navigate to the profile _Defaults_ section.
3. Select the _Appearance_ tab.
4. Flip through different _Color scheme_ options while watching the preview window.


### Expected Behavior

The preview should update to reflect the selected color scheme.

### Actual Behavior

The preview doesn't change.

I did a git bisect of the code, which reported commit 094273b995352ff9d80f36279c297488b756df1d as the point at which this stop working. However, I'm wondering if perhaps it's an interaction between those changes and the color table refactoring I was doing in #11602 and #11784.


Discussion / hints:
> which reported commit [094273b](https://github.com/microsoft/terminal/commit/094273b995352ff9d80f36279c297488b756df1d) as the point at which this stop working

That would have been my guess as well. If this is all that broke, that's pretty dang impressive. I'll add this to 1.13 to make sure this gets resolved before shipping. Thanks!
FYI, I think this has got something to do with "unfocused appearance". I could "fix" the issue by changing the line below so it always passes in `_core.FocusedAppearance()`:

https://github.com/microsoft/terminal/blob/094273b995352ff9d80f36279c297488b756df1d/src/cascadia/TerminalControl/TermControl.cpp#L252

And also changing this call so the parameter hardcoded to `true`:

https://github.com/microsoft/terminal/blob/094273b995352ff9d80f36279c297488b756df1d/src/cascadia/TerminalControl/TermControl.cpp#L313

I'm sure that's not the right solution, but that at least gives you an idea of where things are going wrong. It seems to be attempting to use the unfocused appearance when rendering the preview, and in my case that wasn't actually set to anything.
It looks like the problem is that the preview control is created disabled, and with `AllowFocusWhenDisabled` set to false. Since it can never gain focus, it always renders with the unfocused appearance.

https://github.com/microsoft/terminal/blob/094273b995352ff9d80f36279c297488b756df1d/src/cascadia/TerminalSettingsEditor/Profiles.cpp#L414-L415

One possible fix would be to set the `_focused` property to true by default when `TermControl` is created, and rely on the control receiving a lost focus event (when not disabled) to change that to false when necessary. The preview control wouldn't receive those events so would always be viewed as focused.

If there are situations where the  `_focused`  property _has_ to be false by default, we could always add the initial focus state as a constructor parameter, or maybe add a method to force the focused state.

I don't know much about the UI side of things, though, so maybe it's more complicated than this. Just throwing out some ideas.
Yea, that all makes sense. Messing with `_focused` might just give us a fix for #11411 too. The trick there though is making sure when you're opening a bunch of panes at once that only the last one actually gets the blinking cursor. 

But now I'm looking at the pair of these so hopefully I can come up with something

Fix patch:
diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.cpp b/src/cascadia/TerminalSettingsEditor/Profiles.cpp
index 39f7916d061..1b54ecb2b62 100644
--- a/src/cascadia/TerminalSettingsEditor/Profiles.cpp
+++ b/src/cascadia/TerminalSettingsEditor/Profiles.cpp
@@ -74,13 +74,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
             {
                 _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentScrollState" });
             }
-            _previewControl.UpdateControlSettings(_Profile.TermSettings());
+            _previewControl.UpdateControlSettings(_Profile.TermSettings(), _Profile.TermSettings());
         });
 
         // The Appearances object handles updating the values in the settings UI, but
         // we still need to listen to the changes here just to update the preview control
         _AppearanceViewModelChangedRevoker = _Profile.DefaultAppearance().PropertyChanged(winrt::auto_revoke, [=](auto&&, const PropertyChangedEventArgs& /*args*/) {
-            _previewControl.UpdateControlSettings(_Profile.TermSettings());
+            _previewControl.UpdateControlSettings(_Profile.TermSettings(), _Profile.TermSettings());
         });
 
         // Navigate to the pivot in the provided navigation state
@@ -90,7 +90,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
         // so wait for it to initialize before updating the settings (so we know
         // that the renderer is set up)
         _previewControl.Initialized([&](auto&& /*s*/, auto&& /*e*/) {
-            _previewControl.UpdateControlSettings(_Profile.TermSettings());
+            _previewControl.UpdateControlSettings(_Profile.TermSettings(), _Profile.TermSettings());
         });
     }
 


Test patch: