Improve how command key is handled

pull/502/head
Leo Liang 2 months ago
parent b0038773f3
commit a067370062
No known key found for this signature in database
GPG Key ID: 11D8CC52A029CC0B

@ -248,20 +248,19 @@ function dispatch(event, element) {
* Jest test cases are required. * Jest test cases are required.
* =============================== * ===============================
*/ */
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach((keyName) => { ['metaKey', 'ctrlKey', 'altKey', 'shiftKey'].forEach((keyName) => {
const keyNum = modifierMap[keyName]; const keyNum = modifierMap[keyName];
if (event[keyName] && _downKeys.indexOf(keyNum) === -1) { if (event[keyName] && _downKeys.indexOf(keyNum) === -1) {
_downKeys.push(keyNum); _downKeys.push(keyNum);
} else if (!event[keyName] && _downKeys.indexOf(keyNum) > -1) { } else if (!event[keyName] && _downKeys.indexOf(keyNum) > -1) {
_downKeys.splice(_downKeys.indexOf(keyNum), 1); _downKeys.splice(_downKeys.indexOf(keyNum), 1);
} else if (keyName === 'metaKey' && event[keyName] && _downKeys.length === 3) { } else if (keyName === 'metaKey' && event[keyName] && _downKeys.length === 3) {
/** // 如果command被按下那就清空所有除event按键外的非装饰键。
* Fix if Command is pressed: // 因为command被按下的情况下非装饰键的keyup永远都不会触发。这是已知的浏览器限制。
* =============================== // If command key is pressed, clear all non-decorating keys except for key in event.
*/ // This is because keyup for a non-decorating key will NEVER be triggered when command is pressed.
if (!(event.ctrlKey || event.shiftKey || event.altKey)) { // This is a known browser limitation.
_downKeys = _downKeys.slice(_downKeys.indexOf(keyNum)); _downKeys = _downKeys.filter((k) => k in modifierMap || k === key);
}
} }
}); });
/** /**

Loading…
Cancel
Save