@@ -10,71 +10,10 @@ namespace Terminal.Gui;
10
10
public class KeyBindings : Bindings < Key , KeyBinding >
11
11
{
12
12
/// <summary>Initializes a new instance bound to <paramref name="target"/>.</summary>
13
- public KeyBindings ( View ? target ) : base ( ( commands , key ) => new KeyBinding ( commands ) ) { Target = target ; }
13
+ public KeyBindings ( View ? target ) : base (
14
+ ( commands , key ) => new KeyBinding ( commands ) ,
15
+ new KeyEqualityComparer ( ) ) { Target = target ; }
14
16
15
- /// <summary>Adds a <see cref="KeyBinding"/> to the collection.</summary>
16
- /// <param name="key"></param>
17
- /// <param name="binding"></param>
18
- /// <exception cref="ArgumentException">If <paramref name="binding"/> has no Commands or <paramref name="key"/> is invalid.</exception>
19
- public void Add ( Key key , KeyBinding binding )
20
- {
21
-
22
- if ( ! key . IsValid )
23
- {
24
- throw new ArgumentException ( nameof ( key ) ) ;
25
- }
26
-
27
- if ( binding . Commands is { Length : 0 } )
28
- {
29
- throw new ArgumentException ( nameof ( binding ) ) ;
30
- }
31
-
32
- if ( TryGet ( key , out KeyBinding _ ) )
33
- {
34
- throw new InvalidOperationException ( @$ "A key binding for { key } exists ({ binding } ).") ;
35
-
36
- //Bindings [key] = binding;
37
- }
38
-
39
- if ( Target is { } )
40
- {
41
- binding . Target = Target ;
42
- }
43
-
44
- // IMPORTANT: Add a COPY of the key. This is needed because ConfigurationManager.Apply uses DeepMemberWiseCopy
45
- // IMPORTANT: update the memory referenced by the key, and Dictionary uses caching for performance, and thus
46
- // IMPORTANT: Apply will update the Dictionary with the new key, but the old key will still be in the dictionary.
47
- // IMPORTANT: See the ConfigurationManager.Illustrate_DeepMemberWiseCopy_Breaks_Dictionary test for details.
48
- _bindings . Add ( new ( key ) , binding ) ;
49
- }
50
-
51
- #pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
52
- /// <summary>
53
- /// <para>
54
- /// Adds a new key combination that will trigger the commands in <paramref name="commands"/> (if supported by the
55
- /// View - see <see cref="View.GetSupportedCommands"/>).
56
- /// </para>
57
- /// <para>
58
- /// If the key is already bound to a different array of <see cref="Command"/>s it will be rebound
59
- /// <paramref name="commands"/>.
60
- /// </para>
61
- /// </summary>
62
- /// <remarks>
63
- /// Commands are only ever applied to the current <see cref="View"/> (i.e. this feature cannot be used to switch
64
- /// focus to another view and perform multiple commands there).
65
- /// </remarks>
66
- /// <param name="key">The key to check.</param>
67
- /// <param name="commands">
68
- /// The command to invoked on the <see cref="View"/> when <paramref name="key"/> is pressed. When
69
- /// multiple commands are provided,they will be applied in sequence. The bound <paramref name="key"/> strike will be
70
- /// consumed if any took effect.
71
- /// </param>
72
- /// <exception cref="ArgumentException">If <paramref name="commands"/> is empty.</exception>
73
- #pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
74
- public void Add ( Key key , params Command [ ] commands )
75
- {
76
- Add ( key , new KeyBinding ( commands ) ) ;
77
- }
78
17
79
18
80
19
/// <summary>
@@ -102,8 +41,6 @@ public void Add (Key key, View? target, params Command [] commands)
102
41
Add ( key , binding ) ;
103
42
}
104
43
105
- private readonly Dictionary < Key , KeyBinding > _bindings = new ( new KeyEqualityComparer ( ) ) ;
106
-
107
44
/// <summary>
108
45
/// Gets the bindings.
109
46
/// </summary>
0 commit comments