mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2026-07-24 00:37:20 +08:00
[common] Sort display keys
This commit is contained in:
@ -233,6 +233,10 @@
|
||||
shortcuts[foundIndex].ascShortcut = copyAscShortcut;
|
||||
}
|
||||
}
|
||||
|
||||
if(actionsMap[actionType]) {
|
||||
actionsMap[actionType].shortcuts = shortcuts.sort(_sortComparator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -294,6 +298,40 @@
|
||||
return keys;
|
||||
};
|
||||
|
||||
var _sortComparator = function(first, second) {
|
||||
const priorityModifierKeys = ['asc_IsCommand', 'asc_IsCtrl', 'asc_IsAlt', 'asc_IsShift'];
|
||||
function getWeight(ascShortcut) {
|
||||
// Search for the first modifier key
|
||||
let keyIndex = priorityModifierKeys.length;
|
||||
for (let i = 0; i < priorityModifierKeys.length; i++) {
|
||||
if (ascShortcut[priorityModifierKeys[i]]()) {
|
||||
keyIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyIndex === priorityModifierKeys.length) return -1;
|
||||
|
||||
// Count extra modifier keys
|
||||
let extras = 0;
|
||||
for (let j = 0; j < priorityModifierKeys.length; j++) {
|
||||
if (j !== keyIndex && ascShortcut[priorityModifierKeys[j]]()) extras++;
|
||||
}
|
||||
|
||||
// weight = range for main key + “cost” of extra keys
|
||||
return keyIndex * 100 + extras;
|
||||
}
|
||||
|
||||
if (first.ascShortcut.asc_IsLocked() && !second.ascShortcut.asc_IsLocked()) return -1;
|
||||
if (!first.ascShortcut.asc_IsLocked() && second.ascShortcut.asc_IsLocked()) return 1;
|
||||
|
||||
let wFirst = getWeight(first.ascShortcut);
|
||||
let wSecond = getWeight(second.ascShortcut);
|
||||
|
||||
if (wFirst !== wSecond) return wFirst - wSecond;
|
||||
|
||||
return first.ascShortcut.asc_GetKeyCode() - second.ascShortcut.asc_GetKeyCode();
|
||||
};
|
||||
|
||||
// Utils
|
||||
var pairs = function(obj) {
|
||||
|
||||
@ -159,6 +159,7 @@ define([
|
||||
ascShortcut: ascShortcut,
|
||||
}
|
||||
});
|
||||
actionItem.shortcuts = actionItem.shortcuts.sort(this._sortComparator);
|
||||
}
|
||||
|
||||
this._eventsTrigger();
|
||||
@ -472,6 +473,9 @@ define([
|
||||
shortcuts[foundIndex].ascShortcut = copyAscShortcut;
|
||||
}
|
||||
}
|
||||
if(this.actionsMap[actionType]) {
|
||||
this.actionsMap[actionType].shortcuts = shortcuts.sort(this._sortComparator);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -313,10 +313,10 @@ define([
|
||||
|
||||
const keys = [];
|
||||
|
||||
if (e.ctrlKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.CTRL));
|
||||
if (e.shiftKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.SHIFT));
|
||||
if (e.altKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.ALT));
|
||||
if (e.metaKey && Common.Utils.isMac) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.META));
|
||||
if (e.ctrlKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.CTRL));
|
||||
if (e.altKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.ALT));
|
||||
if (e.shiftKey) keys.push(me._shortcutsController.keyCodeToKeyName(Common.UI.Keys.SHIFT));
|
||||
|
||||
if (![Common.UI.Keys.CTRL, Common.UI.Keys.SHIFT, Common.UI.Keys.ALT, Common.UI.Keys.META].includes(e.keyCode)) {
|
||||
keys.push(me._shortcutsController.keyCodeToKeyName(e.keyCode));
|
||||
|
||||
Reference in New Issue
Block a user