Repository: microsoft/terminal
File: src/cascadia/TerminalApp/ActionPreviewHandlers.cpp (C++)

Code before:
        {
            _ApplyToActiveControls([&](const auto& control) {
                // Stash a copy of the current scheme.
                auto originalScheme{ control.ColorScheme() };

                // Apply the new scheme.
                control.ColorScheme(scheme.ToCoreScheme());

                // Each control will emplace a revert into the
                // _restorePreviewFuncs for itself.
                _restorePreviewFuncs.emplace_back([=]() {
                    // On dismiss, restore the original scheme.
                    control.ColorScheme(originalScheme);
                });
            });
        }
    }

    void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
    {
        // Clear the saved preview funcs because we don't need to add a restore each time
        // the preview color changes, we only need to be able to restore the last one.
        _restorePreviewFuncs.clear();

        _ApplyToActiveControls([&](const auto& control) {
            // Stash a copy of the original scheme.
            auto originalOpacity{ control.BackgroundOpacity() };

            // Apply the new opacity
            control.AdjustOpacity(args.Opacity(), args.Relative());

            _restorePreviewFuncs.emplace_back([=]() {
                // On dismiss:
                // Don't adjust relatively, just set outright.
                control.AdjustOpacity(::base::saturated_cast<int>(originalOpacity * 100), false);
            });
        });
    }

    // Method Description:
    // - Handler for the CommandPalette::PreviewAction event. The Command
    //   Palette will raise this even when an action is selected, but _not_
    //   committed. This gives the Terminal a chance to display a "preview" of
    //   the action.
    // - This will be called with a null args before an action is dispatched, or
    //   when the palette is dismissed.
    // - For any actions that are to be previewed here, MAKE SURE TO RESTORE THE
    //   STATE IN `TerminalPage::_EndPreview`. That method is called to revert
    //   the terminal to the state it was in at the start of the preview.
    // - Currently, only SetColorScheme actions are preview-able.
    // Arguments:

Review comment (suggestion):
```suggestion
            // Stash a copy of the original
```

Code after:
            _ApplyToActiveControls([&](const auto& control) {
                // Stash a copy of the current scheme.
                auto originalScheme{ control.ColorScheme() };

                // Apply the new scheme.
                control.ColorScheme(scheme.ToCoreScheme());

                // Each control will emplace a revert into the
                // _restorePreviewFuncs for itself.
                _restorePreviewFuncs.emplace_back([=]() {
                    // On dismiss, restore the original scheme.
                    control.ColorScheme(originalScheme);
                });
            });
        }
    }

    void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
    {
        // Clear the saved preview funcs because we don't need to add a restore each time
        // the preview changes, we only need to be able to restore the last one.
        _restorePreviewFuncs.clear();

        _ApplyToActiveControls([&](const auto& control) {
            // Stash a copy of the original opacity.
            auto originalOpacity{ control.BackgroundOpacity() };

            // Apply the new opacity
            control.AdjustOpacity(args.Opacity(), args.Relative());

            _restorePreviewFuncs.emplace_back([=]() {
                // On dismiss:
                // Don't adjust relatively, just set outright.
                control.AdjustOpacity(::base::saturated_cast<int>(originalOpacity * 100), false);
            });
        });
    }

    // Method Description:
    // - Handler for the CommandPalette::PreviewAction event. The Command
    //   Palette will raise this even when an action is selected, but _not_
    //   committed. This gives the Terminal a chance to display a "preview" of
    //   the action.
    // - This will be called with a null args before an action is dispatched, or
    //   when the palette is dismissed.
    // - For any actions that are to be previewed here, MAKE SURE TO RESTORE THE
    //   STATE IN `TerminalPage::_EndPreview`. That method is called to revert
    //   the terminal to the state it was in at the start of the preview.
    // - Currently, only SetColorScheme actions are preview-able.
    // Arguments:
    // - args: The Command that's trying to be previewed, or nullptr if we should stop the preview.