Refactor KeyShortcutModifiers to remove unnecessary parameter and improve consistency

This commit is contained in:
mauro-balades 2024-09-29 20:18:32 +02:00
parent cc4f1a3eb2
commit f108074b81

View file

@ -116,14 +116,14 @@ class KeyShortcutModifiers {
#meta = false;
#accel = false;
constructor(ctrl, alt, shift, meta, accel, fromXHTML = false) {
constructor(ctrl, alt, shift, meta, accel) {
this.#control = ctrl;
this.#alt = alt;
this.#shift = shift;
this.#meta = meta;
this.#accel = accel;
if (AppConstants.platform != 'macosx' || !fromXHTML) {
if (AppConstants.platform != 'macosx') {
// Replace control with accel, to make it more consistent
this.#accel = ctrl || accel;
this.#control = false;
@ -154,8 +154,7 @@ class KeyShortcutModifiers {
modifiers.includes('alt'),
modifiers.includes('shift'),
modifiers.includes('meta'),
modifiers.includes('accel'),
true
modifiers.includes('accel')
);
}
@ -166,7 +165,7 @@ class KeyShortcutModifiers {
toUserString() {
let str = '';
if (this.#control && !this.#accel) {
if (this.#control || this.#accel) {
str += 'Ctrl+';
}
if (this.#alt) {
@ -178,13 +177,6 @@ class KeyShortcutModifiers {
if (this.#meta) {
str += AppConstants.platform == 'macosx' ? 'Cmd+' : 'Win+';
}
if (this.#accel) {
if (AppConstants.platform == 'macosx') {
str += 'Meta+';
} else {
str += 'Ctrl+';
}
}
return str;
}