Stop using Settings to shuttle IKeyBindings around (#19314)

For some reason, we went real hard on an architecture where the settings
object contained the key bindings handler for the terminal. To make this
work, we had to wind it through tons of layers: `TermControl`,
`ControlInteractivity`, `ControlCore` (which saved it on
`ControlSettings`), `ControlSettings`. Of course, because we have no
clear delineation of concerns at the App layer this required us to put
the bindings into the Settings Cache[^1].

Well, `TermControl` used `ControlCore` to get the Settings, to get the
Bindings, to dispatch keys.

Yes, `TermControl` stored `IKeyBindings` down three layers _only to fish
it back out and use it itself._

There is one place in the application where `TermControl`s are hooked up
to their owners. Instead of passing the key bindings dispatcher in
through nine hundred layers, we can just set it once--definitively!--
there.

[^1]: This was the last thing that made the settings cache
page-specific...
This commit is contained in:
Dustin L. Howett 2025-09-03 11:43:34 -05:00 committed by GitHub
parent 8011f3e28c
commit fa09141a16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 80 additions and 90 deletions

View File

@ -1419,7 +1419,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile());
VERIFY_IS_NULL(terminalArgs.Elevate()); VERIFY_IS_NULL(terminalArgs.Elevate());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(false, termSettings.Elevate()); VERIFY_ARE_EQUAL(false, termSettings.Elevate());
@ -1442,7 +1442,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile());
VERIFY_IS_NULL(terminalArgs.Elevate()); VERIFY_IS_NULL(terminalArgs.Elevate());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(true, termSettings.Elevate()); VERIFY_ARE_EQUAL(true, termSettings.Elevate());
@ -1465,7 +1465,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile());
VERIFY_IS_NULL(terminalArgs.Elevate()); VERIFY_IS_NULL(terminalArgs.Elevate());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(false, termSettings.Elevate()); VERIFY_ARE_EQUAL(false, termSettings.Elevate());
@ -1490,7 +1490,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); VERIFY_IS_FALSE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(false, termSettings.Elevate()); VERIFY_ARE_EQUAL(false, termSettings.Elevate());
@ -1514,7 +1514,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); VERIFY_IS_FALSE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(false, termSettings.Elevate()); VERIFY_ARE_EQUAL(false, termSettings.Elevate());
@ -1538,7 +1538,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); VERIFY_IS_FALSE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(false, termSettings.Elevate()); VERIFY_ARE_EQUAL(false, termSettings.Elevate());
@ -1563,7 +1563,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); VERIFY_IS_TRUE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(true, termSettings.Elevate()); VERIFY_ARE_EQUAL(true, termSettings.Elevate());
@ -1586,7 +1586,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); VERIFY_IS_TRUE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(true, termSettings.Elevate()); VERIFY_ARE_EQUAL(true, termSettings.Elevate());
@ -1610,7 +1610,7 @@ namespace TerminalAppLocalTests
VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); VERIFY_IS_NOT_NULL(terminalArgs.Elevate());
VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); VERIFY_IS_TRUE(terminalArgs.Elevate().Value());
const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs);
const auto termSettings = termSettingsResult.DefaultSettings(); const auto termSettings = termSettingsResult.DefaultSettings();
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
VERIFY_ARE_EQUAL(true, termSettings.Elevate()); VERIFY_ARE_EQUAL(true, termSettings.Elevate());

View File

@ -74,7 +74,7 @@ namespace winrt::TerminalApp::implementation
{ {
return S_FALSE; return S_FALSE;
} }
const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) }; const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs) };
// Try to handle auto-elevation // Try to handle auto-elevation
if (_maybeElevate(newTerminalArgs, settings, profile)) if (_maybeElevate(newTerminalArgs, settings, profile))

View File

