Skip to content

Commit 4a90377

Browse files
committed
Fix TryMap of KeyMap.cs
1 parent 29e1978 commit 4a90377

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

Source/Lib/Common/Keymaps/Models/Keymap.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,41 @@ public bool TryRegister(KeymapArgs args, CommandNoType command)
4747
return true;
4848
}
4949

50-
public bool TryMap(KeymapArgs args, out CommandNoType command)
50+
public bool TryMap(KeymapArgs args, out CommandNoType? command)
5151
{
5252
lock (_syncRoot)
5353
{
54-
var keybind = new Keybind(args, command);
55-
54+
command = null;
5655
if (args.Key is not null)
5756
{
58-
if (!_mapKey.ContainsKey(args.Key))
59-
_mapKey.Add(args.Key, new());
60-
61-
_mapKey[args.Key].Add(keybind);
57+
if(_mapKey.TryGetValue(args.Key, out var keybindList))
58+
{
59+
foreach (var keybind in keybindList)
60+
{
61+
if (keybind.KeymapArgs == args)
62+
{
63+
command = keybind.CommandNoType;
64+
}
65+
}
66+
}
6267
}
6368

6469
if (args.Code is not null)
6570
{
66-
if (!_mapCode.ContainsKey(args.Code))
67-
_mapCode.Add(args.Code, new());
68-
69-
_mapCode[args.Code].Add(keybind);
71+
if(_mapCode.TryGetValue(args.Code, out var keybindList))
72+
{
73+
foreach (var keybind in keybindList)
74+
{
75+
if (keybind.KeymapArgs == args)
76+
{
77+
command = keybind.CommandNoType;
78+
}
79+
}
80+
}
7081
}
7182
}
7283

73-
return true;
84+
return command is not null;
7485
}
7586

7687
public (List<Keybind>? keyMatchList, List<Keybind>? codeMatchList) MapAll(KeymapArgs args)

0 commit comments

Comments
 (0)