Skip to content

Commit

Permalink
Behavior choice: Basic helix keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
Strackeror committed Jul 3, 2024
1 parent 7bf1463 commit cc565bc
Show file tree
Hide file tree
Showing 18 changed files with 2,034 additions and 1,498 deletions.
3 changes: 3 additions & 0 deletions meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ export function parseKeys(keys: string) {
const remainingKeybinding = keybinding.replace(/[csa]-/g, ""),
whenClauses = ["editorTextFocus"];

if (category !== "core") {
whenClauses.push(`dance.behavior == '${category}'`);
}
for (let tag of tags.split(", ")) {
const negate = tag.startsWith("!");
if (negate) {
Expand Down
50 changes: 26 additions & 24 deletions package.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
description: "Controls which mode is set by default when an editor is opened.",
...modeNamePattern,
},
"dance.behavior": {
enum: ["kakoune", "helix"],
enumItemLabels: ["Kakoune", "Helix"],
description: "Controls which base set of editor keybinds to use",
default: "kakoune",
},
"dance.modes": {
type: "object",
scope: "language-overridable",
Expand Down Expand Up @@ -765,32 +771,28 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
...symbols.map((x) => `Shift+${x}`),
]);

const keysToAssignForNormal = new Set(keysToAssign);
const keysToAssignForVisual = new Set(keysToAssign);

for (const keybinding of keybindings) {
if (keybinding.when.includes("dance.mode == 'normal'")) {
keysToAssignForNormal.delete(keybinding.key);
for (const [category, mode] of [
["kakoune", "normal"],
["helix", "normal"],
["helix", "select"],
]) {
const unassignedKeys = new Set(keysToAssign);
for (const keybinding of keybindings) {
const isInCategory =
keybinding.when.includes(`dance.behavior == '${category}'`) || !keybinding.when.includes("dance.behavior");
const isMode = keybinding.when.includes(`dance.mode == '${mode}'`);
if (isMode && isInCategory) {
unassignedKeys.delete(keybinding.key);
}
}
if (keybinding.when.includes("dance.mode == 'select'")) {
keysToAssignForVisual.delete(keybinding.key);
}
}

for (const keyToAssign of keysToAssignForNormal) {
keybindings.push({
command: "dance.ignore",
key: keyToAssign,
when: "editorTextFocus && dance.mode == 'normal'",
});
}

for (const keyToAssign of keysToAssignForVisual) {
keybindings.push({
command: "dance.ignore",
key: keyToAssign,
when: "editorTextFocus && dance.mode == 'select'",
});
for (const unassignedKey of unassignedKeys) {
keybindings.push({
key: unassignedKey,
command: "dance.ignore",
when: `dance.mode == '${mode}' && dance.behavior == '${category}'`,
});
}
}

return keybindings;
Expand Down
Loading

0 comments on commit cc565bc

Please sign in to comment.