Skip to content

Commit

Permalink
nits and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Jun 3, 2024
1 parent 253dedf commit 5a00d5f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,14 +950,14 @@ namespace winrt::TerminalApp::implementation
void CommandPalette::SetActionMap(const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap)
{
_actionMap = actionMap;
_setCommands();
_populateCommands();
}

void CommandPalette::_setCommands()
void CommandPalette::_populateCommands()
{
_allCommands.Clear();
if (_actionMap)
{
_allCommands.Clear();
const auto expandedCommands{ _actionMap.ExpandedCommands() };
for (const auto& action : expandedCommands)
{
Expand Down Expand Up @@ -1185,7 +1185,7 @@ namespace winrt::TerminalApp::implementation
{
const auto action = nameAndCommand.Value();
// nested commands cannot have keys bound to them, so just pass in the command and no keys
auto nestedActionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, L"") };
auto nestedActionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, winrt::hstring{}) };
auto nestedFilteredCommand{ winrt::make<FilteredCommand>(nestedActionPaletteItem) };
_currentNestedCommands.Append(nestedFilteredCommand);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace winrt::TerminalApp::implementation

bool _lastFilterTextWasEmpty{ true };

void _setCommands();
void _populateCommands();

void _filterTextChanged(const Windows::Foundation::IInspectable& sender,
const Windows::UI::Xaml::RoutedEventArgs& args);
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/SuggestionsControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ namespace winrt::TerminalApp::implementation
for (const auto& action : actions)
{
// key chords aren't relevant in the suggestions control, so make the palette item with just the command and no keys
auto actionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, L"") };
auto actionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, winrt::hstring{}) };
auto filteredCommand{ winrt::make<FilteredCommand>(actionPaletteItem) };
_allCommands.Append(filteredCommand);
}
Expand Down Expand Up @@ -911,7 +911,7 @@ namespace winrt::TerminalApp::implementation
for (const auto& nameAndCommand : parentCommand.NestedCommands())
{
const auto action = nameAndCommand.Value();
auto nestedActionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, L"") };
auto nestedActionPaletteItem{ winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(action, winrt::hstring{}) };
auto nestedFilteredCommand{ winrt::make<FilteredCommand>(nestedActionPaletteItem) };
_currentNestedCommands.Append(nestedFilteredCommand);
}
Expand Down
20 changes: 9 additions & 11 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
if (!_NameMapCache)
{
if (!_CumulativeActionMapCache)
if (_CumulativeActionMapCache.empty())
{
_RefreshKeyBindingCaches();
}
Expand Down Expand Up @@ -373,17 +373,17 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

void ActionMap::_RefreshKeyBindingCaches()
{
_CumulativeKeyMapCache.clear();
_CumulativeActionMapCache.clear();
std::unordered_map<KeyChord, Model::Command, KeyChordHash, KeyChordEquality> globalHotkeys;
std::unordered_map<KeyChord, winrt::hstring, KeyChordHash, KeyChordEquality> accumulatedKeybindingsMap;
std::unordered_map<winrt::hstring, Model::Command> accumulatedActionsMap;
std::unordered_map<KeyChord, Model::Command, KeyChordHash, KeyChordEquality> resolvedKeyActionMap;

_PopulateCumulativeKeyMap(accumulatedKeybindingsMap);
_PopulateCumulativeActionMap(accumulatedActionsMap);
_PopulateCumulativeKeyMap(_CumulativeKeyMapCache);
_PopulateCumulativeActionMap(_CumulativeActionMapCache);

for (const auto& [keys, cmdID] : accumulatedKeybindingsMap)
for (const auto& [keys, cmdID] : _CumulativeKeyMapCache)
{
if (const auto idCmdPair = accumulatedActionsMap.find(cmdID); idCmdPair != accumulatedActionsMap.end())
if (const auto idCmdPair = _CumulativeActionMapCache.find(cmdID); idCmdPair != _CumulativeActionMapCache.end())
{
resolvedKeyActionMap.emplace(keys, idCmdPair->second);

Expand All @@ -396,8 +396,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}

_CumulativeKeyMapCache = single_threaded_map(std::move(accumulatedKeybindingsMap));
_CumulativeActionMapCache = single_threaded_map(std::move(accumulatedActionsMap));
_ResolvedKeyActionMapCache = single_threaded_map(std::move(resolvedKeyActionMap));
_GlobalHotkeysCache = single_threaded_map(std::move(globalHotkeys));
}
Expand Down Expand Up @@ -451,10 +449,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}

// invalidate caches
_CumulativeKeyMapCache.clear();
_CumulativeActionMapCache.clear();
_NameMapCache = nullptr;
_GlobalHotkeysCache = nullptr;
_CumulativeKeyMapCache = nullptr;
_CumulativeActionMapCache = nullptr;
_ResolvedKeyActionMapCache = nullptr;

// Handle nested commands
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsModel/ActionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
std::unordered_map<winrt::hstring, Model::Command> _ActionMap;

// _CumulativeKeyMapCache is the map of key chords -> action IDs defined in all layers, with child layers overriding parent layers
Windows::Foundation::Collections::IMap<Control::KeyChord, winrt::hstring> _CumulativeKeyMapCache{ nullptr };
std::unordered_map<Control::KeyChord, winrt::hstring, KeyChordHash, KeyChordEquality> _CumulativeKeyMapCache;
// _CumulativeActionMapCache is the map of action IDs -> commands defined in all layers, with child layers overriding parent layers
Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command> _CumulativeActionMapCache{ nullptr };
std::unordered_map<winrt::hstring, Model::Command> _CumulativeActionMapCache;

// _ResolvedKeyActionMapCache is the map of key chords -> commands defined in all layers, with child layers overriding parent layers
// This is effectively a combination of _CumulativeKeyMapCache and _CumulativeActionMapCache and its purpose is so that
Expand Down

0 comments on commit 5a00d5f

Please sign in to comment.