@ -270,7 +270,7 @@ namespace winrt::TerminalApp::implementation
if (_settings == nullptr) if (_settings == nullptr)
{ {
// Create this only on the first time we load the settings. // Create this only on the first time we load the settings.
_terminalSettingsCache = std::make_shared<TerminalSettingsCache>(settings, *_bindings); _terminalSettingsCache = std::make_shared<TerminalSettingsCache>(settings);
} }
_settings = settings; _settings = settings;
@ -1597,7 +1597,7 @@ namespace winrt::TerminalApp::implementation
{ {
// TODO GH#5047 If we cache the NewTerminalArgs, we no longer need to do this. // TODO GH#5047 If we cache the NewTerminalArgs, we no longer need to do this.
profile = GetClosestProfileForDuplicationOfProfile(profile); profile = GetClosestProfileForDuplicationOfProfile(profile);
controlSettings = TerminalSettings::CreateWithProfile(_settings, profile, *_bindings); controlSettings = TerminalSettings::CreateWithProfile(_settings, profile);
// Replace the Starting directory with the CWD, if given // Replace the Starting directory with the CWD, if given
const auto workingDirectory = control.WorkingDirectory(); const auto workingDirectory = control.WorkingDirectory();
@ -3437,7 +3437,7 @@ namespace winrt::TerminalApp::implementation
// don't, then when we move the content to another thread, and it // don't, then when we move the content to another thread, and it
// tries to handle a key, it'll callback on the original page's // tries to handle a key, it'll callback on the original page's
// stack, inevitably resulting in a wrong_thread // stack, inevitably resulting in a wrong_thread
return _SetupControl(TermControl::NewControlByAttachingContent(content, *_bindings)); return _SetupControl(TermControl::NewControlByAttachingContent(content));
} }
return nullptr; return nullptr;
} }
@ -3457,6 +3457,8 @@ namespace winrt::TerminalApp::implementation
term.OwningHwnd(reinterpret_cast<uint64_t>(*_hostingHwnd)); term.OwningHwnd(reinterpret_cast<uint64_t>(*_hostingHwnd));
} }
term.KeyBindings(*_bindings);
_RegisterTerminalEvents(term); _RegisterTerminalEvents(term);
return term; return term;
} }
@ -3503,7 +3505,7 @@ namespace winrt::TerminalApp::implementation
{ {
// TODO GH#5047 If we cache the NewTerminalArgs, we no longer need to do this. // TODO GH#5047 If we cache the NewTerminalArgs, we no longer need to do this.
profile = GetClosestProfileForDuplicationOfProfile(profile); profile = GetClosestProfileForDuplicationOfProfile(profile);
controlSettings = TerminalSettings::CreateWithProfile(_settings, profile, *_bindings); controlSettings = TerminalSettings::CreateWithProfile(_settings, profile);
const auto workingDirectory = tabImpl->GetActiveTerminalControl().WorkingDirectory(); const auto workingDirectory = tabImpl->GetActiveTerminalControl().WorkingDirectory();
const auto validWorkingDirectory = !workingDirectory.empty(); const auto validWorkingDirectory = !workingDirectory.empty();
if (validWorkingDirectory) if (validWorkingDirectory)
@ -3515,7 +3517,7 @@ namespace winrt::TerminalApp::implementation
if (!profile) if (!profile)
{ {
profile = _settings.GetProfileForArgs(newTerminalArgs); profile = _settings.GetProfileForArgs(newTerminalArgs);
controlSettings = TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings); controlSettings = TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs);
} }
// Try to handle auto-elevation // Try to handle auto-elevation
@ -3774,7 +3776,7 @@ namespace winrt::TerminalApp::implementation
// updating terminal panes, so that we don't have to build a _new_ // updating terminal panes, so that we don't have to build a _new_
// TerminalSettings for every profile we update - we can just look them // TerminalSettings for every profile we update - we can just look them
// up the previous ones we built. // up the previous ones we built.
_terminalSettingsCache->Reset(_settings, *_bindings); _terminalSettingsCache->Reset(_settings);
for (const auto& tab : _tabs) for (const auto& tab : _tabs)
{ {

View File

@ -13,9 +13,9 @@ namespace winrt
namespace winrt::TerminalApp::implementation namespace winrt::TerminalApp::implementation
{ {
TerminalSettingsCache::TerminalSettingsCache(const MTSM::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings) TerminalSettingsCache::TerminalSettingsCache(const MTSM::CascadiaSettings& settings)
{ {
Reset(settings, bindings); Reset(settings);
} }
MTSM::TerminalSettingsCreateResult TerminalSettingsCache::TryLookup(const MTSM::Profile& profile) MTSM::TerminalSettingsCreateResult TerminalSettingsCache::TryLookup(const MTSM::Profile& profile)
@ -30,7 +30,7 @@ namespace winrt::TerminalApp::implementation
auto& pair{ found->second }; auto& pair{ found->second };
if (!pair.second) if (!pair.second)
{ {
pair.second = MTSM::TerminalSettings::CreateWithProfile(_settings, pair.first, _bindings); pair.second = MTSM::TerminalSettings::CreateWithProfile(_settings, pair.first);
} }
return pair.second; return pair.second;
} }
@ -38,10 +38,9 @@ namespace winrt::TerminalApp::implementation
return nullptr; return nullptr;
} }
void TerminalSettingsCache::Reset(const MTSM::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings) void TerminalSettingsCache::Reset(const MTSM::CascadiaSettings& settings)
{ {
_settings = settings; _settings = settings;
_bindings = bindings;
// Mapping by GUID isn't _excellent_ because the defaults profile doesn't have a stable GUID; however, // Mapping by GUID isn't _excellent_ because the defaults profile doesn't have a stable GUID; however,
// when we stabilize its guid this will become fully safe. // when we stabilize its guid this will become fully safe.

View File

@ -20,13 +20,12 @@ namespace winrt::TerminalApp::implementation
{ {
struct TerminalSettingsCache struct TerminalSettingsCache
{ {
TerminalSettingsCache(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings); TerminalSettingsCache(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult TryLookup(const Microsoft::Terminal::Settings::Model::Profile& profile); Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult TryLookup(const Microsoft::Terminal::Settings::Model::Profile& profile);
void Reset(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings); void Reset(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
private: private:
Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr }; Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr };
TerminalApp::AppKeyBindings _bindings{ nullptr };
std::unordered_map<winrt::guid, std::pair<Microsoft::Terminal::Settings::Model::Profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult>> profileGuidSettingsMap; std::unordered_map<winrt::guid, std::pair<Microsoft::Terminal::Settings::Model::Profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult>> profileGuidSettingsMap;
}; };
} }

View File

@ -613,7 +613,7 @@ namespace winrt::TerminalApp::implementation
if ((_appArgs && _appArgs->ParsedArgs().GetSize().has_value()) || (proposedSize.Width == 0 && proposedSize.Height == 0)) if ((_appArgs && _appArgs->ParsedArgs().GetSize().has_value()) || (proposedSize.Width == 0 && proposedSize.Height == 0))
{ {
// Use the default profile to determine how big of a window we need. // Use the default profile to determine how big of a window we need.
const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr, nullptr) }; const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr) };
const til::size emptySize{}; const til::size emptySize{};
const auto commandlineSize = _appArgs ? _appArgs->ParsedArgs().GetSize().value_or(emptySize) : til::size{}; const auto commandlineSize = _appArgs ? _appArgs->ParsedArgs().GetSize().value_or(emptySize) : til::size{};

