Skip to content

Commit 6c0c8bd

Browse files
committed
Behavior choice: Helix keymap as an extension
1 parent a5c3e7d commit 6c0c8bd

17 files changed

Lines changed: 3313 additions & 1548 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
/src/commands/load-all.ts linguist-generated
44
/src/commands/README.md linguist-generated
55
/package.json linguist-generated
6+
/extensions/helix/package.json linguist-generated
67
/test/suite/api.test.ts linguist-generated
78
/test/suite/commands/*.test.ts linguist-generated

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1010
"outFiles": ["${workspaceFolder}/out/**/*.js"],
1111
},
12+
{
13+
"name": "Launch extension with helix keybinds",
14+
"type": "extensionHost",
15+
"request": "launch",
16+
"runtimeExecutable": "${execPath}",
17+
"args": [
18+
"${workspaceFolder}/.vscode-test",
19+
"--extensionDevelopmentPath=${workspaceFolder}",
20+
"--extensionDevelopmentPath=${workspaceFolder}/extensions/helix/",
21+
],
22+
"outFiles": ["${workspaceFolder}/out/**/*.js"],
23+
},
1224
{
1325
"name": "Run all tests",
1426
"type": "extensionHost",

extensions/helix/LICENSE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright 2020-2021 Grégoire Geis
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

extensions/helix/dance.png

14.2 KB
Loading

extensions/helix/package.build.ts

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Save to package.json
2+
// ============================================================================
3+
4+
import { Builder, generateIgnoredKeybinds } from "../../meta";
5+
import * as fs from "fs/promises";
6+
import { SelectionBehavior } from "../../src/api";
7+
8+
const version = "0.1.0",
9+
preRelease = 1,
10+
preReleaseVersion = version.replace(/\d+$/, "$&" + preRelease.toString().padStart(3, "0"));
11+
12+
export const pkg = (modules: Builder.ParsedModule[]) => ({
13+
14+
// Common package.json properties.
15+
// ==========================================================================
16+
17+
name: "dance-helix-keybinds",
18+
description: "Helix keybindings for dance",
19+
version,
20+
license: "ISC",
21+
22+
author: {
23+
name: "Grégoire Geis",
24+
email: "opensource@gregoirege.is",
25+
},
26+
27+
repository: {
28+
type: "git",
29+
url: "https://github.com/71/dance.git",
30+
},
31+
32+
engines: {
33+
vscode: "^1.63.0",
34+
},
35+
36+
displayName: "Dance",
37+
publisher: "gregoire",
38+
categories: ["Keymaps", "Other"],
39+
readme: "README.md",
40+
icon: "dance.png",
41+
42+
scripts: {
43+
"package": "vsce package --allow-star-activation",
44+
"publish": "vsce publish --allow-star-activation",
45+
"package:pre": `vsce package --allow-star-activation --pre-release --no-git-tag-version --no-update-package-json ${preReleaseVersion}`,
46+
"publish:pre": `vsce publish --allow-star-activation --pre-release --no-git-tag-version --no-update-package-json ${preReleaseVersion}`,
47+
},
48+
49+
contributes: {
50+
configurationDefaults: {
51+
"dance.defaultMode": "helix/normal",
52+
"dance.modes": {
53+
"": {
54+
hiddenSelectionsIndicatorsDecoration: {
55+
after: {
56+
color: "$list.warningForeground",
57+
},
58+
backgroundColor: "$inputValidation.warningBackground",
59+
borderColor: "$inputValidation.warningBorder",
60+
borderStyle: "solid",
61+
borderWidth: "1px",
62+
isWholeLine: true,
63+
},
64+
},
65+
"input": {
66+
cursorStyle: "underline-thin",
67+
},
68+
"helix/insert": {
69+
onLeaveMode: [
70+
[".selections.save", {
71+
register: " insert",
72+
}],
73+
],
74+
},
75+
"helix/select": {
76+
cursorStyle: "block",
77+
selectionBehavior: "character",
78+
},
79+
"helix/normal": {
80+
cursorStyle: "block",
81+
selectionBehavior: "character",
82+
decorations: {
83+
applyTo: "main",
84+
backgroundColor: "$editor.hoverHighlightBackground",
85+
isWholeLine: true,
86+
},
87+
onEnterMode: [
88+
[".selections.restore", { register: " ^", try: true }],
89+
],
90+
onLeaveMode: [
91+
[".selections.save", {
92+
register: " ^",
93+
style: {
94+
borderColor: "$editor.selectionBackground",
95+
borderStyle: "solid",
96+
borderWidth: "2px",
97+
borderRadius: "1px",
98+
},
99+
until: [
100+
["mode-did-change", { include: "normal" }],
101+
["selections-did-change"],
102+
],
103+
}],
104+
],
105+
},
106+
},
107+
108+
"dance.menus": {
109+
match: {
110+
title: "Match",
111+
items: {
112+
// Should be jump in normal mode, extend in select mode, but jump for seek.enclosing is not implemented
113+
"m": { command: "dance.seek.enclosing", text: "Goto matching bracket" },
114+
"a": { command: "dance.openMenu", args: [{ menu: "object", title: "Match around" }], text: "Select around object" },
115+
"i": { command: "dance.openMenu", args: [{ menu: "object", title: "Match inside", pass: [{ inner: true }] }], text: "Select inside object" },
116+
},
117+
},
118+
119+
object: {
120+
title: "Select object...",
121+
items: ((command = "dance.seek.object") => ({
122+
"()": { command, args: [{ input: "\\((?#inner)\\)" }], text: "parenthesis block" },
123+
"{}": { command, args: [{ input: "\\{(?#inner)\\}" }], text: "braces block" },
124+
"[]": { command, args: [{ input: "\\[(?#inner)\\]" }], text: "brackets block" },
125+
"<>": { command, args: [{ input: "<(?#inner)>" }], text: "angle block" },
126+
'"': { command, args: [{ input: "(?#noescape)\"(?#inner)(?#noescape)\"" }], text: "double quote string" },
127+
"'": { command, args: [{ input: "(?#noescape)'(?#inner)(?#noescape)'" }], text: "single quote string" },
128+
"`": { command, args: [{ input: "(?#noescape)`(?#inner)(?#noescape)`" }], text: "grave quote string" },
129+
"w": { command, args: [{ input: "[\\p{L}_\\d]+(?<after>[^\\S\\n]+)" }], text: "word" },
130+
"W": { command, args: [{ input: "[\\S]+(?<after>[^\\S\\n]+)" }], text: "WORD" },
131+
"p": { command, args: [{ input: "(?#predefined=paragraph)" }], text: "paragraph" },
132+
"a": { command, args: [{ input: "(?#predefined=argument)" }], text: "argument" },
133+
"!": { command, text: "custom object desc" },
134+
}))(),
135+
},
136+
137+
view: {
138+
"title": "View",
139+
"items": {
140+
"cz": { text: "Align view center", command: "dance.view.line", args: [{ "at": "center" }] },
141+
"t": { text: "Align view top", command: "dance.view.line", args: [{ "at": "top" }] },
142+
"b": { text: "Align view bottom", command: "dance.view.line", args: [{ "at": "bottom" }] },
143+
"k": { text: "Scroll view up", command: "editorScroll", args: [{ "by": "line", "revealCursor": true, "to": "up" }] },
144+
"j": { text: "Scroll view down", command: "editorScroll", args: [{ "by": "line", "revealCursor": true, "to": "down" }] },
145+
"/": { text: "Search for regex pattern", command: "dance.search" },
146+
"?": { text: "Reverse search for regex pattern", command: "dance.search.backward" },
147+
"n": { text: "Select next search match", command: "dance.search.next" },
148+
"N": { text: "Select previous search match", command: "dance.search.previous" },
149+
},
150+
},
151+
152+
goto: {
153+
title: "Goto",
154+
items: {
155+
"g": { text: "to line number else file start", command: "dance.select.lineStart" },
156+
"e": { text: "to last line", command: "dance.select.lineEnd", args: [{ count: 2 ** 31 - 1 }] },
157+
"f": { text: "to file/URLs in selections", command: "dance.selections.open" },
158+
"h": { text: "to line start", command: "dance.select.lineStart" },
159+
"l": { text: "to line end", command: "dance.select.lineEnd" },
160+
"i": { text: "to first non-blank in line", command: "dance.select.lineStart", args: [{ skipBlank: true }] },
161+
"d": { text: "to definition", command: "editor.action.revealDefinition" },
162+
"r": { text: "to references", command: "editor.action.goToReferences" },
163+
"j": { text: "to last line", command: "dance.select.lastLine" },
164+
"t": { text: "to window top", command: "dance.select.firstVisibleLine" },
165+
"c": { text: "to window center", command: "dance.select.middleVisibleLine" },
166+
"b": { text: "to window bottom", command: "dance.select.lastVisibleLine" },
167+
"a": { text: "to last buffer", command: "workbench.action.openPreviousRecentlyUsedEditorInGroup" },
168+
"A": { text: "to last buffer...", command: "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup" },
169+
"n": { text: "to next buffer", command: "workbench.action.nextEditor" },
170+
"p": { text: "to previous buffer", command: "workbench.action.previousEditor" },
171+
".": { text: "to last buffer modification position", command: "dance.selections.restore", args: [{ register: " insert" }],
172+
},
173+
},
174+
},
175+
},
176+
},
177+
178+
keybindings: (() => {
179+
const ignoredKeybindings = [],
180+
keybindings = modules
181+
.flatMap((module) => module.keybindings)
182+
.filter((keybinding) => ["core", "helix", undefined].includes(keybinding.category))
183+
.map((k) => ({ ...k }));
184+
for (const mode of ["normal", "select", "insert"]) {
185+
for (const keybind of keybindings) {
186+
keybind.when = keybind.when.replace(`dance.mode == '${mode}'`, `dance.mode == 'helix/${mode}'`);
187+
}
188+
}
189+
190+
for (const mode of ["normal", "select"]) {
191+
const whenMode = `dance.mode == 'helix/${mode}'`;
192+
ignoredKeybindings.push(...generateIgnoredKeybinds(
193+
keybindings.filter(key => key.when.includes(whenMode)),
194+
whenMode,
195+
));
196+
197+
}
198+
199+
return [
200+
...keybindings,
201+
...ignoredKeybindings,
202+
];
203+
})(),
204+
205+
206+
},
207+
});
208+
209+
210+
export async function build(builder: Builder) {
211+
await fs.writeFile(
212+
`${__dirname}/package.json`,
213+
JSON.stringify(pkg(await builder.getCommandModules()), undefined, 2) + "\n",
214+
"utf-8",
215+
);
216+
}

0 commit comments

Comments
 (0)