修复hotkey

This commit is contained in:
陈思海 2025-08-11 16:01:34 +08:00
parent d8a4cc0993
commit 374ca27949

View File

@ -109,28 +109,23 @@ internal static class UXHotkeyComponent
{ {
if (_hotkeyRegistry.TryGetValue(actionId, out var registrations)) if (_hotkeyRegistry.TryGetValue(actionId, out var registrations))
{ {
HotkeyRegistration hotkeyInfo;
for (int i = registrations.Count - 1; i >= 0; i--) for (int i = registrations.Count - 1; i >= 0; i--)
{ {
if (registrations[i].button == button) if (registrations[i].button == button)
{ {
registrations.RemoveAt(i); hotkeyInfo = registrations[i];
break;
}
}
if (registrations.Count == 0)
{
_hotkeyRegistry.Remove(actionId);
if (_sharedHandlers.TryGetValue(actionId, out var handlerInfo)) if (_sharedHandlers.TryGetValue(actionId, out var handlerInfo))
{ {
var (handler, pressType) = handlerInfo; var (handler, pressType) = handlerInfo;
var actionRef = registrations.Count > 0 ? registrations[0].reference : null; var actionRef = hotkeyInfo.reference;
if (actionRef != null && actionRef.action != null) if (actionRef != null && actionRef.action != null)
{
if (registrations.Count == 0)
{ {
actionRef.action.Disable(); actionRef.action.Disable();
}
switch (pressType) switch (pressType)
{ {
@ -145,6 +140,11 @@ internal static class UXHotkeyComponent
_sharedHandlers.Remove(actionId); _sharedHandlers.Remove(actionId);
} }
registrations.RemoveAt(i);
_hotkeyRegistry.Remove(actionId);
break;
}
} }
} }
} }