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