@vim-villain/engine 0.0.0-stage → 0.4.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.
- package/CHANGELOG.md +66 -0
- package/DIVERGENCES.md +51 -0
- package/LICENSE +21 -0
- package/README.md +298 -2
- package/dist/buffer.d.ts +55 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +191 -0
- package/dist/buffer.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.d.ts +6 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +315 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/insert.d.ts +25 -0
- package/dist/insert.d.ts.map +1 -0
- package/dist/insert.js +364 -0
- package/dist/insert.js.map +1 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +41 -0
- package/dist/keys.js.map +1 -0
- package/dist/motions.d.ts +32 -0
- package/dist/motions.d.ts.map +1 -0
- package/dist/motions.js +462 -0
- package/dist/motions.js.map +1 -0
- package/dist/operators.d.ts +25 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +648 -0
- package/dist/operators.js.map +1 -0
- package/dist/state.d.ts +22 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +122 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -4
package/dist/buffer.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** Split a string into Unicode code points. */
|
|
2
|
+
export function toChars(value) {
|
|
3
|
+
return Array.from(value);
|
|
4
|
+
}
|
|
5
|
+
/** Length of a string in Unicode code points. */
|
|
6
|
+
export function lineLength(line) {
|
|
7
|
+
return Array.from(line).length;
|
|
8
|
+
}
|
|
9
|
+
/** True for spaces and tabs, the characters Vim treats as blanks within a line. */
|
|
10
|
+
export function isBlankCharacter(char) {
|
|
11
|
+
return char === " " || char === "\t";
|
|
12
|
+
}
|
|
13
|
+
/** True when the line is empty or contains only spaces/tabs. */
|
|
14
|
+
export function isBlankLine(line) {
|
|
15
|
+
return /^[ \t]*$/.test(line);
|
|
16
|
+
}
|
|
17
|
+
/** Column of the first non-blank character, or the line length when blank. */
|
|
18
|
+
export function firstNonBlank(line) {
|
|
19
|
+
const chars = toChars(line);
|
|
20
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
21
|
+
const char = chars[i];
|
|
22
|
+
if (char !== " " && char !== "\t") {
|
|
23
|
+
return i;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return chars.length;
|
|
27
|
+
}
|
|
28
|
+
/** True when a position is inside the logical buffer (virtual EOL allowed). */
|
|
29
|
+
export function isValidPosition(buffer, position) {
|
|
30
|
+
if (!Number.isInteger(position.line) || !Number.isInteger(position.col)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (position.line < 0 || position.line >= buffer.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return position.col >= 0 && position.col <= lineLength(buffer[position.line] ?? "");
|
|
37
|
+
}
|
|
38
|
+
export function clonePosition(position) {
|
|
39
|
+
return { line: position.line, col: position.col };
|
|
40
|
+
}
|
|
41
|
+
export function positionsEqual(a, b) {
|
|
42
|
+
return a.line === b.line && a.col === b.col;
|
|
43
|
+
}
|
|
44
|
+
export function comparePositions(a, b) {
|
|
45
|
+
if (a.line !== b.line) {
|
|
46
|
+
return a.line - b.line;
|
|
47
|
+
}
|
|
48
|
+
return a.col - b.col;
|
|
49
|
+
}
|
|
50
|
+
/** Clamp a line number into the buffer. */
|
|
51
|
+
export function clampLine(buffer, line) {
|
|
52
|
+
if (!Number.isFinite(line)) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return Math.max(0, Math.min(buffer.length - 1, Math.trunc(line)));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clamp a cursor position.
|
|
59
|
+
*
|
|
60
|
+
* `allowEol` permits column == line length (insert mode). Otherwise the cursor
|
|
61
|
+
* is clamped to the last character; an empty line has column 0.
|
|
62
|
+
*/
|
|
63
|
+
export function clampPosition(buffer, position, allowEol) {
|
|
64
|
+
const line = clampLine(buffer, position.line);
|
|
65
|
+
const length = lineLength(buffer[line] ?? "");
|
|
66
|
+
const maxCol = allowEol ? length : Math.max(0, length - 1);
|
|
67
|
+
const col = Number.isFinite(position.col)
|
|
68
|
+
? Math.max(0, Math.min(maxCol, Math.trunc(position.col)))
|
|
69
|
+
: 0;
|
|
70
|
+
return { line, col };
|
|
71
|
+
}
|
|
72
|
+
/** Clamp a buffer-internal line/column for operator endpoints (virtual EOL allowed). */
|
|
73
|
+
export function clampEndpoint(buffer, position) {
|
|
74
|
+
const line = clampLine(buffer, position.line);
|
|
75
|
+
const length = lineLength(buffer[line] ?? "");
|
|
76
|
+
const col = Math.max(0, Math.min(length, position.col));
|
|
77
|
+
return { line, col };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The character at a position, or `"\n"` for a virtual end-of-line/empty line.
|
|
81
|
+
* Line boundaries are treated as newline characters by word motions.
|
|
82
|
+
*/
|
|
83
|
+
export function charAt(buffer, position) {
|
|
84
|
+
const line = buffer[position.line];
|
|
85
|
+
if (line === undefined) {
|
|
86
|
+
return "\n";
|
|
87
|
+
}
|
|
88
|
+
const chars = toChars(line);
|
|
89
|
+
if (position.col < 0 || position.col >= chars.length) {
|
|
90
|
+
return "\n";
|
|
91
|
+
}
|
|
92
|
+
return chars[position.col] ?? "\n";
|
|
93
|
+
}
|
|
94
|
+
/** The position immediately to the right, or null at end of buffer. */
|
|
95
|
+
export function nextPosition(buffer, position) {
|
|
96
|
+
const line = buffer[position.line];
|
|
97
|
+
if (line === undefined) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const length = lineLength(line);
|
|
101
|
+
if (position.col + 1 < length) {
|
|
102
|
+
return { line: position.line, col: position.col + 1 };
|
|
103
|
+
}
|
|
104
|
+
if (position.line + 1 < buffer.length) {
|
|
105
|
+
return { line: position.line + 1, col: 0 };
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/** The position immediately to the left, or null at start of buffer. */
|
|
110
|
+
export function previousPosition(buffer, position) {
|
|
111
|
+
if (position.col > 0) {
|
|
112
|
+
return { line: position.line, col: position.col - 1 };
|
|
113
|
+
}
|
|
114
|
+
if (position.line > 0) {
|
|
115
|
+
const line = buffer[position.line - 1] ?? "";
|
|
116
|
+
return { line: position.line - 1, col: Math.max(0, lineLength(line) - 1) };
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/** Last character position of a line (never virtual). */
|
|
121
|
+
export function lastCharacterPosition(buffer, line) {
|
|
122
|
+
const clamped = clampLine(buffer, line);
|
|
123
|
+
return { line: clamped, col: Math.max(0, lineLength(buffer[clamped] ?? "") - 1) };
|
|
124
|
+
}
|
|
125
|
+
/** Last character position of the whole buffer. */
|
|
126
|
+
export function lastBufferPosition(buffer) {
|
|
127
|
+
return lastCharacterPosition(buffer, buffer.length - 1);
|
|
128
|
+
}
|
|
129
|
+
/** Text in `[start, end)` with newlines between lines. */
|
|
130
|
+
export function textBetween(buffer, start, end) {
|
|
131
|
+
const from = comparePositions(start, end) <= 0 ? start : end;
|
|
132
|
+
const to = comparePositions(start, end) <= 0 ? end : start;
|
|
133
|
+
const firstLine = buffer[from.line] ?? "";
|
|
134
|
+
if (from.line === to.line) {
|
|
135
|
+
const chars = toChars(firstLine);
|
|
136
|
+
return chars.slice(from.col, to.col).join("");
|
|
137
|
+
}
|
|
138
|
+
const firstChars = toChars(firstLine);
|
|
139
|
+
const parts = [firstChars.slice(from.col).join("")];
|
|
140
|
+
for (let line = from.line + 1; line < to.line; line += 1) {
|
|
141
|
+
parts.push(buffer[line] ?? "");
|
|
142
|
+
}
|
|
143
|
+
const lastChars = toChars(buffer[to.line] ?? "");
|
|
144
|
+
parts.push(lastChars.slice(0, to.col).join(""));
|
|
145
|
+
return parts.join("\n");
|
|
146
|
+
}
|
|
147
|
+
/** Replace the code-point range `[start, end)` with `text` (which may contain newlines). */
|
|
148
|
+
export function replaceText(buffer, start, end, text) {
|
|
149
|
+
const from = comparePositions(start, end) <= 0 ? start : end;
|
|
150
|
+
const to = comparePositions(start, end) <= 0 ? end : start;
|
|
151
|
+
const firstChars = toChars(buffer[from.line] ?? "");
|
|
152
|
+
const lastChars = toChars(buffer[to.line] ?? "");
|
|
153
|
+
const prefix = firstChars.slice(0, from.col).join("");
|
|
154
|
+
const suffix = lastChars.slice(to.col).join("");
|
|
155
|
+
const replacement = prefix + text + suffix;
|
|
156
|
+
const next = buffer.slice();
|
|
157
|
+
next.splice(from.line, to.line - from.line + 1, ...replacement.split("\n"));
|
|
158
|
+
if (next.length === 0) {
|
|
159
|
+
next.push("");
|
|
160
|
+
}
|
|
161
|
+
return next;
|
|
162
|
+
}
|
|
163
|
+
/** Insert text at a position, splitting lines on `\n`. */
|
|
164
|
+
export function insertText(buffer, position, text) {
|
|
165
|
+
return replaceText(buffer, position, position, text);
|
|
166
|
+
}
|
|
167
|
+
/** Remove the code-point range `[start, end)`. */
|
|
168
|
+
export function deleteText(buffer, start, end) {
|
|
169
|
+
return replaceText(buffer, start, end, "");
|
|
170
|
+
}
|
|
171
|
+
/** Codepoint slice of a single line. */
|
|
172
|
+
export function sliceLine(line, start, end) {
|
|
173
|
+
return toChars(line).slice(start, end).join("");
|
|
174
|
+
}
|
|
175
|
+
/** Buffers are equal when all lines are identical. */
|
|
176
|
+
export function buffersEqual(a, b) {
|
|
177
|
+
if (a.length !== b.length) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
181
|
+
if (a[i] !== b[i]) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
/** True when `[start, end)` contains no positions. */
|
|
188
|
+
export function isEmptyRange(start, end) {
|
|
189
|
+
return positionsEqual(start, end);
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAEA,+CAA+C;AAC/C,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC;AACvC,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,O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
|
|
2
|
+
export declare const ENGINE_VERSION = "0.4.0";
|
|
3
|
+
/** Neovim release used as the differential-test oracle. */
|
|
4
|
+
export declare const NEOVIM_REFERENCE_VERSION = "0.11.6";
|
|
5
|
+
/** Indent shift width used by `>` and `<`, in columns. */
|
|
6
|
+
export declare const SHIFT_WIDTH = 2;
|
|
7
|
+
/** Tab stop used only for measuring existing indentation in indent operators. */
|
|
8
|
+
export declare const TAB_WIDTH = 8;
|
|
9
|
+
/**
|
|
10
|
+
* Upper bound for a single numeric count.
|
|
11
|
+
*
|
|
12
|
+
* Neovim accepts much larger counts; the engine caps them to keep a short key
|
|
13
|
+
* log from forcing unbounded replay work. This is documented in DIVERGENCES.md.
|
|
14
|
+
*/
|
|
15
|
+
export declare const MAX_COUNT = 9999;
|
|
16
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,2DAA2D;AAC3D,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAEjD,0DAA0D;AAC1D,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,iFAAiF;AACjF,eAAO,MAAM,SAAS,IAAI,CAAC;AAE3B;;;;;GAKG;AACH,eAAO,MAAM,SAAS,OAAO,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Version of the observable engine contract. Keep in sync with package.json. */
|
|
2
|
+
export const ENGINE_VERSION = "0.4.0";
|
|
3
|
+
/** Neovim release used as the differential-test oracle. */
|
|
4
|
+
export const NEOVIM_REFERENCE_VERSION = "0.11.6";
|
|
5
|
+
/** Indent shift width used by `>` and `<`, in columns. */
|
|
6
|
+
export const SHIFT_WIDTH = 2;
|
|
7
|
+
/** Tab stop used only for measuring existing indentation in indent operators. */
|
|
8
|
+
export const TAB_WIDTH = 8;
|
|
9
|
+
/**
|
|
10
|
+
* Upper bound for a single numeric count.
|
|
11
|
+
*
|
|
12
|
+
* Neovim accepts much larger counts; the engine caps them to keep a short key
|
|
13
|
+
* log from forcing unbounded replay work. This is documented in DIVERGENCES.md.
|
|
14
|
+
*/
|
|
15
|
+
export const MAX_COUNT = 9999;
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,QAAQ,CAAC;AAEjD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B,iFAAiF;AACjF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ApplyKeysResult, State, StepResult } from "./types.js";
|
|
2
|
+
/** Apply a single token, returning a new state and per-key information. */
|
|
3
|
+
export declare function step(state: State, key: string): StepResult;
|
|
4
|
+
/** Apply a sequence of tokens. Metadata for each key is returned in order. */
|
|
5
|
+
export declare function applyKeys(state: State, keys: readonly string[]): ApplyKeysResult;
|
|
6
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,eAAe,EAEf,KAAK,EAEL,UAAU,EACX,MAAM,YAAY,CAAC;AA0UpB,2EAA2E;AAC3E,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAyB1D;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,eAAe,CAgBhF"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { buffersEqual, clampPosition, clonePosition, } from "./buffer.js";
|
|
2
|
+
import { MAX_COUNT } from "./constants.js";
|
|
3
|
+
import { handleInsertKey, isInsertStartKey, startInsert, } from "./insert.js";
|
|
4
|
+
import { isKeyToken, isPrintableKey } from "./keys.js";
|
|
5
|
+
import { applyMotion, executeFind, isDirectMotionKey, isFindStartKey, } from "./motions.js";
|
|
6
|
+
import { completeDoubledOperator, completeOperatorFind, completeOperatorMotion, completeOperatorRepeatFind, isOperatorStartKey, startOperator, toggleCaseAtCursor, } from "./operators.js";
|
|
7
|
+
import { cloneState, isIdle, snapshotState } from "./state.js";
|
|
8
|
+
/** Clear all multi-key input without changing mode or buffer. */
|
|
9
|
+
function clearPendingInput(state) {
|
|
10
|
+
state.pendingCount = 0;
|
|
11
|
+
state.pendingOperator = null;
|
|
12
|
+
state.pendingOperatorCount = 0;
|
|
13
|
+
state.pendingG = false;
|
|
14
|
+
state.pendingFind = null;
|
|
15
|
+
state.pendingTextObject = null;
|
|
16
|
+
}
|
|
17
|
+
/** Clamp the cursor and visual anchor after a command. */
|
|
18
|
+
function normalizeState(state) {
|
|
19
|
+
state.cursor = clampPosition(state.buffer, state.cursor, state.mode === "insert");
|
|
20
|
+
if (state.mode === "visual" || state.mode === "visual-line") {
|
|
21
|
+
if (state.visualAnchor === null) {
|
|
22
|
+
state.visualAnchor = clonePosition(state.cursor);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
state.visualAnchor = clampPosition(state.buffer, state.visualAnchor, false);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
state.visualAnchor = null;
|
|
30
|
+
state.visualEndAtEol = false;
|
|
31
|
+
}
|
|
32
|
+
if (state.mode !== "insert") {
|
|
33
|
+
state.insert = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** True when a token is a decimal digit. */
|
|
37
|
+
function isDigitKey(key) {
|
|
38
|
+
return key.length === 1 && key >= "0" && key <= "9";
|
|
39
|
+
}
|
|
40
|
+
/** Parse leading count digits from a recorded command. */
|
|
41
|
+
function leadingCount(keys) {
|
|
42
|
+
let digits = "";
|
|
43
|
+
for (const key of keys) {
|
|
44
|
+
if (isDigitKey(key)) {
|
|
45
|
+
digits += key;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (digits === "") {
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
const parsed = Number.parseInt(digits, 10);
|
|
55
|
+
return Number.isFinite(parsed) && parsed > 0 ? Math.min(parsed, MAX_COUNT) : 1;
|
|
56
|
+
}
|
|
57
|
+
/** True when the recorded command begins with `.` (possibly after a count). */
|
|
58
|
+
function isDotCommand(keys) {
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
if (isDigitKey(key)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
return key === ".";
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Finish the current command record. A buffer change becomes one undo block and
|
|
69
|
+
* (unless the command was `.`) the new dot-repeat target.
|
|
70
|
+
*/
|
|
71
|
+
function finishRecord(state) {
|
|
72
|
+
const record = state.record;
|
|
73
|
+
if (record === null) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
state.record = null;
|
|
77
|
+
if (buffersEqual(record.start.buffer, state.buffer)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
state.undoStack.push({
|
|
81
|
+
buffer: record.start.buffer.slice(),
|
|
82
|
+
cursor: clonePosition(record.start.cursor),
|
|
83
|
+
});
|
|
84
|
+
state.redoStack = [];
|
|
85
|
+
if (!state.replaying && !isDotCommand(record.keys)) {
|
|
86
|
+
state.lastChange = {
|
|
87
|
+
count: leadingCount(record.keys),
|
|
88
|
+
keys: record.keys.slice(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Start recording a command at the current state. */
|
|
93
|
+
function startRecord(state) {
|
|
94
|
+
state.record = {
|
|
95
|
+
keys: [],
|
|
96
|
+
start: snapshotState(state),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Append one digit to a count, clamping to MAX_COUNT. */
|
|
100
|
+
function appendCount(current, digit) {
|
|
101
|
+
if (current === 0) {
|
|
102
|
+
return Math.min(MAX_COUNT, digit);
|
|
103
|
+
}
|
|
104
|
+
return Math.min(MAX_COUNT, current * 10 + digit);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Apply one keystroke to a cloned state.
|
|
108
|
+
*
|
|
109
|
+
* Recognized keys mutate the clone; unrecognized keys are deterministic no-ops.
|
|
110
|
+
* Pending multi-key sequences are cleared when a token is not part of any
|
|
111
|
+
* supported sequence, and the token is reported as unrecognized.
|
|
112
|
+
*/
|
|
113
|
+
function handleKey(state, key) {
|
|
114
|
+
if (!isKeyToken(key)) {
|
|
115
|
+
clearPendingInput(state);
|
|
116
|
+
state.preferredColumn = null;
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (state.mode === "insert") {
|
|
120
|
+
return handleInsertKey(state, key);
|
|
121
|
+
}
|
|
122
|
+
if (key === "Escape") {
|
|
123
|
+
clearPendingInput(state);
|
|
124
|
+
state.preferredColumn = null;
|
|
125
|
+
if (state.mode === "visual" || state.mode === "visual-line") {
|
|
126
|
+
state.mode = "normal";
|
|
127
|
+
state.visualAnchor = null;
|
|
128
|
+
state.visualEndAtEol = false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
// Visual mode is not implemented in this release. Escape above remains a
|
|
133
|
+
// recognized cancellation; all other input is an unrecognized no-op so this
|
|
134
|
+
// dispatch point can grow without changing the contract.
|
|
135
|
+
if (state.mode !== "normal") {
|
|
136
|
+
clearPendingInput(state);
|
|
137
|
+
state.preferredColumn = null;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (state.pendingFind !== null) {
|
|
141
|
+
const pending = state.pendingFind;
|
|
142
|
+
if (pending.command !== "r" && isPrintableKey(key)) {
|
|
143
|
+
const command = pending.command;
|
|
144
|
+
if (state.pendingOperator !== null) {
|
|
145
|
+
const operator = state.pendingOperator;
|
|
146
|
+
const operatorCount = state.pendingOperatorCount;
|
|
147
|
+
completeOperatorFind(state, operator, command, key, operatorCount, pending.count);
|
|
148
|
+
clearPendingInput(state);
|
|
149
|
+
state.preferredColumn = null;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
executeFind(state, command, key, pending.count);
|
|
153
|
+
state.pendingFind = null;
|
|
154
|
+
state.pendingCount = 0;
|
|
155
|
+
state.preferredColumn = null;
|
|
156
|
+
// Vim records the search arguments even when the search fails; a later
|
|
157
|
+
// `;` or `,` repeats the failed target and is a no-op.
|
|
158
|
+
state.lastFind = { command, char: key };
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
clearPendingInput(state);
|
|
162
|
+
state.preferredColumn = null;
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (state.pendingG) {
|
|
166
|
+
if (key === "g") {
|
|
167
|
+
const operator = state.pendingOperator;
|
|
168
|
+
const operatorCount = state.pendingOperatorCount;
|
|
169
|
+
const motionCount = state.pendingCount;
|
|
170
|
+
state.pendingG = false;
|
|
171
|
+
state.pendingCount = 0;
|
|
172
|
+
if (operator !== null) {
|
|
173
|
+
completeOperatorMotion(state, operator, "gg", operatorCount, motionCount);
|
|
174
|
+
clearPendingInput(state);
|
|
175
|
+
state.preferredColumn = null;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return applyMotion(state, "gg", motionCount);
|
|
179
|
+
}
|
|
180
|
+
if (state.pendingOperator === null && (key === "u" || key === "U")) {
|
|
181
|
+
const count = state.pendingCount;
|
|
182
|
+
state.pendingG = false;
|
|
183
|
+
state.pendingCount = 0;
|
|
184
|
+
startOperator(state, key === "u" ? "gu" : "gU", count);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
clearPendingInput(state);
|
|
188
|
+
state.preferredColumn = null;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (isDigitKey(key)) {
|
|
192
|
+
// `0` is the line-start motion only when no count is being accumulated.
|
|
193
|
+
if (key === "0" && state.pendingCount === 0) {
|
|
194
|
+
if (state.pendingOperator !== null) {
|
|
195
|
+
const operator = state.pendingOperator;
|
|
196
|
+
const operatorCount = state.pendingOperatorCount;
|
|
197
|
+
completeOperatorMotion(state, operator, "0", operatorCount, 0);
|
|
198
|
+
clearPendingInput(state);
|
|
199
|
+
state.preferredColumn = null;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
return applyMotion(state, "0", 0);
|
|
203
|
+
}
|
|
204
|
+
state.pendingCount = appendCount(state.pendingCount, Number(key));
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
if (isFindStartKey(key)) {
|
|
208
|
+
state.pendingFind = {
|
|
209
|
+
command: key,
|
|
210
|
+
count: state.pendingCount === 0 ? 1 : state.pendingCount,
|
|
211
|
+
};
|
|
212
|
+
state.pendingCount = 0;
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (key === "g") {
|
|
216
|
+
state.pendingG = true;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (state.pendingOperator !== null) {
|
|
220
|
+
const operator = state.pendingOperator;
|
|
221
|
+
const operatorCount = state.pendingOperatorCount;
|
|
222
|
+
const motionCount = state.pendingCount;
|
|
223
|
+
const doubles = key === operator ||
|
|
224
|
+
(operator === "gu" && key === "u") ||
|
|
225
|
+
(operator === "gU" && key === "U");
|
|
226
|
+
if (doubles) {
|
|
227
|
+
completeDoubledOperator(state, operator, operatorCount, motionCount);
|
|
228
|
+
clearPendingInput(state);
|
|
229
|
+
state.preferredColumn = null;
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
if (key === ";" || key === ",") {
|
|
233
|
+
completeOperatorRepeatFind(state, operator, key === ",", operatorCount, motionCount);
|
|
234
|
+
clearPendingInput(state);
|
|
235
|
+
state.preferredColumn = null;
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (isDirectMotionKey(key)) {
|
|
239
|
+
completeOperatorMotion(state, operator, key, operatorCount, motionCount);
|
|
240
|
+
clearPendingInput(state);
|
|
241
|
+
state.preferredColumn = null;
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
clearPendingInput(state);
|
|
245
|
+
state.preferredColumn = null;
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
if (isOperatorStartKey(key)) {
|
|
249
|
+
const count = state.pendingCount;
|
|
250
|
+
state.pendingCount = 0;
|
|
251
|
+
startOperator(state, key, count);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
if (key === "~") {
|
|
255
|
+
const count = state.pendingCount === 0 ? 1 : state.pendingCount;
|
|
256
|
+
state.pendingCount = 0;
|
|
257
|
+
state.preferredColumn = null;
|
|
258
|
+
toggleCaseAtCursor(state, count);
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
if (isDirectMotionKey(key)) {
|
|
262
|
+
const count = state.pendingCount;
|
|
263
|
+
state.pendingCount = 0;
|
|
264
|
+
return applyMotion(state, key, count);
|
|
265
|
+
}
|
|
266
|
+
if (isInsertStartKey(key)) {
|
|
267
|
+
const count = state.pendingCount === 0 ? 1 : state.pendingCount;
|
|
268
|
+
clearPendingInput(state);
|
|
269
|
+
startInsert(state, key, count);
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
clearPendingInput(state);
|
|
273
|
+
state.preferredColumn = null;
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
/** Apply a single token, returning a new state and per-key information. */
|
|
277
|
+
export function step(state, key) {
|
|
278
|
+
const next = cloneState(state);
|
|
279
|
+
const beforeBuffer = next.buffer.slice();
|
|
280
|
+
if (next.record === null && !next.replaying) {
|
|
281
|
+
startRecord(next);
|
|
282
|
+
}
|
|
283
|
+
if (next.record !== null) {
|
|
284
|
+
next.record.keys.push(key);
|
|
285
|
+
}
|
|
286
|
+
const recognized = handleKey(next, key);
|
|
287
|
+
if (!next.replaying && isIdle(next)) {
|
|
288
|
+
finishRecord(next);
|
|
289
|
+
}
|
|
290
|
+
normalizeState(next);
|
|
291
|
+
return {
|
|
292
|
+
state: next,
|
|
293
|
+
recognized,
|
|
294
|
+
mode: next.mode,
|
|
295
|
+
changed: !buffersEqual(beforeBuffer, next.buffer),
|
|
296
|
+
cursor: clonePosition(next.cursor),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** Apply a sequence of tokens. Metadata for each key is returned in order. */
|
|
300
|
+
export function applyKeys(state, keys) {
|
|
301
|
+
let current = state;
|
|
302
|
+
const results = [];
|
|
303
|
+
for (const key of keys) {
|
|
304
|
+
const result = step(current, key);
|
|
305
|
+
current = result.state;
|
|
306
|
+
results.push({
|
|
307
|
+
recognized: result.recognized,
|
|
308
|
+
mode: result.mode,
|
|
309
|
+
changed: result.changed,
|
|
310
|
+
cursor: result.cursor,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return { state: current, results };
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAA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C,CAAC;IAExC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,cAAc,CAAC,IAAI,CAAC,CAAC;IAErB,OAAO;QACL,KAAK,EAAE,IAAI;QACX,UAAU;QACV,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC;QACjD,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,KAAY,EAAE,IAAuB;IAC7D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,OAAO,GAAe,EAAE,CAAC;IAE/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAClC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC;YACX,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { applyKeys, step, } from "./engine.js";
|
|
2
|
+
export { initialState } from "./state.js";
|
|
3
|
+
export { ENGINE_VERSION, MAX_COUNT, NEOVIM_REFERENCE_VERSION, SHIFT_WIDTH, TAB_WIDTH, } from "./constants.js";
|
|
4
|
+
export type { ApplyKeysResult, FindCommand, InitialStateOptions, InputRecord, InsertCommand, InsertSession, LastChange, LastFind, Mode, Operator, PendingFind, PendingKeyCommand, Position, Register, Snapshot, State, StepInfo, StepResult, TextObjectScope, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,IAAI,GACL,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,UAAU,EACV,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,IAAI,GACL,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,SAAS,GACV,MAAM,gBAAgB,CAAC"}
|
package/dist/insert.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { State } from "./types.js";
|
|
2
|
+
export type InsertStartKey = "i" | "a" | "I" | "A" | "o" | "O";
|
|
3
|
+
export declare function isInsertStartKey(key: string): key is InsertStartKey;
|
|
4
|
+
/**
|
|
5
|
+
* Start an insert session from a normal-mode entry command.
|
|
6
|
+
*
|
|
7
|
+
* `count` is the already-accumulated count (defaulted to 1 by the caller).
|
|
8
|
+
*/
|
|
9
|
+
export declare function startInsert(state: State, command: InsertStartKey, count: number): void;
|
|
10
|
+
/** Autoindent text for a line, shared with the change operator. */
|
|
11
|
+
export declare function insertAutoIndentFor(line: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Start the insert phase of a change operator.
|
|
14
|
+
*
|
|
15
|
+
* The caller has already deleted the affected range and positioned the cursor.
|
|
16
|
+
* For a linewise change, `autoIndentLine` names the single replacement line and
|
|
17
|
+
* `autoIndentText` is its indentation; for charwise change it is null.
|
|
18
|
+
*/
|
|
19
|
+
export declare function startChangeInsert(state: State, autoIndentLine: number | null, autoIndentText?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Handle one token while in insert mode. Unknown tokens are no-ops and keep
|
|
22
|
+
* the session alive; Escape completes the session.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleInsertKey(state: State, key: string): boolean;
|
|
25
|
+
//# sourceMappingURL=insert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../src/insert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAiB,KAAK,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAW/D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,cAAc,CAEnE;AAsRD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,GACZ,IAAI,CAmDN;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,cAAc,SAAK,GAClB,IAAI,CAcN;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CA2BlE"}
|