@gregorlohaus/codemirror-helix 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,UAAU,EAGV,KAAK,aAAa,EAElB,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAuB1B,eAAO,MAAM,WAAW;iBAEP,aAAa;mBAIX,UAAU;gBAUb,UAAU,GAAG,aAAa;aAazC,CAAC;AAEF,eAAO,MAAM,eAAe,uCAEzB,CAAC;AAyBJ,eAAO,MAAM,gBAAgB,uCAA4B,CAAC;AAE1D,eAAO,MAAM,UAAU,uCA8BrB,CAAC"}
package/dist/view.js ADDED
@@ -0,0 +1,105 @@
1
+ import { Decoration, EditorView, ViewPlugin, WidgetType, showPanel, } from "@codemirror/view";
2
+ import { getMode, helixState } from "./state";
3
+ class EolCursorWidget extends WidgetType {
4
+ toDOM() {
5
+ const span = document.createElement("span");
6
+ span.className = "cm-helix-block cm-helix-block-eol";
7
+ span.textContent = " ";
8
+ return span;
9
+ }
10
+ ignoreEvent() {
11
+ return true;
12
+ }
13
+ }
14
+ const blockMark = Decoration.mark({ class: "cm-helix-block" });
15
+ const selectionMark = Decoration.mark({ class: "cm-helix-selection" });
16
+ const eolCursor = Decoration.widget({ widget: new EolCursorWidget(), side: 1 });
17
+ // Draws the selection ranges + a block cursor at each head while in
18
+ // normal/select mode. We render the selection ourselves (rather than relying
19
+ // on drawSelection, which the host theme can leave invisible) so multi-cursor
20
+ // selections are always clearly highlighted.
21
+ export const blockCursor = ViewPlugin.fromClass(class {
22
+ constructor(view) {
23
+ this.decorations = this.build(view);
24
+ }
25
+ update(update) {
26
+ if (update.docChanged ||
27
+ update.selectionSet ||
28
+ update.viewportChanged ||
29
+ update.startState.field(helixState).mode !== update.state.field(helixState).mode) {
30
+ this.decorations = this.build(update.view);
31
+ }
32
+ }
33
+ build(view) {
34
+ if (getMode(view.state) === "insert")
35
+ return Decoration.none;
36
+ const deco = [];
37
+ for (const range of view.state.selection.ranges) {
38
+ if (!range.empty)
39
+ deco.push(selectionMark.range(range.from, range.to));
40
+ const pos = range.head;
41
+ const line = view.state.doc.lineAt(pos);
42
+ deco.push(pos < line.to ? blockMark.range(pos, pos + 1) : eolCursor.range(pos));
43
+ }
44
+ return Decoration.set(deco, true);
45
+ }
46
+ }, { decorations: (plugin) => plugin.decorations });
47
+ export const modeEditorClass = EditorView.editorAttributes.compute([helixState], (state) => ({
48
+ class: `cm-helix cm-helix-${getMode(state)}`,
49
+ }));
50
+ function statusPanel(view) {
51
+ const dom = document.createElement("div");
52
+ dom.className = "cm-helix-status";
53
+ const render = () => {
54
+ const s = view.state.field(helixState);
55
+ const label = s.mode === "insert" ? "INS" : s.mode === "select" ? "SEL" : "NOR";
56
+ const count = s.count ? ` ${s.count}` : "";
57
+ const reg = s.register ? ` "${s.register}` : "";
58
+ const pend = s.pending ? ` ${s.pending.type}` : "";
59
+ const sels = view.state.selection.ranges.length;
60
+ const multi = sels > 1 ? ` ${sels} sels` : "";
61
+ dom.textContent = `${label}${count}${reg}${pend}${multi}`;
62
+ dom.dataset.mode = s.mode;
63
+ };
64
+ render();
65
+ return {
66
+ dom,
67
+ update: (u) => {
68
+ if (u.docChanged || u.selectionSet || u.transactions.length)
69
+ render();
70
+ },
71
+ };
72
+ }
73
+ export const helixStatusPanel = showPanel.of(statusPanel);
74
+ export const helixTheme = EditorView.baseTheme({
75
+ "&.cm-helix-normal .cm-cursor, &.cm-helix-normal .cm-cursorLayer": { display: "none" },
76
+ "&.cm-helix-select .cm-cursor, &.cm-helix-select .cm-cursorLayer": { display: "none" },
77
+ ".cm-helix-selection": { backgroundColor: "rgba(120,160,255,0.32)" },
78
+ ".cm-helix-block": { backgroundColor: "rgba(125,165,255,0.7)", borderRadius: "1px" },
79
+ ".cm-helix-block-eol": { display: "inline-block", width: "0.55em" },
80
+ ".cm-helix-status": {
81
+ padding: "1px 10px",
82
+ font: "11px ui-monospace, SFMono-Regular, Menlo, monospace",
83
+ letterSpacing: "0.05em",
84
+ },
85
+ ".cm-helix-status[data-mode=insert]": { color: "#16a34a" },
86
+ ".cm-helix-status[data-mode=select]": { color: "#d97706" },
87
+ ".cm-helix-status[data-mode=normal]": { color: "#2563eb" },
88
+ ".cm-helix-prompt": {
89
+ display: "flex",
90
+ gap: "0.5em",
91
+ alignItems: "center",
92
+ padding: "2px 10px",
93
+ font: "12px ui-monospace, SFMono-Regular, Menlo, monospace",
94
+ },
95
+ ".cm-helix-prompt label": { opacity: 0.7 },
96
+ ".cm-helix-prompt input": {
97
+ flex: "1",
98
+ border: "none",
99
+ outline: "none",
100
+ background: "transparent",
101
+ color: "inherit",
102
+ font: "inherit",
103
+ },
104
+ });
105
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,SAAS,GAIV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,eAAgB,SAAQ,UAAU;IACtC,KAAK;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,mCAAmC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,WAAW;QACT,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAC/D,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,KA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pF,qBAAqB,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE;IACnE,kBAAkB,EAAE;QAClB,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,qDAAqD;QAC3D,aAAa,EAAE,QAAQ;KACxB;IACD,oCAAoC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1D,oCAAoC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1D,oCAAoC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1D,kBAAkB,EAAE;QAClB,OAAO,EAAE,MAAM;QACf,GAAG,EAAE,OAAO;QACZ,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,qDAAqD;KAC5D;IACD,wBAAwB,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;IAC1C,wBAAwB,EAAE;QACxB,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,aAAa;QACzB,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,SAAS;KAChB;CACF,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@gregorlohaus/codemirror-helix",
3
+ "version": "0.1.0",
4
+ "description": "Helix-editor-style modal editing for CodeMirror 6 (multiple selections, select mode, goto/match modes, textobjects, surround, registers, search).",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": ["dist", "README.md"],
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "prepublishOnly": "tsc -p tsconfig.json"
20
+ },
21
+ "keywords": [
22
+ "codemirror",
23
+ "codemirror6",
24
+ "helix",
25
+ "modal",
26
+ "vim",
27
+ "editor",
28
+ "keybindings"
29
+ ],
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://gitea.gregorlohaus.com/gregor/gregorlohaus.com",
34
+ "directory": "packages/codemirror-helix"
35
+ },
36
+ "peerDependencies": {
37
+ "@codemirror/commands": "^6.0.0",
38
+ "@codemirror/language": "^6.0.0",
39
+ "@codemirror/search": "^6.0.0",
40
+ "@codemirror/state": "^6.0.0",
41
+ "@codemirror/view": "^6.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@codemirror/commands": "^6.10.3",
45
+ "@codemirror/language": "^6.12.3",
46
+ "@codemirror/search": "^6.5.6",
47
+ "@codemirror/state": "^6.6.0",
48
+ "@codemirror/view": "^6.43.1",
49
+ "typescript": "^5.6.0"
50
+ }
51
+ }