diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs index 4b8a2b49a9f7..5ff833749482 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelViewModel.cs @@ -152,7 +152,7 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property { GenerateId(); - UpdateAlias(); + FetchAliasFromAliasManager(); UpdateHotkey(); UpdateTags(); } @@ -163,24 +163,31 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property private void HandleChangeAlias() { - SetAlias(Alias); + SetAlias(); Save(); } - public void SetAlias(CommandAlias? newAlias) + public void SetAlias() { - _serviceProvider.GetService()!.UpdateAlias(Id, newAlias); - UpdateAlias(); + var commandAlias = Alias is null + ? null + : new CommandAlias(Alias.Alias, Alias.CommandId, Alias.IsDirect); + + _serviceProvider.GetService()!.UpdateAlias(Id, commandAlias); UpdateTags(); } - private void UpdateAlias() + private void FetchAliasFromAliasManager() { - // Add tags for the alias, if we have one. - var aliases = _serviceProvider.GetService(); - if (aliases != null) + var am = _serviceProvider.GetService(); + if (am != null) { - Alias = aliases.AliasFromId(Id); + var commandAlias = am.AliasFromId(Id); + if (commandAlias is not null) + { + // Decouple from the alias manager alias object + Alias = new CommandAlias(commandAlias.Alias, commandAlias.CommandId, commandAlias.IsDirect); + } } }