View File

@ -265,9 +265,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
shared->updateScrollBar.reset(); shared->updateScrollBar.reset();
} }
void ControlCore::AttachToNewControl(const Microsoft::Terminal::Control::IKeyBindings& keyBindings) void ControlCore::AttachToNewControl()
{ {
_settings->KeyBindings(keyBindings);
_setupDispatcherAndCallbacks(); _setupDispatcherAndCallbacks();
const auto actualNewSize = _actualFont.GetSize(); const auto actualNewSize = _actualFont.GetSize();
// Bubble this up, so our new control knows how big we want the font. // Bubble this up, so our new control knows how big we want the font.

View File

@ -105,7 +105,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
::Microsoft::Console::Render::Renderer* GetRenderer() const noexcept; ::Microsoft::Console::Render::Renderer* GetRenderer() const noexcept;
uint64_t SwapChainHandle() const; uint64_t SwapChainHandle() const;
void AttachToNewControl(const Microsoft::Terminal::Control::IKeyBindings& keyBindings); void AttachToNewControl();
void SizeChanged(const float width, const float height); void SizeChanged(const float width, const float height);
void ScaleChanged(const float scale); void ScaleChanged(const float scale);

View File

@ -84,9 +84,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_core->Detach(); _core->Detach();
} }
void ControlInteractivity::AttachToNewControl(const Microsoft::Terminal::Control::IKeyBindings& keyBindings) void ControlInteractivity::AttachToNewControl()
{ {
_core->AttachToNewControl(keyBindings); _core->AttachToNewControl();
} }
// Method Description: // Method Description:

View File

