summaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-08 10:53:41 -0400
committerGitHub <noreply@github.com>2020-09-08 10:53:41 -0400
commit36fc5abae543840484b3d8f7abff85f57de66ada (patch)
treed8ce5b59ca26e8b91957989a775cb75a76c3d44a /ext/mixed
parent0a5e832dfddcc6184410e8836cc8dea030457486 (diff)
Modifier key refactor (#784)
* Add functions for getting keyboard key information * Use os + DocumentUtil to get modifier key names * Remove keyboard modifier info from environment info
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/document-util.js40
-rw-r--r--ext/mixed/js/environment.js61
2 files changed, 41 insertions, 60 deletions
diff --git a/ext/mixed/js/document-util.js b/ext/mixed/js/document-util.js
index ba39942d..0b72ff9a 100644
--- a/ext/mixed/js/document-util.js
+++ b/ext/mixed/js/document-util.js
@@ -259,6 +259,46 @@ class DocumentUtil {
return false;
}
+ static getModifierKeys(os) {
+ switch (os) {
+ case 'win':
+ return [
+ ['alt', 'Alt'],
+ ['ctrl', 'Ctrl'],
+ ['shift', 'Shift'],
+ ['meta', 'Windows']
+ ];
+ case 'mac':
+ return [
+ ['alt', 'Opt'],
+ ['ctrl', 'Ctrl'],
+ ['shift', 'Shift'],
+ ['meta', 'Cmd']
+ ];
+ case 'linux':
+ case 'openbsd':
+ case 'cros':
+ case 'android':
+ return [
+ ['alt', 'Alt'],
+ ['ctrl', 'Ctrl'],
+ ['shift', 'Shift'],
+ ['meta', 'Super']
+ ];
+ default: // 'unknown', etc
+ return [
+ ['alt', 'Alt'],
+ ['ctrl', 'Ctrl'],
+ ['shift', 'Shift'],
+ ['meta', 'Meta']
+ ];
+ }
+ }
+
+ static isMetaKeySupported(os, browser) {
+ return !(browser === 'firefox' || browser === 'firefox-mobile') || os === 'mac';
+ }
+
// Private
_setImposterStyle(style, propertyName, value) {
diff --git a/ext/mixed/js/environment.js b/ext/mixed/js/environment.js
index 1f4038d2..3ed9f5cf 100644
--- a/ext/mixed/js/environment.js
+++ b/ext/mixed/js/environment.js
@@ -33,11 +33,9 @@ class Environment {
async _loadEnvironmentInfo() {
const browser = await this._getBrowser();
const os = await this._getOperatingSystem();
- const modifierInfo = this._getModifierInfo(browser, os);
return {
browser,
- platform: {os},
- modifiers: modifierInfo
+ platform: {os}
};
}
@@ -91,61 +89,4 @@ class Environment {
return 'chrome';
}
}
-
- _getModifierInfo(browser, os) {
- let osKeys;
- let separator;
- switch (os) {
- case 'win':
- separator = ' + ';
- osKeys = [
- ['alt', 'Alt'],
- ['ctrl', 'Ctrl'],
- ['shift', 'Shift'],
- ['meta', 'Windows']
- ];
- break;
- case 'mac':
- separator = '';
- osKeys = [
- ['alt', '⌥'],
- ['ctrl', '⌃'],
- ['shift', '⇧'],
- ['meta', '⌘']
- ];
- break;
- case 'linux':
- case 'openbsd':
- case 'cros':
- case 'android':
- separator = ' + ';
- osKeys = [
- ['alt', 'Alt'],
- ['ctrl', 'Ctrl'],
- ['shift', 'Shift'],
- ['meta', 'Super']
- ];
- break;
- default: // 'unknown', etc
- separator = ' + ';
- osKeys = [
- ['alt', 'Alt'],
- ['ctrl', 'Ctrl'],
- ['shift', 'Shift'],
- ['meta', 'Meta']
- ];
- break;
- }
-
- const isFirefox = (browser === 'firefox' || browser === 'firefox-mobile');
- const keys = [];
-
- for (const [value, name] of osKeys) {
- // Firefox doesn't support event.metaKey on platforms other than macOS
- if (value === 'meta' && isFirefox && os !== 'mac') { continue; }
- keys.push({value, name});
- }
-
- return {keys, separator};
- }
}