@@ -23,104 +23,20 @@ @interface UIEvent (UIPhysicalKeyboardEvent)
2323
2424@end
2525
26- #if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
27-
28- @interface FLEXKeyInput : UIKeyCommand @end
29-
30- @interface UIKeyCommand (FLEX )
31-
32- @property (nonatomic , assign , readonly ) BOOL isCreatedByFLEX;
33-
34- #else
35-
3626@interface FLEXKeyInput : NSObject <NSCopying >
3727
38- #endif
39-
4028@property (nonatomic , copy , readonly ) NSString *key;
4129@property (nonatomic , readonly ) UIKeyModifierFlags flags;
4230@property (nonatomic , copy , readonly ) NSString *helpDescription;
4331
4432@end
4533
46- #if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
47-
48- @implementation FLEXKeyInput @end
49-
50- @implementation UIKeyCommand (FLEX )
51-
52- - (NSString *)key {
53-
54- return objc_getAssociatedObject (self, @selector (key ));
55- }
56-
57- - (void )setKey : (NSString *)key {
58-
59- objc_setAssociatedObject (self, @selector (key ), key, OBJC_ASSOCIATION_COPY_NONATOMIC );
60- }
61-
62- - (UIKeyModifierFlags)flags {
63-
64- UIKeyModifierFlags (^block)() = objc_getAssociatedObject (self, @selector (flags ));
65-
66- return (block ? block () : kNilOptions );
67- }
68-
69- - (void )setFlags : (UIKeyModifierFlags)flags {
70-
71- UIKeyModifierFlags (^block)() = ^{
72- return flags;
73- };
74-
75- objc_setAssociatedObject (self, @selector (flags ), block, OBJC_ASSOCIATION_COPY );
76- }
77-
78- - (NSString *)helpDescription {
79-
80- return objc_getAssociatedObject (self, @selector (helpDescription ));
81- }
82-
83- - (void )setHelpDescription : (NSString *)helpDescription {
84-
85- objc_setAssociatedObject (self, @selector (helpDescription ), helpDescription, OBJC_ASSOCIATION_COPY_NONATOMIC );
86- }
87-
88- - (BOOL )isCreatedByFLEX {
89-
90- BOOL (^block)() = objc_getAssociatedObject (self, @selector (isCreatedByFLEX ));
91-
92- return (block ? block () : NO );
93- }
94-
95- - (void )setIsCreatedByFLEX : (BOOL )isCreatedByFLEX {
96-
97- BOOL (^block)() = ^{
98- return isCreatedByFLEX;
99- };
100-
101- objc_setAssociatedObject (self, @selector (isCreatedByFLEX ), block, OBJC_ASSOCIATION_COPY );
102- }
103-
104- #else
105-
10634@implementation FLEXKeyInput
10735
108- #endif
109-
11036- (BOOL )isEqual : (id )object {
11137 BOOL isEqual = NO ;
112- #if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
113- if ([object isKindOfClass: [UIKeyCommand class ]]) {
114- UIKeyCommand *keyCommand = (UIKeyCommand *)object;
115- if (!keyCommand.isCreatedByFLEX ) {
116- // Not FLEX's business anymore.
117-
118- return [super isEqual: object];
119- }
120- #else
12138 if ([object isKindOfClass: [FLEXKeyInput class ]]) {
12239 FLEXKeyInput *keyCommand = (FLEXKeyInput *)object;
123- #endif
12440 BOOL equalKeys = self.key == keyCommand.key || [self .key isEqual: keyCommand.key];
12541 BOOL equalFlags = self.flags == keyCommand.flags ;
12642 isEqual = equalKeys && equalFlags;
@@ -179,24 +95,6 @@ + (instancetype)keyInputForKey:(NSString *)key flags:(UIKeyModifierFlags)flags {
17995 return [self keyInputForKey: key flags: flags helpDescription: nil ];
18096}
18197
182- #if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
183-
184- + (instancetype )keyInputForKey:(NSString *)key
185- flags:(UIKeyModifierFlags)flags
186- helpDescription:(NSString *)helpDescription {
187- FLEXKeyInput *keyInput = [UIKeyCommand keyCommandWithInput: key modifierFlags: flags action: nil ];
188- if (keyInput) {
189- [keyInput setKey: key];
190- [keyInput setFlags: flags];
191- [keyInput setHelpDescription: helpDescription];
192-
193- [keyInput setIsCreatedByFLEX: YES ];
194- }
195- return keyInput;
196- }
197-
198- #else
199-
20098+ (instancetype )keyInputForKey : (NSString *)key
20199 flags : (UIKeyModifierFlags)flags
202100 helpDescription : (NSString *)helpDescription {
@@ -209,17 +107,11 @@ + (instancetype)keyInputForKey:(NSString *)key
209107 return keyInput;
210108}
211109
212- #endif
213-
214110@end
215111
216112@interface FLEXKeyboardShortcutManager ()
217113
218- #if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
219- @property (nonatomic , strong ) NSMutableDictionary <UIKeyCommand *, dispatch_block_t> *actionsForKeyInputs;
220- #else
221114@property (nonatomic ) NSMutableDictionary <FLEXKeyInput *, dispatch_block_t> *actionsForKeyInputs;
222- #endif
223115
224116@property (nonatomic , getter =isPressingShift) BOOL pressingShift;
225117@property (nonatomic , getter =isPressingCommand) BOOL pressingCommand;
@@ -432,7 +324,9 @@ - (NSString *)keyboardShortcutsDescription {
432324#if TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
433325
434326- (NSArray <UIKeyCommand *> *)getKeyCommands {
435- return self.actionsForKeyInputs .allKeys ;
327+ return [self .actionsForKeyInputs.allKeys flex_mapped: ^UIKeyCommand *(FLEXKeyInput *keyInput, NSUInteger index) {
328+ return [UIKeyCommand keyCommandWithInput: keyInput.key modifierFlags: keyInput.flags action: nil ];
329+ }];
436330}
437331
438332#endif
0 commit comments