@ -89,7 +89,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void SetEndSelectionPoint(const Core::Point pixelPosition); void SetEndSelectionPoint(const Core::Point pixelPosition);
uint64_t Id(); uint64_t Id();
void AttachToNewControl(const Microsoft::Terminal::Control::IKeyBindings& keyBindings); void AttachToNewControl();
til::typed_event<IInspectable, Control::OpenHyperlinkEventArgs> OpenHyperlink; til::typed_event<IInspectable, Control::OpenHyperlinkEventArgs> OpenHyperlink;
til::typed_event<IInspectable, Control::PasteFromClipboardEventArgs> PasteFromClipboard; til::typed_event<IInspectable, Control::PasteFromClipboardEventArgs> PasteFromClipboard;

View File

@ -25,7 +25,7 @@ namespace Microsoft.Terminal.Control
UInt64 Id { get; }; UInt64 Id { get; };
void AttachToNewControl(Microsoft.Terminal.Control.IKeyBindings keyBindings); void AttachToNewControl();
void Detach(); void Detach();
void Close(); void Close();

View File

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT license. // Licensed under the MIT license.
import "IKeyBindings.idl";
import "IControlAppearance.idl"; import "IControlAppearance.idl";
import "EventArgs.idl"; import "EventArgs.idl";
@ -53,8 +52,6 @@ namespace Microsoft.Terminal.Control
String CellWidth { get; }; String CellWidth { get; };
String CellHeight { get; }; String CellHeight { get; };
Microsoft.Terminal.Control.IKeyBindings KeyBindings { get; };
Boolean CopyOnSelect { get; }; Boolean CopyOnSelect { get; };
Microsoft.Terminal.Control.CopyFormat CopyFormatting { get; }; Microsoft.Terminal.Control.CopyFormat CopyFormatting { get; };
Boolean FocusFollowMouse { get; }; Boolean FocusFollowMouse { get; };

View File

