Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/cm/keyBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ export function keyBindingsConflict(left, right) {
}

function toCodeMirrorKeyStroke(stroke) {
const parts = stroke.endsWith("-")
? [...stroke.slice(0, -1).split("-").filter(Boolean), "-"]
: stroke
const normalizedStroke = normalizeLegacyModifierSeparators(stroke);
const parts = normalizedStroke.endsWith("-")
? [...normalizedStroke.slice(0, -1).split("-").filter(Boolean), "-"]
: normalizedStroke
.split("-")
.map((part) => part.trim())
.filter(Boolean);
Expand Down Expand Up @@ -121,3 +122,7 @@ function toCodeMirrorKeyStroke(stroke) {
);
return orderedModifiers.length ? `${orderedModifiers.join("-")}-${key}` : key;
}

function normalizeLegacyModifierSeparators(stroke) {
return stroke.replace(/\+(?!$)/g, "-");
}
14 changes: 14 additions & 0 deletions tests/unit/keyBindingUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { toCodeMirrorKey } from "cm/keyBindingUtils";
import { expect, it } from "vitest";

it("parses legacy plus-separated modifier bindings", () => {
expect(toCodeMirrorKey("Ctrl+-")).toBe("Mod--");
expect(toCodeMirrorKey("Ctrl+_")).toBe("Mod-_");
expect(toCodeMirrorKey("Ctrl+=")).toBe("Mod-=");
expect(toCodeMirrorKey("Ctrl+Shift+K")).toBe("Mod-Shift-k");
});

it("keeps hyphen-separated literal plus bindings working", () => {
expect(toCodeMirrorKey("Ctrl-+")).toBe("Mod-+");
expect(toCodeMirrorKey("-")).toBe("-");
});