@@ -154,7 +154,7 @@ var menuBarShortcuts = ['mod+t', 'shift+mod+p', 'mod+n'] // shortcuts that are a
154
154
155
155
var shortcutsList = [ ]
156
156
157
- function defineShortcut ( keysOrKeyMapName , fn ) {
157
+ function defineShortcut ( keysOrKeyMapName , fn , options = { } ) {
158
158
if ( keysOrKeyMapName . keys ) {
159
159
var binding = keysOrKeyMapName . keys
160
160
} else {
@@ -193,11 +193,12 @@ function defineShortcut (keysOrKeyMapName, fn) {
193
193
shortcutsList . push ( {
194
194
combo : keys ,
195
195
keys : keys . split ( '+' ) ,
196
- fn : shortcutCallback
196
+ fn : shortcutCallback ,
197
+ keyUp : options . keyUp
197
198
} )
198
199
} )
199
200
200
- Mousetrap . bind ( binding , shortcutCallback )
201
+ Mousetrap . bind ( binding , shortcutCallback , ( options . keyUp ? "keyup" : null ) )
201
202
}
202
203
203
204
settings . get ( 'keyMap' , function ( keyMapSettings ) {
@@ -425,7 +426,7 @@ settings.get('keyMap', function (keyMapSettings) {
425
426
426
427
defineShortcut ( 'showAndHideMenuBar' , function ( ) {
427
428
menuBarVisibility . toggleMenuBar ( )
428
- } )
429
+ } , { keyUp : true } ) //run on keyUp to avoid interfering with alt+f4 shortcut, see https://github.com/minbrowser/min/issues/631
429
430
430
431
defineShortcut ( 'followLink' , function ( ) {
431
432
findinpage . end ( { action : 'activateSelection' } )
@@ -457,34 +458,35 @@ webviews.bindEvent('before-input-event', function (e, input) {
457
458
expectedKeys ++
458
459
}
459
460
460
- if ( input . type === 'keyDown' ) {
461
- shortcutsList . forEach ( function ( shortcut ) {
462
- var matches = true
463
- var matchedKeys = 0
464
- shortcut . keys . forEach ( function ( key ) {
465
- if ( ! (
466
- key === input . key . toLowerCase ( ) ||
467
- key === input . code . replace ( 'Digit' , '' ) ||
468
- ( key === 'left' && input . key === 'ArrowLeft' ) ||
469
- ( key === 'right' && input . key === 'ArrowRight' ) ||
470
- ( key === 'up' && input . key === 'ArrowUp' ) ||
471
- ( key === 'down' && input . key === 'ArrowDown' ) ||
472
- ( key === 'alt' && ( input . alt || input . key === "Alt" ) ) ||
473
- ( key === 'shift' && ( input . shift || input . key === "Shift" ) ) ||
474
- ( key === 'ctrl' && ( input . control || input . key === "Control" ) ) ||
475
- ( key === 'mod' && window . platformType === 'mac' && ( input . meta || input . key === "Meta" ) ) ||
476
- ( key === 'mod' && window . platformType !== 'mac' && ( input . control || input . key === "Control" ) )
477
- )
478
- ) {
479
- matches = false
480
- } else {
481
- matchedKeys ++
482
- }
483
- } )
484
-
485
- if ( matches && matchedKeys === expectedKeys ) {
486
- shortcut . fn ( null , shortcut . combo )
461
+ shortcutsList . forEach ( function ( shortcut ) {
462
+ if ( ( shortcut . keyUp && input . type !== "keyUp" ) || ( ! shortcut . keyUp && input . type !== "keyDown" ) ) {
463
+ return
464
+ }
465
+ var matches = true
466
+ var matchedKeys = 0
467
+ shortcut . keys . forEach ( function ( key ) {
468
+ if ( ! (
469
+ key === input . key . toLowerCase ( ) ||
470
+ key === input . code . replace ( 'Digit' , '' ) ||
471
+ ( key === 'left' && input . key === 'ArrowLeft' ) ||
472
+ ( key === 'right' && input . key === 'ArrowRight' ) ||
473
+ ( key === 'up' && input . key === 'ArrowUp' ) ||
474
+ ( key === 'down' && input . key === 'ArrowDown' ) ||
475
+ ( key === 'alt' && ( input . alt || input . key === "Alt" ) ) ||
476
+ ( key === 'shift' && ( input . shift || input . key === "Shift" ) ) ||
477
+ ( key === 'ctrl' && ( input . control || input . key === "Control" ) ) ||
478
+ ( key === 'mod' && window . platformType === 'mac' && ( input . meta || input . key === "Meta" ) ) ||
479
+ ( key === 'mod' && window . platformType !== 'mac' && ( input . control || input . key === "Control" ) )
480
+ )
481
+ ) {
482
+ matches = false
483
+ } else {
484
+ matchedKeys ++
487
485
}
488
486
} )
489
- }
487
+
488
+ if ( matches && matchedKeys === expectedKeys ) {
489
+ shortcut . fn ( null , shortcut . combo )
490
+ }
491
+ } )
490
492
} )
0 commit comments