Skip to content

Commit 5e48a45

Browse files
update add action
1 parent 14d83b5 commit 5e48a45

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/cascadia/TerminalSettingsModel/ActionMap.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
449449
// - Adds a command to the ActionMap
450450
// Arguments:
451451
// - cmd: the command we're adding
452-
void ActionMap::AddAction(const Model::Command& cmd)
452+
void ActionMap::AddAction(const Model::Command& cmd, const Control::KeyChord& keys)
453453
{
454454
// _Never_ add null to the ActionMap
455455
if (!cmd)
@@ -489,7 +489,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
489489
// Add the new keybinding to the _KeyMap
490490

491491
_TryUpdateActionMap(cmd);
492-
_TryUpdateKeyChord(cmd);
492+
_TryUpdateKeyChord(cmd, keys);
493493
}
494494

495495
// Method Description:
@@ -548,12 +548,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
548548
// - Update our internal state with the key chord of the newly registered action
549549
// Arguments:
550550
// - cmd: the action we're trying to register
551-
void ActionMap::_TryUpdateKeyChord(const Model::Command& cmd)
551+
void ActionMap::_TryUpdateKeyChord(const Model::Command& cmd, const Control::KeyChord& keys)
552552
{
553553
// Example (this is a legacy case, where the keys are provided in the same block as the command):
554554
// { "command": "copy", "keys": "ctrl+c" } --> we are registering a new key chord
555555
// { "name": "foo", "command": "copy" } --> no change to keys, exit early
556-
const auto keys{ cmd.Keys() };
557556
if (!keys)
558557
{
559558
// the user is not trying to update the keys.
@@ -773,7 +772,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
773772
cmd->RegisterKey(keys);
774773
cmd->ActionAndArgs(action);
775774
cmd->GenerateID();
776-
AddAction(*cmd);
775+
AddAction(*cmd, keys);
777776
}
778777

779778
// This is a helper to aid in sorting commands by their `Name`s, alphabetically.

src/cascadia/TerminalSettingsModel/ActionMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
6464
Control::KeyChord GetKeyBindingForAction(winrt::hstring cmdID) const;
6565

6666
// population
67-
void AddAction(const Model::Command& cmd);
67+
void AddAction(const Model::Command& cmd, const Control::KeyChord& keys);
6868

6969
// JSON
7070
static com_ptr<ActionMap> FromJson(const Json::Value& json, const OriginTag origin = OriginTag::None);
@@ -98,7 +98,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
9898
void _PopulateCumulativeActionMap(std::unordered_map<hstring, Model::Command>& actionMap);
9999

100100
void _TryUpdateActionMap(const Model::Command& cmd);
101-
void _TryUpdateKeyChord(const Model::Command& cmd);
101+
void _TryUpdateKeyChord(const Model::Command& cmd, const Control::KeyChord& keys);
102102

103103
Windows::Foundation::Collections::IMap<hstring, Model::ActionAndArgs> _AvailableActionsCache{ nullptr };
104104
Windows::Foundation::Collections::IMap<hstring, Model::Command> _NameMapCache{ nullptr };

src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,32 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
6161
// if there is no "command" field, then it is a modern style keys block
6262
if (jsonBlock.isMember(JsonKey(CommandsKey)) || jsonBlock.isMember(JsonKey(ActionKey)))
6363
{
64-
AddAction(*Command::FromJson(jsonBlock, warnings, origin, withKeybindings));
65-
66-
// for non-nested non-iterable commands,
67-
// check if this is a legacy-style command block so we can inform the loader that fixups are needed
68-
if (jsonBlock.isMember(JsonKey(ActionKey)) && !jsonBlock.isMember(JsonKey(IterateOnKey)))
64+
Control::KeyChord keys{ nullptr };
65+
if (jsonBlock.isMember(JsonKey(KeysKey)))
6966
{
70-
if (jsonBlock.isMember(JsonKey(KeysKey)))
67+
const auto keysJson{ json[JsonKey(KeysKey)] };
68+
if (keysJson.isArray() && keysJson.size() > 1)
7169
{
72-
// there are keys in this command block - its the legacy style
70+
warnings.push_back(SettingsLoadWarnings::TooManyKeysForChord);
71+
}
72+
else
73+
{
74+
JsonUtils::GetValueForKey(json, KeysKey, keys);
75+
76+
// there are keys in this command block meaning this is the legacy style -
77+
// inform the loader that fixups are needed
7378
_fixUpsAppliedDuringLoad = true;
7479
}
80+
}
81+
82+
AddAction(*Command::FromJson(jsonBlock, warnings, origin, withKeybindings), keys);
7583

84+
if (jsonBlock.isMember(JsonKey(ActionKey)) && !jsonBlock.isMember(JsonKey(IterateOnKey)))
85+
{
7686
if (origin == OriginTag::User && !jsonBlock.isMember(JsonKey(IDKey)))
7787
{
78-
// there's no ID in this command block - we will generate one for the user
88+
// for non-nested non-iterable commands,
89+
// if there's no ID in the command block we will generate one for the user -
7990
// inform the loader that the ID needs to be written into the json
8091
_fixUpsAppliedDuringLoad = true;
8192
}

0 commit comments

Comments
 (0)