Skip to content

Commit

Permalink
handle and test nested and unbound commands
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed May 5, 2021
1 parent c434ee6 commit 586b977
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
41 changes: 39 additions & 2 deletions src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ namespace SettingsModelLocalTests
const std::string actionsString2A{ R"([
{ "command": { "action": "setTabColor" } }
])" };

const std::string actionsString2B{ R"([
{ "command": { "action": "setTabColor", "color": "#112233" } }
])" };

const std::string actionsString2C{ R"([
{ "command": { "action": "copy" } },
{ "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" } }
Expand All @@ -262,10 +260,40 @@ namespace SettingsModelLocalTests
const std::string actionsString6{ R"([
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+g" },
])" };

const std::string actionsString7{ R"([
{ "command": { "action": "renameWindow", "name": null }, "keys": "ctrl+h" }
])" };

const std::string actionsString8{ R"([
{
"name": "Change font size...",
"commands": [
{ "command": { "action": "adjustFontSize", "delta": 1 } },
{ "command": { "action": "adjustFontSize", "delta": -1 } },
{ "command": "resetFontSize" },
]
}
])" };

const std::string actionsString9{ R"([
{
"name": "New tab",
"commands": [
{
"iterateOn": "profiles",
"icon": "${profile.icon}",
"name": "${profile.name}",
"command": { "action": "newTab", "profile": "${profile.name}" }
}
]
}
])" };

const std::string actionsString10{ R"([
{ "command": "unbound", "keys": "ctrl+c" }
])" };

Log::Comment(L"simple command");
RoundtripTest<implementation::ActionMap>(actionsString1);

Expand All @@ -288,6 +316,15 @@ namespace SettingsModelLocalTests

Log::Comment(L"complex command with meaningful null arg");
RoundtripTest<implementation::ActionMap>(actionsString7);

Log::Comment(L"nested command");
RoundtripTest<implementation::ActionMap>(actionsString8);

Log::Comment(L"iterable command");
RoundtripTest<implementation::ActionMap>(actionsString9);

Log::Comment(L"unbound command");
RoundtripTest<implementation::ActionMap>(actionsString10);
}

void SerializationTests::CascadiaSettings()
Expand Down
8 changes: 3 additions & 5 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::NewWindow, NewWindowArgs::ToJson },
{ ShortcutAction::PrevTab, PrevTabArgs::ToJson },
{ ShortcutAction::NextTab, NextTabArgs::ToJson },
{ ShortcutAction::RenameWindow, RenameWindowArgs::ToJson },

{ ShortcutAction::Invalid, nullptr },
{ ShortcutAction::RenameWindow, RenameWindowArgs::ToJson }
};

// Function Description:
Expand Down Expand Up @@ -301,8 +299,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}

// "command": null
return { Json::ValueType::nullValue };
// "command": "unbound"
return JsonKey(UnboundKey);
}

com_ptr<ActionAndArgs> ActionAndArgs::Copy() const
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
actionList.append(cmdJson);
}
}
for (const auto& [_, cmd] : _NestedCommands)
{
const auto cmdImpl{ winrt::get_self<implementation::Command>(cmd) };
const auto& cmdJsonArray{ cmdImpl->ToJson() };
for (const auto& cmdJson : cmdJsonArray)
{
actionList.append(cmdJson);
}
}
return actionList;
}

Expand Down
10 changes: 9 additions & 1 deletion src/cascadia/TerminalSettingsModel/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
Json::Value cmdList{ Json::ValueType::arrayValue };

if (_keyMappings.empty())
if (_nestedCommand)
{
// handle nested command
// For nested commands, we can trust _originalJson to be correct.
// In fact, we _need_ to use it here because we don't actually deserialize `iterateOn`
// until we expand the command.
cmdList.append(_originalJson);
}
else if (_keyMappings.empty())
{
// only write out one command
Json::Value cmdJson{ Json::ValueType::objectValue };
Expand Down

0 comments on commit 586b977

Please sign in to comment.