From 8b9bf9c5cd3e058e7b3559e042cd49ca85d96860 Mon Sep 17 00:00:00 2001 From: Ian Sanders Date: Mon, 16 Mar 2026 11:45:02 -0400 Subject: [PATCH 1/4] Fix bug in hotkey modifier sorting --- src/hotkey.ts | 19 ++++++++++--------- test/test-normalize-hotkey.js | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/hotkey.ts b/src/hotkey.ts index 2e168d0..e7e5599 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -96,14 +96,15 @@ function localizeMod(hotkey: string, platform?: string | undefined): string { return hotkey.replace('Mod', localModifier) } +const orderedModifiers = { + Control: 0, + Alt: 1, + Meta: 2, + Shift: 3 +} + function sortModifiers(hotkey: string): string { - const key = hotkey.split('+').pop() - const modifiers: string[] = [] - for (const modifier of ['Control', 'Alt', 'Meta', 'Shift']) { - if (hotkey.includes(modifier)) { - modifiers.push(modifier) - } - } - if (key) modifiers.push(key) - return modifiers.join('+') + return hotkey.split('+') + .sort((a, b) => (orderedModifiers[a] ?? Infinity) - (orderedModifiers[b] ?? Infinity)) + .join('+') } diff --git a/test/test-normalize-hotkey.js b/test/test-normalize-hotkey.js index a9efb7b..6b43215 100644 --- a/test/test-normalize-hotkey.js +++ b/test/test-normalize-hotkey.js @@ -31,6 +31,9 @@ describe('normalizeHotkey', () => { // Modifier sorting ['Shift+Alt+Meta+Control+m', 'Control+Alt+Meta+Shift+m'], ['Shift+Alt+Mod+m', 'Control+Alt+Shift+m', 'win'] + // Edge case: only modifiers + ['Alt', 'Alt', 'win / linux'], + ['Alt+Mod', 'Control+Alt', 'win / linux'] ] for (const [input, expected, platform = 'any platform'] of tests) { From 3fbc63c66323a5ff3248a2ddd9c14f7b70527bd2 Mon Sep 17 00:00:00 2001 From: Ian Sanders Date: Mon, 16 Mar 2026 11:52:20 -0400 Subject: [PATCH 2/4] Add explicit type annotation --- src/hotkey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotkey.ts b/src/hotkey.ts index e7e5599..981afbc 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -96,7 +96,7 @@ function localizeMod(hotkey: string, platform?: string | undefined): string { return hotkey.replace('Mod', localModifier) } -const orderedModifiers = { +const orderedModifiers: Partial> = { Control: 0, Alt: 1, Meta: 2, From 774d13258b23be015325b13eedebb970c896fda2 Mon Sep 17 00:00:00 2001 From: Ian Sanders Date: Mon, 16 Mar 2026 11:55:12 -0400 Subject: [PATCH 3/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- test/test-normalize-hotkey.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-normalize-hotkey.js b/test/test-normalize-hotkey.js index 6b43215..8d61fa1 100644 --- a/test/test-normalize-hotkey.js +++ b/test/test-normalize-hotkey.js @@ -30,7 +30,7 @@ describe('normalizeHotkey', () => { ['Mod+a', 'Control+a', undefined], // Modifier sorting ['Shift+Alt+Meta+Control+m', 'Control+Alt+Meta+Shift+m'], - ['Shift+Alt+Mod+m', 'Control+Alt+Shift+m', 'win'] + ['Shift+Alt+Mod+m', 'Control+Alt+Shift+m', 'win'], // Edge case: only modifiers ['Alt', 'Alt', 'win / linux'], ['Alt+Mod', 'Control+Alt', 'win / linux'] From dd025b58220a97b9bf20f096327c48737cb2344e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 15:58:03 +0000 Subject: [PATCH 4/4] Fix prettier formatting in sortModifiers function Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com> --- package-lock.json | 40 ---------------------------------------- src/hotkey.ts | 3 ++- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 392a168..a9eb29a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1073,18 +1073,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "node_modules/@types/node": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.0.tgz", - "integrity": "sha512-IbKooQVqUBrlzWTi79E8Fw78l8k1RNtlDDNWsFZs7XonuQSJ8oNYfEeclhprUldXISRMLzBpILuKgPlIxm+/Yw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "undici-types": "~7.14.0" - } - }, "node_modules/@types/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.4.tgz", @@ -5319,15 +5307,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "7.14.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.14.0.tgz", - "integrity": "sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true - }, "node_modules/untildify": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", @@ -6368,17 +6347,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "@types/node": { - "version": "24.7.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.0.tgz", - "integrity": "sha512-IbKooQVqUBrlzWTi79E8Fw78l8k1RNtlDDNWsFZs7XonuQSJ8oNYfEeclhprUldXISRMLzBpILuKgPlIxm+/Yw==", - "dev": true, - "optional": true, - "peer": true, - "requires": { - "undici-types": "~7.14.0" - } - }, "@types/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.4.tgz", @@ -9283,14 +9251,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "undici-types": { - "version": "7.14.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.14.0.tgz", - "integrity": "sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA==", - "dev": true, - "optional": true, - "peer": true - }, "untildify": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", diff --git a/src/hotkey.ts b/src/hotkey.ts index 981afbc..a31fd3c 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -104,7 +104,8 @@ const orderedModifiers: Partial> = { } function sortModifiers(hotkey: string): string { - return hotkey.split('+') + return hotkey + .split('+') .sort((a, b) => (orderedModifiers[a] ?? Infinity) - (orderedModifiers[b] ?? Infinity)) .join('+') }