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