Skip to content

Commit 7f04bc3

Browse files
committed
fix: unit tests fails after shortcut pack infra changes
1 parent 88068d0 commit 7f04bc3

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/command/KeyBindingManager.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,9 +1704,24 @@ define(function (require, exports, module) {
17041704

17051705
function _getNormalisedKeyMap(keyMap) {
17061706
const normalisedKeyMap = {};
1707+
const normalisedKeyMapCounts = {};
1708+
// if the supplied keymap has duplicates, we have to retain them as is for error dialogs later. Eg:
1709+
// { "ctrl-2": "file.newFile", "Ctrl-2": "navigate.previousMatch", // observe case of Ctrl here
1710+
// "Ctrl-Alt-4": "view.toggleSidebar", "Alt-Ctrl-4": "view.toggleSidebar"}
1711+
for(let key of Object.keys(keyMap)) {
1712+
const normalisedKey = normalizeKeyDescriptorString(key);
1713+
normalisedKeyMapCounts[normalisedKey] = (normalisedKeyMapCounts[normalisedKey] || 0) + 1;
1714+
}
17071715
for(let key of Object.keys(keyMap)) {
17081716
try {
1709-
normalisedKeyMap[normalizeKeyDescriptorString(key)] = keyMap[key];
1717+
const normalisedKey = normalizeKeyDescriptorString(key);
1718+
if(normalisedKeyMapCounts[normalisedKey] === 1) {
1719+
normalisedKeyMap[normalisedKey] = keyMap[key];
1720+
} else {
1721+
// if we are here, it means the supplied keymap has non-normalised duplicates.
1722+
// in case of duplicates, we will keep the keys as is in the map for the error dialogs to kick in.
1723+
normalisedKeyMap[key] = keyMap[key];
1724+
}
17101725
} catch (e) {
17111726
console.error("Error normalising user keymap key: ", key, e);
17121727
// we will still inject the key with error as so that the error dialogs will come up as expected.

test/spec/KeyBindingManager-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,11 @@ define(function (require, exports, module) {
537537
var msgPrefix = Strings.ERROR_RESTRICTED_SHORTCUTS.replace("{0}", "");
538538
expect(message).toMatch(msgPrefix);
539539
if (platform === "mac") {
540-
expect(message).toMatch("cmd-z");
541-
expect(message).toMatch("Cmd-m");
542-
expect(message).toMatch("cmd-h");
540+
expect(message.toLowerCase()).toMatch("cmd-z");
541+
expect(message.toLowerCase()).toMatch("cmd-m");
542+
expect(message.toLowerCase()).toMatch("cmd-h");
543543
} else {
544-
expect(message).toMatch("ctrl-z");
544+
expect(message.toLowerCase()).toMatch("ctrl-z");
545545
}
546546
return {done: function (callback) { callback(Dialogs.DIALOG_BTN_OK); } };
547547
};

0 commit comments

Comments
 (0)