Skip to content

Commit e6fdd15

Browse files
committed
feat(tpl): skip filename lookup when Alt key is down for non-Mac platform
On non-Mac platform, Alt key is generally used for other purpose in the browser, e.g. Alt+d is used to focus the address bar. On Mac platform, Alt key(actually the Option key) is used to input other kind of characters.
1 parent ffd6a98 commit e6fdd15

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/tpl/asset/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
var ARROW_RIGHT_CODE = 39;
246246

247247
var SKIP_TAGS = ['INPUT', 'BUTTON', 'TEXTAREA'];
248+
var IS_MAC_PLATFORM = navigator.platform.indexOf('Mac') >= 0;
248249

249250
var lookupKey = '';
250251
var lookupBuffer = '';
@@ -315,7 +316,7 @@
315316
}
316317
}
317318
}
318-
if (!e.ctrlKey && !e.metaKey && e.key.length === 1) {
319+
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.key.length === 1) {
319320
return lookup(e.key);
320321
}
321322
} else if (e.keyCode) {
@@ -347,7 +348,7 @@
347348
}
348349
}
349350
}
350-
if (!e.ctrlKey && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
351+
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
351352
return lookup(String.fromCharCode(e.keyCode));
352353
}
353354
}

src/tpl/asset/main.js.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ var ARROW_DOWN_CODE = 40;
222222
var ARROW_LEFT_CODE = 37;
223223
var ARROW_RIGHT_CODE = 39;
224224
var SKIP_TAGS = ['INPUT', 'BUTTON', 'TEXTAREA'];
225+
var IS_MAC_PLATFORM = navigator.platform.indexOf('Mac') >= 0;
225226
var lookupKey = '';
226227
var lookupBuffer = '';
227228
var lookupStartA = null;
@@ -286,7 +287,7 @@ return getFocusableSibling(itemList, false);
286287
}
287288
}
288289
}
289-
if (!e.ctrlKey && !e.metaKey && e.key.length === 1) {
290+
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.key.length === 1) {
290291
return lookup(e.key);
291292
}
292293
} else if (e.keyCode) {
@@ -318,7 +319,7 @@ return getFocusableSibling(itemList, false);
318319
}
319320
}
320321
}
321-
if (!e.ctrlKey && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
322+
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
322323
return lookup(String.fromCharCode(e.keyCode));
323324
}
324325
}

0 commit comments

Comments
 (0)