Delete the KeyChordViewModel if we leave edit mode with no keys (#19778)

There was an issue where if the user adds a new keybinding and then hits
"cancel changes", the KeyChordViewModel is left in the keybinding list
with an empty value. Nothing gets saved to the json, but visually there
was an empty keychord box left behind. This commit fixes that.

## Validation Steps Performed
Adding a new keybinding and cancelling changes deletes the keybinding.
This commit is contained in:
PankajBhojwani 2026-01-23 16:25:43 -08:00 committed by GitHub
parent c8549bebed
commit 6723ca2239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -220,7 +220,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
break; break;
} }
} }
actionsPageVM.DeleteKeyChord(args); if (args)
{
actionsPageVM.DeleteKeyChord(args);
}
} }
}); });
kcVM.PropertyChanged([weakThis{ get_weak() }](const IInspectable& sender, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args) { kcVM.PropertyChanged([weakThis{ get_weak() }](const IInspectable& sender, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args) {
@ -1032,6 +1035,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// if we're in edit mode, populate the text box with the current keys // if we're in edit mode, populate the text box with the current keys
ProposedKeys(_currentKeys); ProposedKeys(_currentKeys);
} }
else if (!_currentKeys)
{
// we have left edit mode but don't have any current keys - delete this view model
DeleteKeyChord();
}
} }
void KeyChordViewModel::AcceptChanges() void KeyChordViewModel::AcceptChanges()