@ -487,25 +487,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Function Description: // Function Description:
// - Static helper for building a new TermControl from an already existing // - Static helper for building a new TermControl from an already existing
// content. We'll attach the existing swapchain to this new control's // content. We'll attach the existing swapchain to this new control's
// SwapChainPanel. The IKeyBindings might belong to a non-agile object on // SwapChainPanel.
// a new thread, so we'll hook up the core to these new bindings.
// Arguments: // Arguments:
// - content: The preexisting ControlInteractivity to connect to. // - content: The preexisting ControlInteractivity to connect to.
// - keybindings: The new IKeyBindings instance to use for this control.
// Return Value: // Return Value:
// - The newly constructed TermControl. // - The newly constructed TermControl.
Control::TermControl TermControl::NewControlByAttachingContent(Control::ControlInteractivity content, Control::TermControl TermControl::NewControlByAttachingContent(Control::ControlInteractivity content)
const Microsoft::Terminal::Control::IKeyBindings& keyBindings)
{ {
const auto term{ winrt::make_self<TermControl>(content) }; const auto term{ winrt::make_self<TermControl>(content) };
term->_initializeForAttach(keyBindings); term->_initializeForAttach();
return *term; return *term;
} }
void TermControl::_initializeForAttach(const Microsoft::Terminal::Control::IKeyBindings& keyBindings) void TermControl::_initializeForAttach()
{ {
_AttachDxgiSwapChainToXaml(reinterpret_cast<HANDLE>(_core.SwapChainHandle())); _AttachDxgiSwapChainToXaml(reinterpret_cast<HANDLE>(_core.SwapChainHandle()));
_interactivity.AttachToNewControl(keyBindings); _interactivity.AttachToNewControl();
// Initialize the terminal only once the swapchainpanel is loaded - that // Initialize the terminal only once the swapchainpanel is loaded - that
// way, we'll be able to query the real pixel size it got on layout // way, we'll be able to query the real pixel size it got on layout
@ -1848,13 +1845,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return true; return true;
} }
auto bindings = _core.Settings().KeyBindings(); if (!_keyBindings)
if (!bindings)
{ {
return false; return false;
} }
auto success = bindings.TryKeyChord({ auto success = _keyBindings.TryKeyChord({
modifiers.IsCtrlPressed(), modifiers.IsCtrlPressed(),
modifiers.IsAltPressed(), modifiers.IsAltPressed(),
modifiers.IsShiftPressed(), modifiers.IsShiftPressed(),

View File

@ -50,12 +50,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
TermControl(IControlSettings settings, Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection); TermControl(IControlSettings settings, Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection);
static Control::TermControl NewControlByAttachingContent(Control::ControlInteractivity content, const Microsoft::Terminal::Control::IKeyBindings& keyBindings); static Control::TermControl NewControlByAttachingContent(Control::ControlInteractivity content);
void UpdateControlSettings(Control::IControlSettings settings); void UpdateControlSettings(Control::IControlSettings settings);
void UpdateControlSettings(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance); void UpdateControlSettings(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance);
IControlSettings Settings() const; IControlSettings Settings() const;
void KeyBindings(const Control::IKeyBindings& bindings) { _keyBindings = bindings; }
uint64_t ContentId() const; uint64_t ContentId() const;
hstring GetStartingTitle() const; hstring GetStartingTitle() const;
@ -249,6 +251,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Control::TermControlAutomationPeer _automationPeer{ nullptr }; Control::TermControlAutomationPeer _automationPeer{ nullptr };
Control::ControlInteractivity _interactivity{ nullptr }; Control::ControlInteractivity _interactivity{ nullptr };
Control::ControlCore _core{ nullptr }; Control::ControlCore _core{ nullptr };
Control::IKeyBindings _keyBindings{ nullptr };
TsfDataProvider _tsfDataProvider{ this }; TsfDataProvider _tsfDataProvider{ this };
winrt::com_ptr<SearchBoxControl> _searchBox; winrt::com_ptr<SearchBoxControl> _searchBox;
@ -340,7 +343,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _closing; return _closing;
} }
void _initializeForAttach(const Microsoft::Terminal::Control::IKeyBindings& keyBindings); void _initializeForAttach();
void _UpdateSettingsFromUIThread(); void _UpdateSettingsFromUIThread();
void _UpdateAppearanceFromUIThread(Control::IControlAppearance newAppearance); void _UpdateAppearanceFromUIThread(Control::IControlAppearance newAppearance);

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT license. // Licensed under the MIT license.
import "IKeyBindings.idl";
import "IMouseWheelListener.idl"; import "IMouseWheelListener.idl";
import "IControlSettings.idl"; import "IControlSettings.idl";
import "ControlInteractivity.idl"; import "ControlInteractivity.idl";
@ -36,7 +37,7 @@ namespace Microsoft.Terminal.Control
IControlAppearance unfocusedAppearance, IControlAppearance unfocusedAppearance,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection); Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
static TermControl NewControlByAttachingContent(ControlInteractivity content, Microsoft.Terminal.Control.IKeyBindings keyBindings); static TermControl NewControlByAttachingContent(ControlInteractivity content);
static Windows.Foundation.Size GetProposedDimensions(IControlSettings settings, static Windows.Foundation.Size GetProposedDimensions(IControlSettings settings,
UInt32 dpi, UInt32 dpi,
@ -52,6 +53,9 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.Control.IControlSettings Settings { get; }; Microsoft.Terminal.Control.IControlSettings Settings { get; };
// MIDL 3 does not support setter-only properties.
void KeyBindings(Microsoft.Terminal.Control.IKeyBindings KeyBindings);
event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged; event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, WriteToClipboardEventArgs> WriteToClipboard; event Windows.Foundation.TypedEventHandler<Object, WriteToClipboardEventArgs> WriteToClipboard;
event Windows.Foundation.TypedEventHandler<Object, PasteFromClipboardEventArgs> PasteFromClipboard; event Windows.Foundation.TypedEventHandler<Object, PasteFromClipboardEventArgs> PasteFromClipboard;

View File

@ -79,14 +79,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Arguments: // Arguments:
// - appSettings: the set of settings being used to construct the new terminal // - appSettings: the set of settings being used to construct the new terminal
// - profileGuid: the unique identifier (guid) of the profile // - profileGuid: the unique identifier (guid) of the profile
// - keybindings: the keybinding handler
// Return Value: // Return Value:
// - A TerminalSettingsCreateResult, which contains a pair of TerminalSettings objects, // - A TerminalSettingsCreateResult, which contains a pair of TerminalSettings objects,
// one for when the terminal is focused and the other for when the terminal is unfocused // one for when the terminal is focused and the other for when the terminal is unfocused
Model::TerminalSettingsCreateResult TerminalSettings::CreateWithProfile(const Model::CascadiaSettings& appSettings, const Model::Profile& profile, const IKeyBindings& keybindings) Model::TerminalSettingsCreateResult TerminalSettings::CreateWithProfile(const Model::CascadiaSettings& appSettings, const Model::Profile& profile)
{ {
const auto settings = _CreateWithProfileCommon(appSettings, profile); const auto settings = _CreateWithProfileCommon(appSettings, profile);
settings->_KeyBindings = keybindings;
Model::TerminalSettings child{ nullptr }; Model::TerminalSettings child{ nullptr };
if (const auto& unfocusedAppearance{ profile.UnfocusedAppearance() }) if (const auto& unfocusedAppearance{ profile.UnfocusedAppearance() })
@ -114,16 +112,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// * Additionally, we'll use other values (such as Commandline, // * Additionally, we'll use other values (such as Commandline,
// StartingDirectory) in this object to override the settings directly from // StartingDirectory) in this object to override the settings directly from
// the profile. // the profile.
// - keybindings: the keybinding handler
// Return Value: // Return Value:
// - A TerminalSettingsCreateResult object, which contains a pair of TerminalSettings // - A TerminalSettingsCreateResult object, which contains a pair of TerminalSettings
// objects. One for when the terminal is focused and one for when the terminal is unfocused. // objects. One for when the terminal is focused and one for when the terminal is unfocused.
Model::TerminalSettingsCreateResult TerminalSettings::CreateWithNewTerminalArgs(const CascadiaSettings& appSettings, Model::TerminalSettingsCreateResult TerminalSettings::CreateWithNewTerminalArgs(const CascadiaSettings& appSettings,
const NewTerminalArgs& newTerminalArgs, const NewTerminalArgs& newTerminalArgs)
const IKeyBindings& keybindings)
{ {
const auto profile = appSettings.GetProfileForArgs(newTerminalArgs); const auto profile = appSettings.GetProfileForArgs(newTerminalArgs);
auto settingsPair{ CreateWithProfile(appSettings, profile, keybindings) }; auto settingsPair{ CreateWithProfile(appSettings, profile) };
auto defaultSettings = settingsPair.DefaultSettings(); auto defaultSettings = settingsPair.DefaultSettings();
if (newTerminalArgs) if (newTerminalArgs)

View File

@ -59,12 +59,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static Model::TerminalSettings CreateForPreview(const Model::CascadiaSettings& appSettings, const Model::Profile& profile); static Model::TerminalSettings CreateForPreview(const Model::CascadiaSettings& appSettings, const Model::Profile& profile);
static Model::TerminalSettingsCreateResult CreateWithProfile(const Model::CascadiaSettings& appSettings, static Model::TerminalSettingsCreateResult CreateWithProfile(const Model::CascadiaSettings& appSettings,
const Model::Profile& profile, const Model::Profile& profile);
const Control::IKeyBindings& keybindings);
static Model::TerminalSettingsCreateResult CreateWithNewTerminalArgs(const Model::CascadiaSettings& appSettings, static Model::TerminalSettingsCreateResult CreateWithNewTerminalArgs(const Model::CascadiaSettings& appSettings,
const Model::NewTerminalArgs& newTerminalArgs, const Model::NewTerminalArgs& newTerminalArgs);
const Control::IKeyBindings& keybindings);
void ApplyColorScheme(const Model::ColorScheme& scheme); void ApplyColorScheme(const Model::ColorScheme& scheme);
@ -145,8 +143,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center); INHERITABLE_SETTING(Model::TerminalSettings, winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center);
INHERITABLE_SETTING(Model::TerminalSettings, winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center); INHERITABLE_SETTING(Model::TerminalSettings, winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center);
INHERITABLE_SETTING(Model::TerminalSettings, Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, Commandline); INHERITABLE_SETTING(Model::TerminalSettings, hstring, Commandline);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, StartingDirectory); INHERITABLE_SETTING(Model::TerminalSettings, hstring, StartingDirectory);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, StartingTitle); INHERITABLE_SETTING(Model::TerminalSettings, hstring, StartingTitle);

View File

@ -31,8 +31,8 @@ namespace Microsoft.Terminal.Settings.Model
Windows.Foundation.Collections.IMap<String COMMA String> EnvironmentVariables; Windows.Foundation.Collections.IMap<String COMMA String> EnvironmentVariables;
static TerminalSettings CreateForPreview(CascadiaSettings appSettings, Profile profile); static TerminalSettings CreateForPreview(CascadiaSettings appSettings, Profile profile);
static TerminalSettingsCreateResult CreateWithProfile(CascadiaSettings appSettings, Profile profile, Microsoft.Terminal.Control.IKeyBindings keybindings); static TerminalSettingsCreateResult CreateWithProfile(CascadiaSettings appSettings, Profile profile);
static TerminalSettingsCreateResult CreateWithNewTerminalArgs(CascadiaSettings appSettings, NewTerminalArgs newTerminalArgs, Microsoft.Terminal.Control.IKeyBindings keybindings); static TerminalSettingsCreateResult CreateWithNewTerminalArgs(CascadiaSettings appSettings, NewTerminalArgs newTerminalArgs);
void ApplyColorScheme(ColorScheme scheme); void ApplyColorScheme(ColorScheme scheme);

View File

@ -330,7 +330,7 @@ namespace SettingsModelUnitTests
VERIFY_IS_TRUE(terminalArgs.Profile().empty()); VERIFY_IS_TRUE(terminalArgs.Profile().empty());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(guid0, profile.Guid());
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
@ -354,7 +354,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(guid1, profile.Guid());
VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline());
@ -378,7 +378,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(guid1, profile.Guid());
VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline());
@ -402,7 +402,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid());
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
@ -426,7 +426,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline()); VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
// This action specified a command but no profile; it gets reassigned to the base profile // This action specified a command but no profile; it gets reassigned to the base profile
VERIFY_ARE_EQUAL(settings->ProfileDefaults(), profile); VERIFY_ARE_EQUAL(settings->ProfileDefaults(), profile);
@ -452,7 +452,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline()); VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(guid1, profile.Guid());
VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline());
@ -474,7 +474,7 @@ namespace SettingsModelUnitTests
VERIFY_IS_TRUE(terminalArgs.Profile().empty()); VERIFY_IS_TRUE(terminalArgs.Profile().empty());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(guid0, profile.Guid());
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
@ -497,7 +497,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"c:\\foo", terminalArgs.StartingDirectory()); VERIFY_ARE_EQUAL(L"c:\\foo", terminalArgs.StartingDirectory());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(guid0, profile.Guid());
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
@ -522,7 +522,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid());
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
@ -546,7 +546,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"bar", terminalArgs.TabTitle()); VERIFY_ARE_EQUAL(L"bar", terminalArgs.TabTitle());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(guid0, profile.Guid());
VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline());
@ -571,7 +571,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid());
VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline());
@ -598,7 +598,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile());
const auto profile{ settings->GetProfileForArgs(terminalArgs) }; const auto profile{ settings->GetProfileForArgs(terminalArgs) };
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs) };
const auto termSettings = settingsStruct.DefaultSettings(); const auto termSettings = settingsStruct.DefaultSettings();
VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(guid1, profile.Guid());
VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline());
@ -637,7 +637,7 @@ namespace SettingsModelUnitTests
try try
{ {
auto terminalSettings{ TerminalSettings::CreateWithProfile(*settings, profile1, nullptr) }; auto terminalSettings{ TerminalSettings::CreateWithProfile(*settings, profile1) };
VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings); VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings);
VERIFY_ARE_EQUAL(1, terminalSettings.DefaultSettings().HistorySize()); VERIFY_ARE_EQUAL(1, terminalSettings.DefaultSettings().HistorySize());
} }
@ -648,7 +648,7 @@ namespace SettingsModelUnitTests
try try
{ {
auto terminalSettings{ TerminalSettings::CreateWithProfile(*settings, profile2, nullptr) }; auto terminalSettings{ TerminalSettings::CreateWithProfile(*settings, profile2) };
VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings); VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings);
VERIFY_ARE_EQUAL(2, terminalSettings.DefaultSettings().HistorySize()); VERIFY_ARE_EQUAL(2, terminalSettings.DefaultSettings().HistorySize());
} }
@ -659,7 +659,7 @@ namespace SettingsModelUnitTests
try try
{ {
const auto termSettings{ TerminalSettings::CreateWithNewTerminalArgs(*settings, nullptr, nullptr) }; const auto termSettings{ TerminalSettings::CreateWithNewTerminalArgs(*settings, nullptr) };
VERIFY_ARE_NOT_EQUAL(nullptr, termSettings); VERIFY_ARE_NOT_EQUAL(nullptr, termSettings);
VERIFY_ARE_EQUAL(1, termSettings.DefaultSettings().HistorySize()); VERIFY_ARE_EQUAL(1, termSettings.DefaultSettings().HistorySize());
} }
@ -698,7 +698,7 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(settings->GlobalSettings().DefaultProfile(), settings->ActiveProfiles().GetAt(0).Guid()); VERIFY_ARE_EQUAL(settings->GlobalSettings().DefaultProfile(), settings->ActiveProfiles().GetAt(0).Guid());
try try
{ {
const auto termSettings{ TerminalSettings::CreateWithNewTerminalArgs(*settings, nullptr, nullptr) }; const auto termSettings{ TerminalSettings::CreateWithNewTerminalArgs(*settings, nullptr) };
VERIFY_ARE_NOT_EQUAL(nullptr, termSettings); VERIFY_ARE_NOT_EQUAL(nullptr, termSettings);
VERIFY_ARE_EQUAL(1, termSettings.DefaultSettings().HistorySize()); VERIFY_ARE_EQUAL(1, termSettings.DefaultSettings().HistorySize());
} }
@ -839,58 +839,58 @@ namespace SettingsModelUnitTests
{ // just a profile (profile wins) { // just a profile (profile wins)
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Profile(L"profile0"); args.Profile(L"profile0");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"profile0", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"profile0", settingsStruct.DefaultSettings().StartingTitle());
} }
{ // profile and command line -> no promotion (profile wins) { // profile and command line -> no promotion (profile wins)
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Profile(L"profile0"); args.Profile(L"profile0");
args.Commandline(L"foo.exe"); args.Commandline(L"foo.exe");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"profile0", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"profile0", settingsStruct.DefaultSettings().StartingTitle());
} }
{ // just a title -> it is propagated { // just a title -> it is propagated
NewTerminalArgs args{}; NewTerminalArgs args{};
args.TabTitle(L"Analog Kid"); args.TabTitle(L"Analog Kid");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"Analog Kid", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"Analog Kid", settingsStruct.DefaultSettings().StartingTitle());
} }
{ // title and command line -> no promotion { // title and command line -> no promotion
NewTerminalArgs args{}; NewTerminalArgs args{};
args.TabTitle(L"Digital Man"); args.TabTitle(L"Digital Man");
args.Commandline(L"foo.exe"); args.Commandline(L"foo.exe");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"Digital Man", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"Digital Man", settingsStruct.DefaultSettings().StartingTitle());
} }
{ // just a commandline -> promotion { // just a commandline -> promotion
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Commandline(L"foo.exe"); args.Commandline(L"foo.exe");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"foo.exe", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"foo.exe", settingsStruct.DefaultSettings().StartingTitle());
} }
// various typesof commandline follow // various typesof commandline follow
{ {
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Commandline(L"foo.exe bar"); args.Commandline(L"foo.exe bar");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"foo.exe", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"foo.exe", settingsStruct.DefaultSettings().StartingTitle());
} }
{ {
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Commandline(L"\"foo exe.exe\" bar"); args.Commandline(L"\"foo exe.exe\" bar");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"foo exe.exe", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"foo exe.exe", settingsStruct.DefaultSettings().StartingTitle());
} }
{ {
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Commandline(L"\"\" grand designs"); args.Commandline(L"\"\" grand designs");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings().StartingTitle());
} }
{ {
NewTerminalArgs args{}; NewTerminalArgs args{};
args.Commandline(L" imagine a man"); args.Commandline(L" imagine a man");
const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args, nullptr) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, args) };
VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings().StartingTitle()); VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings().StartingTitle());
} }
} }

View File

@ -72,7 +72,6 @@
X(bool, EnableColorGlyphs, true) \ X(bool, EnableColorGlyphs, true) \
X(winrt::hstring, CellWidth) \ X(winrt::hstring, CellWidth) \
X(winrt::hstring, CellHeight) \ X(winrt::hstring, CellHeight) \
X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \
X(winrt::hstring, Commandline) \ X(winrt::hstring, Commandline) \
X(winrt::hstring, StartingDirectory) \ X(winrt::hstring, StartingDirectory) \
X(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible) \ X(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible) \