@@ -59,43 +59,52 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
59
59
// and we can call Command::FromJson on it (Command::FromJson can handle parsing both legacy or modern)
60
60
61
61
// 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)))
63
66
{
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
66
73
{
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);
80
75
}
76
+ }
81
77
78
+ // Now check if this is a command block
79
+ if (jsonBlock.isMember (JsonKey (CommandsKey)) || jsonBlock.isMember (JsonKey (ActionKey)))
80
+ {
82
81
AddAction (*Command::FromJson (jsonBlock, warnings, origin), keys);
83
82
84
- if (jsonBlock.isMember (JsonKey (ActionKey)) && !jsonBlock. isMember ( JsonKey (IterateOnKey )))
83
+ if (jsonBlock.isMember (JsonKey (KeysKey )))
85
84
{
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 ;
93
96
}
94
97
}
95
- else
98
+ else if (keys)
96
99
{
97
100
// 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);
99
108
}
100
109
}
101
110
@@ -151,31 +160,4 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
151
160
152
161
return keybindingsList;
153
162
}
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
- }
181
163
}
0 commit comments