CmdPal: Ensuring alias changes are propagated to related TopLevelViewModels (#40970)

Closes #39709

- Only updating aliases when the alias has changed
- When an alias is used that is already in use, remove the alias from
the previous TopLevelViewModel
- Don't crash if the previous TopLevelViewModel doesn't exist (e.g. it
was uninstalled)
This commit is contained in:
Michael Jolley
2025-08-21 06:09:00 -05:00
committed by GitHub
parent da572c6c40
commit 56aa9acfb4
2 changed files with 23 additions and 4 deletions

View File

@@ -97,14 +97,27 @@ public partial class AliasManager : ObservableObject
}
}
// Look for the old alias, and remove it
List<CommandAlias> toRemove = [];
foreach (var kv in _aliases)
{
// Look for the old aliases for the command, and remove it
if (kv.Value.CommandId == commandId)
{
toRemove.Add(kv.Value);
}
// Look for the alias belonging to another command, and remove it
if (newAlias is not null && kv.Value.Alias == newAlias.Alias)
{
toRemove.Add(kv.Value);
// Remove alias from other TopLevelViewModels it may be assigned to
var topLevelCommand = _topLevelCommandManager.LookupCommand(kv.Value.CommandId);
if (topLevelCommand is not null)
{
topLevelCommand.AliasText = string.Empty;
}
}
}
foreach (var alias in toRemove)