Skip to content

Commit d4d216c

Browse files
don't need helper anymore
1 parent 7d00b25 commit d4d216c

File tree

2 files changed

+35
-55
lines changed

2 files changed

+35
-55
lines changed

src/cascadia/TerminalSettingsModel/ActionMap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
111111

112112
bool _fixUpsAppliedDuringLoad;
113113

114-
void _AddKeyBindingHelper(const Json::Value& json, std::vector<SettingsLoadWarnings>& warnings);
115-
116114
// _KeyMap is the map of key chords -> action IDs defined in this layer
117115
// _ActionMap is the map of action IDs -> commands defined in this layer
118116
// These maps are the ones that we deserialize into when parsing the user json and vice-versa

src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,52 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
5959
// and we can call Command::FromJson on it (Command::FromJson can handle parsing both legacy or modern)
6060

6161
// if there is no "command" field, then it is a modern style keys block
62-
if (jsonBlock.isMember(JsonKey(CommandsKey)) || jsonBlock.isMember(JsonKey(ActionKey)))
62+
63+
// if there are keys, extract them first
64+
Control::KeyChord keys{ nullptr };
65+
if (withKeybindings && jsonBlock.isMember(JsonKey(KeysKey)))
6366
{
64-
Control::KeyChord keys{ nullptr };
65-
if (withKeybindings && jsonBlock.isMember(JsonKey(KeysKey)))
67+
const auto keysJson{ jsonBlock[JsonKey(KeysKey)] };
68+
if (keysJson.isArray() && keysJson.size() > 1)
69+
{
70+
warnings.push_back(SettingsLoadWarnings::TooManyKeysForChord);
71+
}
72+
else
6673
{
67-
const auto keysJson{ json[JsonKey(KeysKey)] };
68-
if (keysJson.isArray() && keysJson.size() > 1)
69-
{
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
78-
_fixUpsAppliedDuringLoad = true;
79-
}
74+
JsonUtils::GetValueForKey(jsonBlock, KeysKey, keys);
8075
}
76+
}
8177

78+
// Now check if this is a command block
79+
if (jsonBlock.isMember(JsonKey(CommandsKey)) || jsonBlock.isMember(JsonKey(ActionKey)))
80+
{
8281
AddAction(*Command::FromJson(jsonBlock, warnings, origin), keys);
8382

84-
if (jsonBlock.isMember(JsonKey(ActionKey)) && !jsonBlock.isMember(JsonKey(IterateOnKey)))
83+
if (jsonBlock.isMember(JsonKey(KeysKey)))
8584
{
86-
if (origin == OriginTag::User && !jsonBlock.isMember(JsonKey(IDKey)))
87-
{
88-
// for non-nested non-iterable commands,
89-
// if there's no ID in the command block we will generate one for the user -
90-
// inform the loader that the ID needs to be written into the json
91-
_fixUpsAppliedDuringLoad = true;
92-
}
85+
// there are keys in this command block meaning this is the legacy style -
86+
// inform the loader that fixups are needed
87+
_fixUpsAppliedDuringLoad = true;
88+
}
89+
90+
if (jsonBlock.isMember(JsonKey(ActionKey)) && !jsonBlock.isMember(JsonKey(IterateOnKey)) && origin == OriginTag::User && !jsonBlock.isMember(JsonKey(IDKey)))
91+
{
92+
// for non-nested non-iterable commands,
93+
// if there's no ID in the command block we will generate one for the user -
94+
// inform the loader that the ID needs to be written into the json
95+
_fixUpsAppliedDuringLoad = true;
9396
}
9497
}
95-
else
98+
else if (keys)
9699
{
97100
// this is not a command block, so it is a keybinding block
98-
_AddKeyBindingHelper(jsonBlock, warnings);
101+
102+
// if the "id" field doesn't exist in the json, then idJson will be an empty string which is fine
103+
winrt::hstring idJson;
104+
JsonUtils::GetValueForKey(jsonBlock, IDKey, idJson);
105+
106+
// any existing keybinding with the same keychord in this layer will get overwritten
107+
_KeyMap.insert_or_assign(keys, idJson);
99108
}
100109
}
101110

@@ -151,31 +160,4 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
151160

152161
return keybindingsList;
153162
}
154-
155-
void ActionMap::_AddKeyBindingHelper(const Json::Value& json, std::vector<SettingsLoadWarnings>& warnings)
156-
{
157-
// There should always be a "keys" field
158-
// - If there is also an "id" field - we add the pair to our _KeyMap
159-
// - If there is no "id" field - this is an explicit unbinding, still add it to the _KeyMap,
160-
// when this key chord is queried for we will know it is an explicit unbinding
161-
const auto keysJson{ json[JsonKey(KeysKey)] };
162-
if (keysJson.isArray() && keysJson.size() > 1)
163-
{
164-
warnings.push_back(SettingsLoadWarnings::TooManyKeysForChord);
165-
}
166-
else
167-
{
168-
Control::KeyChord keys{ nullptr };
169-
winrt::hstring idJson;
170-
if (JsonUtils::GetValueForKey(json, KeysKey, keys))
171-
{
172-
// if the "id" field doesn't exist in the json, then idJson will be an empty string which is fine
173-
JsonUtils::GetValueForKey(json, IDKey, idJson);
174-
175-
// any existing keybinding with the same keychord in this layer will get overwritten
176-
_KeyMap.insert_or_assign(keys, idJson);
177-
}
178-
}
179-
return;
180-
}
181163
}

0 commit comments

Comments
 (0)