@@ -393,12 +393,13 @@ class ShortcutMapProperty extends DiagnosticsProperty<Map<ShortcutActivator, Int
393
393
class SingleActivator with Diagnosticable , MenuSerializableShortcut implements ShortcutActivator {
394
394
/// Triggered when the [trigger] key is pressed while the modifiers are held.
395
395
///
396
- /// The ` trigger` should be the non-modifier key that is pressed after all the
396
+ /// The [ trigger] should be the non-modifier key that is pressed after all the
397
397
/// modifiers, such as [LogicalKeyboardKey.keyC] as in `Ctrl+C` . It must not be
398
398
/// a modifier key (sided or unsided).
399
399
///
400
- /// The `control` , `shift` , `alt` , and `meta` flags represent whether
401
- /// the respect modifier keys should be held (true) or released (false)
400
+ /// The [control] , [shift] , [alt] , and [meta] flags represent whether
401
+ /// the respect modifier keys should be held (true) or released (false).
402
+ /// They default to false.
402
403
///
403
404
/// By default, the activator is checked on all [RawKeyDownEvent] events for
404
405
/// the [trigger] key. If `includeRepeats` is false, only the [trigger] key
@@ -445,8 +446,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
445
446
/// Whether either (or both) control keys should be held for [trigger] to
446
447
/// activate the shortcut.
447
448
///
448
- /// If false, then all control keys must be released when the event is received
449
- /// in order to activate the shortcut.
449
+ /// It defaults to false, meaning all Control keys must be released when the
450
+ /// event is received in order to activate the shortcut. If it's true, then
451
+ /// either or both Control keys must be pressed.
450
452
///
451
453
/// See also:
452
454
///
@@ -456,8 +458,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
456
458
/// Whether either (or both) shift keys should be held for [trigger] to
457
459
/// activate the shortcut.
458
460
///
459
- /// If false, then all shift keys must be released when the event is received
460
- /// in order to activate the shortcut.
461
+ /// It defaults to false, meaning all Shift keys must be released when the
462
+ /// event is received in order to activate the shortcut. If it's true, then
463
+ /// either or both Shift keys must be pressed.
461
464
///
462
465
/// See also:
463
466
///
@@ -467,8 +470,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
467
470
/// Whether either (or both) alt keys should be held for [trigger] to
468
471
/// activate the shortcut.
469
472
///
470
- /// If false, then all alt keys must be released when the event is received
471
- /// in order to activate the shortcut.
473
+ /// It defaults to false, meaning all Alt keys must be released when the
474
+ /// event is received in order to activate the shortcut. If it's true, then
475
+ /// either or both Alt keys must be pressed.
472
476
///
473
477
/// See also:
474
478
///
@@ -478,8 +482,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
478
482
/// Whether either (or both) meta keys should be held for [trigger] to
479
483
/// activate the shortcut.
480
484
///
481
- /// If false, then all meta keys must be released when the event is received
482
- /// in order to activate the shortcut.
485
+ /// It defaults to false, meaning all Meta keys must be released when the
486
+ /// event is received in order to activate the shortcut. If it's true, then
487
+ /// either or both Meta keys must be pressed.
483
488
///
484
489
/// See also:
485
490
///
@@ -545,7 +550,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
545
550
@override
546
551
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
547
552
super .debugFillProperties (properties);
548
- properties.add (DiagnosticsProperty < String > ('keys' , debugDescribeKeys ()));
553
+ properties.add (MessageProperty ('keys' , debugDescribeKeys ()));
549
554
properties.add (FlagProperty ('includeRepeats' , value: includeRepeats, ifFalse: 'excluding repeats' ));
550
555
}
551
556
}
@@ -577,8 +582,54 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
577
582
/// * [SingleActivator] , an activator that represents a single key combined
578
583
/// with modifiers, such as `Ctrl+C`.
579
584
class CharacterActivator with Diagnosticable , MenuSerializableShortcut implements ShortcutActivator {
580
- /// Create a [CharacterActivator] from the triggering character.
581
- const CharacterActivator (this .character);
585
+ /// Triggered when the key event yields the given character.
586
+ ///
587
+ /// The [control] and [meta] flags represent whether the respect modifier
588
+ /// keys should be held (true) or released (false). They default to false.
589
+ /// [CharacterActivator] can not check Shift keys or Alt keys yet, and will
590
+ /// accept whether they are pressed or not.
591
+ ///
592
+ /// By default, the activator is checked on all [RawKeyDownEvent] events for
593
+ /// the [character] . If `includeRepeats` is false, only the [character]
594
+ /// events with a false [RawKeyDownEvent.repeat] attribute will be
595
+ /// considered.
596
+ const CharacterActivator (this .character, {
597
+ this .control = false ,
598
+ this .meta = false ,
599
+ this .includeRepeats = true ,
600
+ });
601
+
602
+ /// Whether either (or both) control keys should be held for the [character]
603
+ /// to activate the shortcut.
604
+ ///
605
+ /// It defaults to false, meaning all Control keys must be released when the
606
+ /// event is received in order to activate the shortcut. If it's true, then
607
+ /// either or both Control keys must be pressed.
608
+ ///
609
+ /// See also:
610
+ ///
611
+ /// * [LogicalKeyboardKey.controlLeft] , [LogicalKeyboardKey.controlRight] .
612
+ final bool control;
613
+
614
+ /// Whether either (or both) meta keys should be held for the [character] to
615
+ /// activate the shortcut.
616
+ ///
617
+ /// It defaults to false, meaning all Meta keys must be released when the
618
+ /// event is received in order to activate the shortcut. If it's true, then
619
+ /// either or both Meta keys must be pressed.
620
+ ///
621
+ /// See also:
622
+ ///
623
+ /// * [LogicalKeyboardKey.metaLeft] , [LogicalKeyboardKey.metaRight] .
624
+ final bool meta;
625
+
626
+ /// Whether this activator accepts repeat events of the [character] .
627
+ ///
628
+ /// If [includeRepeats] is true, the activator is checked on all
629
+ /// [RawKeyDownEvent] events for the [character] . If `includeRepeats` is
630
+ /// false, only the [character] events with a false [RawKeyDownEvent.repeat]
631
+ /// attribute will be considered.
632
+ final bool includeRepeats;
582
633
583
634
/// The character of the triggering event.
584
635
///
@@ -598,15 +649,24 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
598
649
599
650
@override
600
651
bool accepts (RawKeyEvent event, RawKeyboard state) {
652
+ final Set <LogicalKeyboardKey > pressed = state.keysPressed;
601
653
return event is RawKeyDownEvent
602
- && event.character == character;
654
+ && event.character == character
655
+ && (includeRepeats || ! event.repeat)
656
+ && (control == (pressed.contains (LogicalKeyboardKey .controlLeft) || pressed.contains (LogicalKeyboardKey .controlRight)))
657
+ && (meta == (pressed.contains (LogicalKeyboardKey .metaLeft) || pressed.contains (LogicalKeyboardKey .metaRight)));
603
658
}
604
659
605
660
@override
606
661
String debugDescribeKeys () {
607
662
String result = '' ;
608
663
assert (() {
609
- result = "'$character '" ;
664
+ final List <String > keys = < String > [
665
+ if (control) 'Control' ,
666
+ if (meta) 'Meta' ,
667
+ "'$character '" ,
668
+ ];
669
+ result = keys.join (' + ' );
610
670
return true ;
611
671
}());
612
672
return result;
@@ -620,7 +680,8 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
620
680
@override
621
681
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
622
682
super .debugFillProperties (properties);
623
- properties.add (StringProperty ('character' , character));
683
+ properties.add (MessageProperty ('character' , debugDescribeKeys ()));
684
+ properties.add (FlagProperty ('includeRepeats' , value: includeRepeats, ifFalse: 'excluding repeats' ));
624
685
}
625
686
}
626
687
0 commit comments