@monaco-neovim-wasm/lib 0.1.9 → 0.1.11
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/dist/monaco-neovim-wasm.es.js +325 -264
- package/dist/monacoNeovim.d.ts +0 -1
- package/dist/neovimWasmSession.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as g from "monaco-editor";
|
|
2
|
-
class
|
|
2
|
+
class V {
|
|
3
3
|
buffer;
|
|
4
4
|
ctrl;
|
|
5
5
|
data;
|
|
6
6
|
capacity;
|
|
7
|
-
constructor(t =
|
|
7
|
+
constructor(t = N) {
|
|
8
8
|
this.capacity = Math.max(8 * 1024, t | 0), this.buffer = new SharedArrayBuffer(8 + this.capacity), this.ctrl = new Int32Array(this.buffer, 0, 2), this.data = new Uint8Array(this.buffer, 8), Atomics.store(this.ctrl, 0, 0), Atomics.store(this.ctrl, 1, 0);
|
|
9
9
|
}
|
|
10
10
|
push(t) {
|
|
@@ -16,15 +16,15 @@ class U {
|
|
|
16
16
|
return e.byteLength <= a ? (this.data.set(e, s), Atomics.store(this.ctrl, 1, (s + e.byteLength) % this.capacity)) : (this.data.set(e.subarray(0, a), s), this.data.set(e.subarray(a), 0), Atomics.store(this.ctrl, 1, e.byteLength - a)), Atomics.notify(this.ctrl, 1), !0;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
return new
|
|
19
|
+
const N = 262144;
|
|
20
|
+
function U(o = N) {
|
|
21
|
+
return new V(o);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function R(o) {
|
|
24
24
|
const t = [];
|
|
25
|
-
return
|
|
25
|
+
return E(o, t), new Uint8Array(t);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function E(o, t) {
|
|
28
28
|
if (o == null) {
|
|
29
29
|
t.push(192);
|
|
30
30
|
return;
|
|
@@ -53,12 +53,12 @@ function T(o, t) {
|
|
|
53
53
|
j(o, t);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
56
|
+
if (Y(o)) {
|
|
57
|
+
J(o, t);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
if (typeof o == "object") {
|
|
61
|
-
|
|
61
|
+
X(o, t);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
throw new Error("Unsupported type in msgpack encode");
|
|
@@ -108,24 +108,24 @@ function G(o, t) {
|
|
|
108
108
|
const e = o.length;
|
|
109
109
|
e <= 15 ? t.push(144 | e) : e <= 65535 ? t.push(220, e >> 8 & 255, e & 255) : t.push(221, e >> 24 & 255, e >> 16 & 255, e >> 8 & 255, e & 255);
|
|
110
110
|
for (const i of o)
|
|
111
|
-
|
|
111
|
+
E(i, t);
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function X(o, t) {
|
|
114
114
|
const e = Object.keys(o), i = e.length;
|
|
115
115
|
i <= 15 ? t.push(128 | i) : i <= 65535 ? t.push(222, i >> 8 & 255, i & 255) : t.push(223, i >> 24 & 255, i >> 16 & 255, i >> 8 & 255, i & 255);
|
|
116
116
|
for (const s of e)
|
|
117
|
-
|
|
117
|
+
E(s, t), E(o[s], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function J(o, t) {
|
|
120
120
|
const e = o.data.length;
|
|
121
121
|
e === 1 ? t.push(212, o.type) : e === 2 ? t.push(213, o.type) : e === 4 ? t.push(214, o.type) : e === 8 ? t.push(215, o.type) : e === 16 ? t.push(216, o.type) : t.push(199, e, o.type);
|
|
122
122
|
for (let i = 0; i < e; i += 1)
|
|
123
123
|
t.push(o.data[i]);
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function Y(o) {
|
|
126
126
|
return !!(o && typeof o == "object" && typeof o.type == "number" && o.data instanceof Uint8Array);
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function Z() {
|
|
129
129
|
return typeof SharedArrayBuffer < "u" && typeof crossOriginIsolated < "u" && crossOriginIsolated;
|
|
130
130
|
}
|
|
131
131
|
function ee(o) {
|
|
@@ -140,6 +140,7 @@ class te {
|
|
|
140
140
|
pending = /* @__PURE__ */ new Map();
|
|
141
141
|
workerExited = !1;
|
|
142
142
|
workerExitCode = null;
|
|
143
|
+
workerFatalError = null;
|
|
143
144
|
inputQueue = [];
|
|
144
145
|
inputQueueHead = 0;
|
|
145
146
|
inputQueuedBytes = 0;
|
|
@@ -149,7 +150,7 @@ class te {
|
|
|
149
150
|
worker: t.worker ?? null,
|
|
150
151
|
workerUrl: t.workerUrl ?? null,
|
|
151
152
|
createWorker: t.createWorker ?? null,
|
|
152
|
-
sharedInputBytes: t.sharedInputBytes ??
|
|
153
|
+
sharedInputBytes: t.sharedInputBytes ?? N,
|
|
153
154
|
inputMode: t.inputMode ?? "shared",
|
|
154
155
|
rpcTimeoutMs: t.rpcTimeoutMs ?? 8e3,
|
|
155
156
|
maxQueuedBytes: t.maxQueuedBytes ?? 4 * 1024 * 1024,
|
|
@@ -168,12 +169,31 @@ class te {
|
|
|
168
169
|
}
|
|
169
170
|
async start(t) {
|
|
170
171
|
const { cols: e, rows: i, wasmPath: s, runtimePath: n, env: r, files: a } = t;
|
|
171
|
-
if (this.inputMode = t.inputMode ?? this.init.inputMode, this.inputMode === "shared" && !
|
|
172
|
+
if (this.inputMode = t.inputMode ?? this.init.inputMode, this.inputMode === "shared" && !Z())
|
|
172
173
|
throw new Error('SharedArrayBuffer is required for inputMode="shared"; serve with COOP/COEP so crossOriginIsolated is true, or use inputMode="message" with the asyncify worker.');
|
|
173
|
-
const
|
|
174
|
-
if (this.stop({ terminate: !this.init.reuseWorker, silent: !0 }), this.sharedInput = this.inputMode === "shared" ?
|
|
175
|
-
this.worker.onmessage = (
|
|
176
|
-
const
|
|
174
|
+
const u = this.worker;
|
|
175
|
+
if (this.stop({ terminate: !this.init.reuseWorker, silent: !0 }), this.sharedInput = this.inputMode === "shared" ? U(this.init.sharedInputBytes) : null, this.workerExited = !1, this.workerExitCode = null, this.workerFatalError = null, this.reqId = 1, this.pending.clear(), this.init.worker ? this.worker = this.init.worker : this.init.createWorker ? this.worker = this.init.createWorker() : this.init.reuseWorker && u ? this.worker = u : this.worker = this.init.workerUrl ? new Worker(this.init.workerUrl, { type: "module" }) : null, !this.worker) throw new Error("worker/workerUrl is required");
|
|
176
|
+
this.worker.onmessage = (l) => this.handleWorkerMessage(l.data);
|
|
177
|
+
const d = (l) => {
|
|
178
|
+
if (!this.workerExited) {
|
|
179
|
+
if (this.workerFatalError = l, this.workerExited = !0, this.workerExitCode = 1, this.pending.size) {
|
|
180
|
+
const c = new Error(l);
|
|
181
|
+
this.pending.forEach((h) => h.reject(c)), this.pending.clear();
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
this.init.handlers.onStartError?.(l);
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
this.worker.onerror = (l) => {
|
|
190
|
+
const c = l?.message ? `worker error: ${l.message}` : "worker error", h = l?.error?.stack;
|
|
191
|
+
d(h ? `${c}
|
|
192
|
+
${h}` : c);
|
|
193
|
+
}, this.worker.onmessageerror = () => {
|
|
194
|
+
d("worker messageerror");
|
|
195
|
+
};
|
|
196
|
+
const f = {
|
|
177
197
|
type: "start",
|
|
178
198
|
cols: Number(e) || 80,
|
|
179
199
|
rows: Number(i) || 24,
|
|
@@ -184,9 +204,9 @@ class te {
|
|
|
184
204
|
files: a ?? void 0
|
|
185
205
|
};
|
|
186
206
|
try {
|
|
187
|
-
this.worker.postMessage(
|
|
207
|
+
this.worker.postMessage(f, []);
|
|
188
208
|
} catch {
|
|
189
|
-
this.worker.postMessage(
|
|
209
|
+
this.worker.postMessage(f);
|
|
190
210
|
}
|
|
191
211
|
}
|
|
192
212
|
stop(t = {}) {
|
|
@@ -211,7 +231,7 @@ class te {
|
|
|
211
231
|
}
|
|
212
232
|
notify(t, e = []) {
|
|
213
233
|
if (!this.worker || this.workerExited) return;
|
|
214
|
-
const i =
|
|
234
|
+
const i = R([2, t, e]);
|
|
215
235
|
this.postInput(i);
|
|
216
236
|
}
|
|
217
237
|
call(t, e = []) {
|
|
@@ -221,32 +241,41 @@ class te {
|
|
|
221
241
|
return;
|
|
222
242
|
}
|
|
223
243
|
if (this.workerExited) {
|
|
224
|
-
const a = this.workerExitCode;
|
|
225
|
-
s(new Error(a != null ? `nvim exited (${a})` :
|
|
244
|
+
const a = this.workerExitCode, u = this.workerFatalError ? `: ${this.workerFatalError}` : "";
|
|
245
|
+
s(new Error(a != null ? `nvim exited (${a})${u}` : `nvim exited${u}`));
|
|
226
246
|
return;
|
|
227
247
|
}
|
|
228
248
|
const n = this.reqId++;
|
|
229
249
|
this.pending.set(n, { resolve: i, reject: s, ts: Date.now(), method: t });
|
|
230
|
-
const r =
|
|
250
|
+
const r = R([0, n, t, e]);
|
|
231
251
|
this.postInput(r), setTimeout(() => {
|
|
232
|
-
this.pending.has(n) && (this.pending.delete(n), s(new Error(this.workerExited ? this.workerExitCode != null ? `nvim exited (${this.workerExitCode})` : "nvim exited" : `rpc timeout: ${t}`)));
|
|
252
|
+
this.pending.has(n) && (this.pending.delete(n), s(new Error(this.workerExited ? this.workerExitCode != null ? `nvim exited (${this.workerExitCode})${this.workerFatalError ? `: ${this.workerFatalError}` : ""}` : `nvim exited${this.workerFatalError ? `: ${this.workerFatalError}` : ""}` : `rpc timeout: ${t}`)));
|
|
233
253
|
}, this.init.rpcTimeoutMs);
|
|
234
254
|
});
|
|
235
255
|
}
|
|
236
256
|
async waitForApi() {
|
|
237
|
-
const e = Math.min(Math.max(this.init.rpcTimeoutMs * 2,
|
|
238
|
-
for (
|
|
257
|
+
const e = Math.min(Math.max(this.init.rpcTimeoutMs * 2, 15e3), 9e4), i = Date.now() + e;
|
|
258
|
+
for (; Date.now() < i; ) {
|
|
259
|
+
if (this.workerExited) {
|
|
260
|
+
const s = this.workerExitCode, n = this.workerFatalError ? `: ${this.workerFatalError}` : "";
|
|
261
|
+
throw new Error(s != null ? `nvim exited (${s})${n}` : `nvim exited${n}`);
|
|
262
|
+
}
|
|
239
263
|
try {
|
|
240
264
|
await this.call("nvim_get_api_info", []);
|
|
241
265
|
return;
|
|
242
266
|
} catch {
|
|
243
|
-
|
|
267
|
+
if (this.workerExited) {
|
|
268
|
+
const n = this.workerExitCode, r = this.workerFatalError ? `: ${this.workerFatalError}` : "";
|
|
269
|
+
throw new Error(n != null ? `nvim exited (${n})${r}` : `nvim exited${r}`);
|
|
270
|
+
}
|
|
271
|
+
await new Promise((n) => setTimeout(n, 300));
|
|
244
272
|
}
|
|
273
|
+
}
|
|
245
274
|
throw new Error("nvim_get_api_info timed out");
|
|
246
275
|
}
|
|
247
276
|
respond(t, e, i) {
|
|
248
277
|
if (!this.worker || this.workerExited) return;
|
|
249
|
-
const s =
|
|
278
|
+
const s = R([1, t, e, i]);
|
|
250
279
|
this.postInput(s);
|
|
251
280
|
}
|
|
252
281
|
handleWorkerMessage(t) {
|
|
@@ -309,7 +338,7 @@ class te {
|
|
|
309
338
|
const i = t, s = i.code, n = i.lastStderr;
|
|
310
339
|
if (this.workerExited = !0, this.workerExitCode = s, this.pending.size) {
|
|
311
340
|
const r = n ? `: ${n.trim()}` : "", a = new Error(`nvim exited (${s})${r}`);
|
|
312
|
-
this.pending.forEach((
|
|
341
|
+
this.pending.forEach((u) => u.reject(a)), this.pending.clear();
|
|
313
342
|
}
|
|
314
343
|
try {
|
|
315
344
|
this.init.handlers.onExit?.(s, n);
|
|
@@ -850,7 +879,6 @@ class le {
|
|
|
850
879
|
compositionActive = !1;
|
|
851
880
|
pendingResyncAfterComposition = !1;
|
|
852
881
|
ignoreNextInputEvent = !1;
|
|
853
|
-
ignoreNvimBufLinesUntil = 0;
|
|
854
882
|
exitingInsertMode = !1;
|
|
855
883
|
pendingKeysAfterExit = "";
|
|
856
884
|
exitInsertTimer = null;
|
|
@@ -898,7 +926,7 @@ class le {
|
|
|
898
926
|
const e = String(t ?? "");
|
|
899
927
|
if (!e) return;
|
|
900
928
|
const i = typeof performance < "u" && performance.now ? performance.now() : Date.now();
|
|
901
|
-
e.length > 1 && e === this.lastImeCommitText && i - this.lastImeCommitAt < 60 || (this.lastImeCommitText = e, this.lastImeCommitAt = i, this.sendInput(
|
|
929
|
+
e.length > 1 && e === this.lastImeCommitText && i - this.lastImeCommitAt < 60 || (this.lastImeCommitText = e, this.lastImeCommitAt = i, this.sendInput(k(e, !0)));
|
|
902
930
|
}
|
|
903
931
|
constructor(t, e = {}) {
|
|
904
932
|
this.editor = t, this.opts = {
|
|
@@ -910,7 +938,7 @@ class le {
|
|
|
910
938
|
inputMode: e.inputMode ?? "shared",
|
|
911
939
|
env: e.env,
|
|
912
940
|
files: e.files,
|
|
913
|
-
sharedInputBytes: e.sharedInputBytes ??
|
|
941
|
+
sharedInputBytes: e.sharedInputBytes ?? N,
|
|
914
942
|
cols: e.cols ?? 120,
|
|
915
943
|
rows: e.rows ?? 40,
|
|
916
944
|
minCols: e.minCols ?? 20,
|
|
@@ -1073,7 +1101,7 @@ class le {
|
|
|
1073
1101
|
this.sendNotify("nvim_input", [String(t ?? "")]);
|
|
1074
1102
|
}
|
|
1075
1103
|
type(t, e = !0) {
|
|
1076
|
-
const i =
|
|
1104
|
+
const i = k(String(t ?? ""), e);
|
|
1077
1105
|
i && this.sendNotify("nvim_input", [i]);
|
|
1078
1106
|
}
|
|
1079
1107
|
paste(t) {
|
|
@@ -1176,8 +1204,8 @@ end)(unpack(_A))`;
|
|
|
1176
1204
|
}
|
|
1177
1205
|
computeGridSize() {
|
|
1178
1206
|
try {
|
|
1179
|
-
const t = this.editor.getLayoutInfo(), e = Math.max(0, Number(t?.contentWidth ?? t?.width ?? 0) || 0), i = Math.max(0, Number(t?.contentHeight ?? t?.height ?? 0) || 0), s = this.editor.getOption(g.editor.EditorOption.fontInfo), n = Math.max(1, Number(s?.typicalHalfwidthCharacterWidth ?? s?.maxDigitWidth ?? 0) || 0), r = Math.max(1, Number(s?.lineHeight ?? 0) || 0), a = Math.max(this.opts.minCols, Math.floor(e / n)),
|
|
1180
|
-
if (Number.isFinite(a) && Number.isFinite(
|
|
1207
|
+
const t = this.editor.getLayoutInfo(), e = Math.max(0, Number(t?.contentWidth ?? t?.width ?? 0) || 0), i = Math.max(0, Number(t?.contentHeight ?? t?.height ?? 0) || 0), s = this.editor.getOption(g.editor.EditorOption.fontInfo), n = Math.max(1, Number(s?.typicalHalfwidthCharacterWidth ?? s?.maxDigitWidth ?? 0) || 0), r = Math.max(1, Number(s?.lineHeight ?? 0) || 0), a = Math.max(this.opts.minCols, Math.floor(e / n)), u = Math.max(this.opts.minRows, Math.floor(i / r));
|
|
1208
|
+
if (Number.isFinite(a) && Number.isFinite(u) && a > 0 && u > 0) return { cols: a, rows: u };
|
|
1181
1209
|
} catch {
|
|
1182
1210
|
}
|
|
1183
1211
|
return { cols: this.opts.cols, rows: this.opts.rows };
|
|
@@ -1220,10 +1248,10 @@ end)(unpack(_A))`;
|
|
|
1220
1248
|
const e = this.editor.getModel();
|
|
1221
1249
|
if (!e) return;
|
|
1222
1250
|
const i = this.editor.getSelection(), n = (i && !i.isEmpty() ? i.getStartPosition() : null) ?? this.editor.getPosition() ?? this.lastCursorPos ?? new g.Position(1, 1), r = String(t).split(/\r?\n/);
|
|
1223
|
-
let a = n.lineNumber,
|
|
1224
|
-
r.length <= 1 ?
|
|
1225
|
-
const
|
|
1226
|
-
this.optimisticCursorPrevPos = f, this.optimisticCursorPos =
|
|
1251
|
+
let a = n.lineNumber, u = n.column;
|
|
1252
|
+
r.length <= 1 ? u += Array.from(r[0] ?? "").length : (a += r.length - 1, u = 1 + Array.from(r[r.length - 1] ?? "").length);
|
|
1253
|
+
const d = e.validatePosition(new g.Position(a, u)), f = this.editor.getPosition() ?? this.lastCursorPos ?? n;
|
|
1254
|
+
this.optimisticCursorPrevPos = f, this.optimisticCursorPos = d, this.optimisticCursorUntil = (typeof performance < "u" && performance.now ? performance.now() : Date.now()) + 120, this.lastCursorPos = d, !this.compositionActive && (this.suppressCursorSync = !0, this.editor.setPosition(d), this.suppressCursorSync = !1);
|
|
1227
1255
|
}
|
|
1228
1256
|
positionPreedit() {
|
|
1229
1257
|
if (!this.preeditEl || !this.preeditVisible) return;
|
|
@@ -1349,7 +1377,7 @@ end)(unpack(_A))`;
|
|
|
1349
1377
|
await this.execLua(this.opts.startupLua, []);
|
|
1350
1378
|
} catch {
|
|
1351
1379
|
}
|
|
1352
|
-
const t = await this.rpcCall("nvim_get_current_buf", []), e =
|
|
1380
|
+
const t = await this.rpcCall("nvim_get_current_buf", []), e = x(t) ?? 1;
|
|
1353
1381
|
if (this.bufHandle = e, await this.rpcCall("nvim_buf_attach", [e, !0, {}]) !== !0) throw new Error("nvim_buf_attach failed");
|
|
1354
1382
|
this.ensureActiveState(), this.opts.syncTabstop && this.syncTabstopFromMonaco();
|
|
1355
1383
|
const s = await this.rpcCall("nvim_buf_get_lines", [e, 0, -1, !1]);
|
|
@@ -1362,8 +1390,8 @@ end)(unpack(_A))`;
|
|
|
1362
1390
|
const a = await this.rpcCall("nvim_buf_get_name", [e]);
|
|
1363
1391
|
r.name = typeof a == "string" ? a : "", r.name && this.buffersByName.set(r.name, e);
|
|
1364
1392
|
try {
|
|
1365
|
-
const
|
|
1366
|
-
r.filetype = typeof
|
|
1393
|
+
const u = await this.rpcCall("nvim_buf_get_option", [e, "filetype"]);
|
|
1394
|
+
r.filetype = typeof u == "string" ? u : "";
|
|
1367
1395
|
} catch {
|
|
1368
1396
|
}
|
|
1369
1397
|
}
|
|
@@ -1439,7 +1467,7 @@ end)(unpack(_A))`;
|
|
|
1439
1467
|
this.lastCursorPos = a;
|
|
1440
1468
|
return;
|
|
1441
1469
|
}
|
|
1442
|
-
this.updateCursor(n.line, n.col),
|
|
1470
|
+
this.updateCursor(n.line, n.col), w(this.lastMode) && this.scheduleVisualSelectionRefresh();
|
|
1443
1471
|
return;
|
|
1444
1472
|
}
|
|
1445
1473
|
if (t === "monaco_mode") {
|
|
@@ -1453,46 +1481,45 @@ end)(unpack(_A))`;
|
|
|
1453
1481
|
return;
|
|
1454
1482
|
}
|
|
1455
1483
|
if (t === "nvim_buf_lines_event") {
|
|
1456
|
-
const [i, s, n, r, a] = e,
|
|
1457
|
-
if (!
|
|
1458
|
-
const
|
|
1459
|
-
if (!
|
|
1460
|
-
if (this.bufHandle != null &&
|
|
1484
|
+
const [i, s, n, r, a] = e, u = x(i);
|
|
1485
|
+
if (!u) return;
|
|
1486
|
+
const d = this.bufHandle != null && u === this.bufHandle ? this.ensureActiveState() : this.buffers.get(u) ?? null;
|
|
1487
|
+
if (!d) return;
|
|
1488
|
+
if (this.bufHandle != null && u === this.bufHandle && this.compositionActive) {
|
|
1461
1489
|
this.pendingResyncAfterComposition = !0;
|
|
1462
1490
|
return;
|
|
1463
1491
|
}
|
|
1464
|
-
const f =
|
|
1465
|
-
if (f && Number.isInteger(l) && Number.isInteger(
|
|
1492
|
+
const f = d.model, l = Number(n), c = Number(r), h = Array.isArray(a) ? a.map((p) => String(p ?? "")) : null;
|
|
1493
|
+
if (f && Number.isInteger(l) && Number.isInteger(c) && l >= 0 && c >= l && h)
|
|
1466
1494
|
try {
|
|
1467
|
-
const p = this.bufHandle != null &&
|
|
1495
|
+
const p = this.bufHandle != null && u === this.bufHandle && this.editor.getModel() === f;
|
|
1468
1496
|
if (p && this.delegateInsertToMonaco) {
|
|
1469
|
-
const y = this.computeLinePatch(f, l,
|
|
1497
|
+
const y = this.computeLinePatch(f, l, c, h);
|
|
1470
1498
|
let b = !1;
|
|
1471
1499
|
try {
|
|
1472
1500
|
b = f.getValueInRange(y.range) === y.text;
|
|
1473
1501
|
} catch {
|
|
1474
1502
|
}
|
|
1475
1503
|
if (!b) {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
this.applyLinePatchToModel(f, l, u, d);
|
|
1504
|
+
if (d.pendingFullSync || d.pendingBufEdits.length) return;
|
|
1505
|
+
this.applyLinePatchToModel(f, l, c, h);
|
|
1479
1506
|
try {
|
|
1480
|
-
|
|
1507
|
+
d.shadowLines = f.getLinesContent();
|
|
1481
1508
|
} catch {
|
|
1482
1509
|
}
|
|
1483
1510
|
}
|
|
1484
|
-
} else p ? this.applyLinePatch(f, l,
|
|
1511
|
+
} else p ? this.applyLinePatch(f, l, c, h) : this.applyLinePatchToModel(f, l, c, h);
|
|
1485
1512
|
} catch {
|
|
1486
1513
|
}
|
|
1487
1514
|
else
|
|
1488
1515
|
try {
|
|
1489
|
-
const p = await this.rpcCall("nvim_buf_get_lines", [
|
|
1490
|
-
this.bufHandle != null &&
|
|
1516
|
+
const p = await this.rpcCall("nvim_buf_get_lines", [u, 0, -1, !1]), y = Array.isArray(p) ? p : [""];
|
|
1517
|
+
this.bufHandle != null && u === this.bufHandle && this.editor.getModel() === f ? this.applyBuffer(y) : this.setModelText(f, y);
|
|
1491
1518
|
} catch {
|
|
1492
1519
|
}
|
|
1493
|
-
this.bufHandle != null &&
|
|
1520
|
+
this.bufHandle != null && u === this.bufHandle && w(this.lastMode) && this.scheduleVisualSelectionRefresh();
|
|
1494
1521
|
} else if (t === "nvim_buf_detach_event") {
|
|
1495
|
-
const i =
|
|
1522
|
+
const i = x(e?.[0]);
|
|
1496
1523
|
if (i && this.buffers.has(i)) {
|
|
1497
1524
|
const s = this.buffers.get(i);
|
|
1498
1525
|
if (s.name && this.buffersByName.delete(s.name), s.createdModel)
|
|
@@ -1506,12 +1533,12 @@ end)(unpack(_A))`;
|
|
|
1506
1533
|
} else t === "redraw" && this.handleRedraw(e);
|
|
1507
1534
|
}
|
|
1508
1535
|
computeLinePatch(t, e, i, s) {
|
|
1509
|
-
const n = t.getLineCount(), r = Math.min(e, n), a = Math.min(i, n),
|
|
1510
|
-
let
|
|
1536
|
+
const n = t.getLineCount(), r = Math.min(e, n), a = Math.min(i, n), u = new g.Position(n, t.getLineMaxColumn(n)), f = a >= n && s.length === 0 && r > 0 ? new g.Position(r, t.getLineMaxColumn(r)) : r < n ? new g.Position(r + 1, 1) : u, l = a < n ? new g.Position(a + 1, 1) : u;
|
|
1537
|
+
let c = s.join(`
|
|
1511
1538
|
`);
|
|
1512
|
-
return e >= n && i >= n && s.length > 0 && (
|
|
1513
|
-
${
|
|
1514
|
-
`), { range: new g.Range(f.lineNumber, f.column, l.lineNumber, l.column), text:
|
|
1539
|
+
return e >= n && i >= n && s.length > 0 && (c = `
|
|
1540
|
+
${c}`), i < n && s.length > 0 && (c += `
|
|
1541
|
+
`), { range: new g.Range(f.lineNumber, f.column, l.lineNumber, l.column), text: c };
|
|
1515
1542
|
}
|
|
1516
1543
|
applyLinePatch(t, e, i, s) {
|
|
1517
1544
|
const n = this.lastCursorPos ?? this.editor.getPosition() ?? new g.Position(1, 1), r = this.computeLinePatch(t, e, i, s);
|
|
@@ -1597,7 +1624,7 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1597
1624
|
this.cmdlineEl.textContent = this.cmdlineTextRaw, this.cmdlineCursorByte = null;
|
|
1598
1625
|
return;
|
|
1599
1626
|
}
|
|
1600
|
-
const e = this.cmdlineTextRaw, i = Math.max(0, Math.min(Number(t) || 0,
|
|
1627
|
+
const e = this.cmdlineTextRaw, i = Math.max(0, Math.min(Number(t) || 0, A(e))), s = Math.max(0, Math.min(e.length, S(e, i)));
|
|
1601
1628
|
this.cmdlineCursorByte = i, this.cmdlineEl.textContent = `${e.slice(0, s)}▏${e.slice(s)}`;
|
|
1602
1629
|
}
|
|
1603
1630
|
setMessage(t) {
|
|
@@ -1663,7 +1690,7 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1663
1690
|
}
|
|
1664
1691
|
if (i === "wrappedLine" && (e === "down" || e === "up")) {
|
|
1665
1692
|
const a = e === "down" ? "cursorDown" : "cursorUp";
|
|
1666
|
-
for (let
|
|
1693
|
+
for (let u = 0; u < s; u += 1)
|
|
1667
1694
|
try {
|
|
1668
1695
|
this.editor.trigger("monaco-neovim-wasm", a, null);
|
|
1669
1696
|
} catch {
|
|
@@ -1700,40 +1727,40 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1700
1727
|
} catch {
|
|
1701
1728
|
}
|
|
1702
1729
|
};
|
|
1703
|
-
let
|
|
1730
|
+
let u = null;
|
|
1704
1731
|
try {
|
|
1705
|
-
|
|
1732
|
+
u = this.editor.getScrolledVisiblePosition(i);
|
|
1706
1733
|
} catch {
|
|
1707
1734
|
}
|
|
1708
|
-
if (!
|
|
1735
|
+
if (!u) {
|
|
1709
1736
|
a();
|
|
1710
1737
|
try {
|
|
1711
|
-
|
|
1738
|
+
u = this.editor.getScrolledVisiblePosition(i);
|
|
1712
1739
|
} catch {
|
|
1713
1740
|
}
|
|
1714
1741
|
}
|
|
1715
|
-
if (!
|
|
1716
|
-
const
|
|
1717
|
-
let
|
|
1718
|
-
if (f < n ?
|
|
1742
|
+
if (!u || !Number.isFinite(u.top) || !Number.isFinite(u.height)) return !1;
|
|
1743
|
+
const d = this.editor.getScrollTop(), f = u.top, l = u.top + u.height, c = Math.max(0, r - n);
|
|
1744
|
+
let h = 0;
|
|
1745
|
+
if (f < n ? h = f - n : l > c && (h = l - c), !h) return !1;
|
|
1719
1746
|
try {
|
|
1720
|
-
this.editor.setScrollTop(Math.max(0,
|
|
1747
|
+
this.editor.setScrollTop(Math.max(0, d + h));
|
|
1721
1748
|
} catch {
|
|
1722
1749
|
}
|
|
1723
1750
|
return !0;
|
|
1724
1751
|
}
|
|
1725
1752
|
applyMonacoScroll(t) {
|
|
1726
|
-
const e = typeof t.by == "string" ? t.by : "", i = typeof t.direction == "string" ? t.direction : "", s = Math.max(1, Number(t.value ?? 1) || 1), n = !!t.moveCursor, r = typeof t.cursorBy == "string" ? t.cursorBy : "wrappedLine", a = Math.max(3, this.uiRows || this.opts.rows),
|
|
1727
|
-
let
|
|
1728
|
-
if (e === "page")
|
|
1729
|
-
else if (e === "halfPage")
|
|
1730
|
-
else if (e === "line")
|
|
1753
|
+
const e = typeof t.by == "string" ? t.by : "", i = typeof t.direction == "string" ? t.direction : "", s = Math.max(1, Number(t.value ?? 1) || 1), n = !!t.moveCursor, r = typeof t.cursorBy == "string" ? t.cursorBy : "wrappedLine", a = Math.max(3, this.uiRows || this.opts.rows), u = this.editor.getOption(g.editor.EditorOption.fontInfo), d = Math.max(1, Number(u?.lineHeight ?? 0) || 0), f = Math.max(1, a - 2), l = Math.max(1, Math.floor(f / 2));
|
|
1754
|
+
let c = s;
|
|
1755
|
+
if (e === "page") c = f * s;
|
|
1756
|
+
else if (e === "halfPage") c = l * s;
|
|
1757
|
+
else if (e === "line") c = s;
|
|
1731
1758
|
else return !1;
|
|
1732
|
-
const
|
|
1733
|
-
if (!
|
|
1759
|
+
const h = i === "up" ? -1 : i === "down" ? 1 : 0;
|
|
1760
|
+
if (!h) return !1;
|
|
1734
1761
|
this.suppressCursorSync = !0;
|
|
1735
1762
|
try {
|
|
1736
|
-
const p = this.editor.getScrollTop(), y = Math.max(0, p +
|
|
1763
|
+
const p = this.editor.getScrollTop(), y = Math.max(0, p + h * c * d);
|
|
1737
1764
|
this.editor.setScrollTop(y);
|
|
1738
1765
|
} catch {
|
|
1739
1766
|
}
|
|
@@ -1741,9 +1768,9 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1741
1768
|
if (n)
|
|
1742
1769
|
try {
|
|
1743
1770
|
this.applyMonacoCursorMove({
|
|
1744
|
-
to:
|
|
1771
|
+
to: h > 0 ? "down" : "up",
|
|
1745
1772
|
by: r,
|
|
1746
|
-
value:
|
|
1773
|
+
value: c
|
|
1747
1774
|
}), m = !0;
|
|
1748
1775
|
} catch {
|
|
1749
1776
|
}
|
|
@@ -1752,23 +1779,23 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1752
1779
|
applyMonacoReveal(t) {
|
|
1753
1780
|
const e = typeof t.direction == "string" ? t.direction : "", i = !!t.resetCursor, s = this.editor.getPosition();
|
|
1754
1781
|
if (!s) return !1;
|
|
1755
|
-
const n = s.lineNumber, r = Math.max(1, this.uiRows || this.opts.rows), a = this.editor.getOption(g.editor.EditorOption.fontInfo),
|
|
1782
|
+
const n = s.lineNumber, r = Math.max(1, this.uiRows || this.opts.rows), a = this.editor.getOption(g.editor.EditorOption.fontInfo), u = Math.max(1, Number(a?.lineHeight ?? 0) || 0);
|
|
1756
1783
|
this.suppressCursorSync = !0;
|
|
1757
1784
|
try {
|
|
1758
1785
|
if (e === "top") {
|
|
1759
|
-
const
|
|
1760
|
-
this.editor.setScrollTop(
|
|
1786
|
+
const d = this.editor.getTopForLineNumber(n);
|
|
1787
|
+
this.editor.setScrollTop(d);
|
|
1761
1788
|
} else if (e === "center")
|
|
1762
1789
|
this.editor.revealLineInCenter(n);
|
|
1763
1790
|
else if (e === "bottom") {
|
|
1764
|
-
const
|
|
1791
|
+
const d = this.editor.getTopForLineNumber(n), f = Math.max(0, d - (r - 1) * u);
|
|
1765
1792
|
this.editor.setScrollTop(f);
|
|
1766
1793
|
}
|
|
1767
1794
|
if (i) {
|
|
1768
|
-
const
|
|
1769
|
-
if (
|
|
1770
|
-
const f =
|
|
1771
|
-
this.editor.setPosition(
|
|
1795
|
+
const d = this.editor.getModel();
|
|
1796
|
+
if (d) {
|
|
1797
|
+
const f = d.getLineContent(n) ?? "", l = /\S/.exec(f), c = l ? l.index + 1 : 1, h = d.validatePosition(new g.Position(n, c));
|
|
1798
|
+
this.editor.setPosition(h), this.lastCursorPos = h;
|
|
1772
1799
|
}
|
|
1773
1800
|
}
|
|
1774
1801
|
} catch {
|
|
@@ -1783,8 +1810,8 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1783
1810
|
const s = Math.max(1, Number(t.value ?? 1) || 1);
|
|
1784
1811
|
let n = 1, r = i.getLineCount();
|
|
1785
1812
|
try {
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1813
|
+
const c = this.editor.getVisibleRanges();
|
|
1814
|
+
c && c.length && (n = Math.min(...c.map((h) => h.startLineNumber)), r = Math.max(...c.map((h) => h.endLineNumber)));
|
|
1788
1815
|
} catch {
|
|
1789
1816
|
}
|
|
1790
1817
|
n = Math.max(1, Math.min(n, i.getLineCount())), r = Math.max(1, Math.min(r, i.getLineCount())), r < n && (r = n);
|
|
@@ -1798,7 +1825,7 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1798
1825
|
else
|
|
1799
1826
|
return;
|
|
1800
1827
|
a = Math.max(n, Math.min(r, a));
|
|
1801
|
-
const
|
|
1828
|
+
const u = i.getLineContent(a) ?? "", d = /\S/.exec(u), f = d ? d.index + 1 : 1, l = i.validatePosition(new g.Position(a, f));
|
|
1802
1829
|
this.suppressCursorSync = !0;
|
|
1803
1830
|
try {
|
|
1804
1831
|
this.editor.setPosition(l);
|
|
@@ -1838,9 +1865,9 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1838
1865
|
continue;
|
|
1839
1866
|
}
|
|
1840
1867
|
if (i === "cmdline_show") {
|
|
1841
|
-
const r = n[0], a = Math.max(0, Number(n[1] ?? 0) || 0),
|
|
1868
|
+
const r = n[0], a = Math.max(0, Number(n[1] ?? 0) || 0), u = typeof n[2] == "string" ? n[2] : "", d = typeof n[3] == "string" ? n[3] : "", f = Math.max(0, Number(n[4] ?? 0) || 0), l = d || u || "", c = " ".repeat(f), h = T(r), m = `${c}${l}${h}`;
|
|
1842
1869
|
this.setCmdline(m);
|
|
1843
|
-
const p =
|
|
1870
|
+
const p = A(`${c}${l}`), y = A(h);
|
|
1844
1871
|
this.cmdlineCursorOffsetBytes = p, this.cmdlineCursorContentBytes = y;
|
|
1845
1872
|
const b = a <= y ? this.cmdlineCursorOffsetBytes + a : a;
|
|
1846
1873
|
this.setCmdlineCursor(b), this.scheduleSearchHighlightRefresh();
|
|
@@ -1856,17 +1883,17 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1856
1883
|
continue;
|
|
1857
1884
|
}
|
|
1858
1885
|
if (i === "msg_show") {
|
|
1859
|
-
const r = typeof n[0] == "string" ? n[0] : "", a = n[1],
|
|
1886
|
+
const r = typeof n[0] == "string" ? n[0] : "", a = n[1], u = !!n[2], d = !!n[4], f = T(a);
|
|
1860
1887
|
if (r === "empty" && !f) {
|
|
1861
1888
|
this.setMessage(null);
|
|
1862
1889
|
continue;
|
|
1863
1890
|
}
|
|
1864
1891
|
if (!f) continue;
|
|
1865
|
-
if (
|
|
1892
|
+
if (d && this.messageEl?.textContent) {
|
|
1866
1893
|
this.setMessage(`${this.messageEl.textContent}${f}`);
|
|
1867
1894
|
continue;
|
|
1868
1895
|
}
|
|
1869
|
-
if (
|
|
1896
|
+
if (u) {
|
|
1870
1897
|
this.setMessage(f);
|
|
1871
1898
|
continue;
|
|
1872
1899
|
}
|
|
@@ -1874,7 +1901,7 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1874
1901
|
continue;
|
|
1875
1902
|
}
|
|
1876
1903
|
if (i === "msg_showmode" || i === "msg_showcmd" || i === "msg_ruler") {
|
|
1877
|
-
const r = n[0], a =
|
|
1904
|
+
const r = n[0], a = T(r);
|
|
1878
1905
|
this.setMessage(a || null);
|
|
1879
1906
|
continue;
|
|
1880
1907
|
}
|
|
@@ -1883,8 +1910,8 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1883
1910
|
continue;
|
|
1884
1911
|
}
|
|
1885
1912
|
if (i === "popupmenu_show") {
|
|
1886
|
-
const r = n[0], a = Number(n[1] ?? -1),
|
|
1887
|
-
this.setPopupmenu(
|
|
1913
|
+
const r = n[0], a = Number(n[1] ?? -1), u = be(r);
|
|
1914
|
+
this.setPopupmenu(u, Number.isFinite(a) ? a : -1);
|
|
1888
1915
|
continue;
|
|
1889
1916
|
}
|
|
1890
1917
|
if (i === "popupmenu_select") {
|
|
@@ -1913,14 +1940,29 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1913
1940
|
}
|
|
1914
1941
|
}, i = (l) => {
|
|
1915
1942
|
try {
|
|
1916
|
-
const
|
|
1917
|
-
|
|
1943
|
+
const c = l;
|
|
1944
|
+
if (!c || typeof c.tagName != "string") return null;
|
|
1945
|
+
const h = c.tagName;
|
|
1946
|
+
return h === "TEXTAREA" ? c.classList?.contains?.("inputarea") || c.classList?.contains?.("ime-text-area") ? c : null : h === "DIV" && c.classList?.contains?.("native-edit-context") ? c : null;
|
|
1918
1947
|
} catch {
|
|
1919
1948
|
return null;
|
|
1920
1949
|
}
|
|
1921
1950
|
}, s = (l) => {
|
|
1922
1951
|
if (this.compositionActive || l.isComposing || l.getModifierState?.("AltGraph")) return;
|
|
1923
|
-
|
|
1952
|
+
const c = this.delegateInsertToMonaco && !this.exitingInsertMode;
|
|
1953
|
+
if (!c && (l.key === "Backspace" || l.key === "Delete" || l.key === "Escape")) {
|
|
1954
|
+
if (!this.opts.shouldHandleKey(l)) return;
|
|
1955
|
+
const p = this.opts.translateKey(l);
|
|
1956
|
+
if (!p) return;
|
|
1957
|
+
e(l);
|
|
1958
|
+
try {
|
|
1959
|
+
l.preventDefault();
|
|
1960
|
+
} catch {
|
|
1961
|
+
}
|
|
1962
|
+
this.exitingInsertMode ? this.pendingKeysAfterExit += p : this.sendInput(p);
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
if (v(this.lastMode) && !this.delegateInsertToMonaco && !this.exitingInsertMode && !l.ctrlKey && !l.metaKey && typeof l.key == "string" && l.key.length === 1) {
|
|
1924
1966
|
const p = /^[\x20-\x7E]$/.test(l.key);
|
|
1925
1967
|
if (!!!(l.altKey && p)) {
|
|
1926
1968
|
if (!this.opts.shouldHandleKey(l)) return;
|
|
@@ -1929,12 +1971,11 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1929
1971
|
}
|
|
1930
1972
|
}
|
|
1931
1973
|
if (!l.ctrlKey && !l.altKey && !l.metaKey) return;
|
|
1932
|
-
const
|
|
1933
|
-
if (!
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
} else if (d || !l.ctrlKey || l.altKey || l.metaKey || u !== "f" && u !== "b" && u !== "d" && u !== "u" && u !== "e" && u !== "y" && u !== "v") return;
|
|
1974
|
+
const h = this.modifiedKeyName(l);
|
|
1975
|
+
if (!h || !this.opts.shouldHandleKey(l)) return;
|
|
1976
|
+
if (this.hasExplicitModAllowlist(c)) {
|
|
1977
|
+
if (!this.shouldForwardModifiedKeys(l, c)) return;
|
|
1978
|
+
} else if (c || !l.ctrlKey || l.altKey || l.metaKey || h !== "f" && h !== "b" && h !== "d" && h !== "u" && h !== "e" && h !== "y" && h !== "v") return;
|
|
1938
1979
|
const m = this.opts.translateKey(l);
|
|
1939
1980
|
if (m) {
|
|
1940
1981
|
e(l);
|
|
@@ -1942,7 +1983,7 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1942
1983
|
l.preventDefault();
|
|
1943
1984
|
} catch {
|
|
1944
1985
|
}
|
|
1945
|
-
this.exitingInsertMode ? (this.debugLog(`keydown(capture) buffer: key=${JSON.stringify(l.key)} code=${JSON.stringify(l.code)} mods=${l.ctrlKey ? "C" : ""}${l.altKey ? "A" : ""}${l.metaKey ? "D" : ""}${l.shiftKey ? "S" : ""} -> ${m}`), this.pendingKeysAfterExit += m) : (
|
|
1986
|
+
this.exitingInsertMode ? (this.debugLog(`keydown(capture) buffer: key=${JSON.stringify(l.key)} code=${JSON.stringify(l.code)} mods=${l.ctrlKey ? "C" : ""}${l.altKey ? "A" : ""}${l.metaKey ? "D" : ""}${l.shiftKey ? "S" : ""} -> ${m}`), this.pendingKeysAfterExit += m) : (c && this.flushPendingMonacoSync(), this.debugLog(`keydown(capture) send: key=${JSON.stringify(l.key)} code=${JSON.stringify(l.code)} mods=${l.ctrlKey ? "C" : ""}${l.altKey ? "A" : ""}${l.metaKey ? "D" : ""}${l.shiftKey ? "S" : ""} -> ${m}`), this.sendInput(m));
|
|
1946
1987
|
}
|
|
1947
1988
|
}, n = () => {
|
|
1948
1989
|
if (this.compositionActive = !0, this.debugLog(`compositionstart delegateInsert=${this.delegateInsertToMonaco} mode=${JSON.stringify(this.lastMode)}`), this.delegateInsertToMonaco) {
|
|
@@ -1955,65 +1996,75 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
1955
1996
|
this.scheduleCursorSyncToNvim();
|
|
1956
1997
|
return;
|
|
1957
1998
|
}
|
|
1958
|
-
const
|
|
1959
|
-
if (
|
|
1960
|
-
const
|
|
1999
|
+
const c = i(l.target);
|
|
2000
|
+
if (v(this.lastMode)) {
|
|
2001
|
+
const h = typeof l.data == "string" ? l.data : "", m = !h && c && c.tagName === "TEXTAREA" && c.value ? String(c.value) : !h && c?.textContent ? String(c.textContent) : "", p = h || m;
|
|
1961
2002
|
p && this.sendCmdlineImeText(p);
|
|
1962
2003
|
}
|
|
1963
2004
|
try {
|
|
1964
|
-
|
|
1965
|
-
d && (d.value = "");
|
|
2005
|
+
c && c.tagName === "TEXTAREA" ? c.value = "" : c && (c.textContent = "");
|
|
1966
2006
|
} catch {
|
|
1967
2007
|
}
|
|
1968
2008
|
this.pendingResyncAfterComposition && (this.pendingResyncAfterComposition = !1, this.scheduleResync());
|
|
1969
2009
|
}, a = (l) => {
|
|
1970
2010
|
if (this.compositionActive || (this.compositionActive = !0), this.delegateInsertToMonaco) return;
|
|
1971
|
-
const
|
|
1972
|
-
this.setPreedit(
|
|
1973
|
-
},
|
|
1974
|
-
i(l.target) && (this.delegateInsertToMonaco && !this.exitingInsertMode
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2011
|
+
const c = i(l.target), h = typeof l.data == "string" ? l.data : c && c.tagName === "TEXTAREA" && c.value ? String(c.value) : c?.textContent ? String(c.textContent) : "";
|
|
2012
|
+
this.setPreedit(h || "");
|
|
2013
|
+
}, u = (l) => {
|
|
2014
|
+
if (i(l.target) && !(this.delegateInsertToMonaco && !this.exitingInsertMode)) {
|
|
2015
|
+
e(l);
|
|
2016
|
+
try {
|
|
2017
|
+
l.preventDefault?.();
|
|
2018
|
+
} catch {
|
|
2019
|
+
}
|
|
2020
|
+
if (v(this.lastMode) && !this.compositionActive) {
|
|
2021
|
+
const h = l, m = typeof h.data == "string" ? h.data : "", p = typeof h.inputType == "string" ? String(h.inputType) : "";
|
|
2022
|
+
!!!h.isComposing && !p.includes("Composition") && m && this.sendCmdlineImeText(m);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}, d = (l) => {
|
|
2026
|
+
const c = i(l.target);
|
|
2027
|
+
if (!c || this.delegateInsertToMonaco && !this.exitingInsertMode) return;
|
|
1978
2028
|
e(l);
|
|
1979
|
-
const
|
|
2029
|
+
const h = l;
|
|
1980
2030
|
if (this.ignoreNextInputEvent) {
|
|
1981
2031
|
this.ignoreNextInputEvent = !1;
|
|
1982
2032
|
try {
|
|
1983
|
-
|
|
2033
|
+
c.tagName === "TEXTAREA" ? c.value = "" : c.textContent = "";
|
|
1984
2034
|
} catch {
|
|
1985
2035
|
}
|
|
1986
2036
|
return;
|
|
1987
2037
|
}
|
|
1988
2038
|
if (!this.compositionActive) {
|
|
1989
|
-
if (
|
|
1990
|
-
const m = typeof
|
|
2039
|
+
if (v(this.lastMode)) {
|
|
2040
|
+
const m = typeof h.data == "string" ? h.data : "", p = !m && c.tagName === "TEXTAREA" && c.value ? String(c.value) : !m && c?.textContent ? String(c.textContent) : "", y = m || p;
|
|
1991
2041
|
y && this.sendCmdlineImeText(y);
|
|
1992
2042
|
}
|
|
1993
2043
|
try {
|
|
1994
|
-
|
|
2044
|
+
c.tagName === "TEXTAREA" ? c.value = "" : c.textContent = "";
|
|
1995
2045
|
} catch {
|
|
1996
2046
|
}
|
|
1997
2047
|
}
|
|
1998
2048
|
}, f = (l) => {
|
|
1999
|
-
|
|
2049
|
+
const c = i(l.target);
|
|
2050
|
+
if (!c || this.delegateInsertToMonaco && !this.exitingInsertMode) return;
|
|
2000
2051
|
e(l);
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2052
|
+
const h = l.clipboardData?.getData("text/plain") ?? "";
|
|
2053
|
+
h && (l.preventDefault(), this.ignoreNextInputEvent = !0, this.pasteText(h));
|
|
2003
2054
|
try {
|
|
2004
|
-
|
|
2055
|
+
c.tagName === "TEXTAREA" ? c.value = "" : c.textContent = "";
|
|
2005
2056
|
} catch {
|
|
2006
2057
|
}
|
|
2007
2058
|
};
|
|
2008
2059
|
this.disposables.push(
|
|
2009
2060
|
// Capture phase to ensure we see events even if Monaco stops propagation.
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2061
|
+
C(t, "keydown", s, !0),
|
|
2062
|
+
C(t, "beforeinput", u, !0),
|
|
2063
|
+
C(t, "input", d, !0),
|
|
2064
|
+
C(t, "paste", f, !0),
|
|
2065
|
+
C(t, "compositionstart", n, !0),
|
|
2066
|
+
C(t, "compositionupdate", a, !0),
|
|
2067
|
+
C(t, "compositionend", r, !0)
|
|
2017
2068
|
);
|
|
2018
2069
|
}
|
|
2019
2070
|
scheduleResync() {
|
|
@@ -2137,27 +2188,27 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
2137
2188
|
this.clearSearchHighlights();
|
|
2138
2189
|
return;
|
|
2139
2190
|
}
|
|
2140
|
-
const n = Array.isArray(i.matches) ? i.matches : [], r = i.current && typeof i.current == "object" ? i.current : null, a = r && Number.isFinite(Number(r.l)) ? `${Number(r.l)}:${Number(r.s)}:${Number(r.e)}` : null,
|
|
2141
|
-
if (f.has(
|
|
2142
|
-
const
|
|
2143
|
-
return f.set(
|
|
2191
|
+
const n = Array.isArray(i.matches) ? i.matches : [], r = i.current && typeof i.current == "object" ? i.current : null, a = r && Number.isFinite(Number(r.l)) ? `${Number(r.l)}:${Number(r.s)}:${Number(r.e)}` : null, u = [], d = 2e3, f = /* @__PURE__ */ new Map(), l = (c) => {
|
|
2192
|
+
if (f.has(c)) return f.get(c);
|
|
2193
|
+
const h = e.getLineContent(c) ?? "";
|
|
2194
|
+
return f.set(c, h), h;
|
|
2144
2195
|
};
|
|
2145
|
-
for (let
|
|
2146
|
-
const
|
|
2196
|
+
for (let c = 0; c < n.length && u.length < d; c += 1) {
|
|
2197
|
+
const h = n[c], m = Number(h?.l), p = Number(h?.s), y = Number(h?.e);
|
|
2147
2198
|
if (!Number.isFinite(m) || !Number.isFinite(p) || !Number.isFinite(y)) continue;
|
|
2148
2199
|
const b = m + 1;
|
|
2149
2200
|
if (b < 1 || b > e.getLineCount()) continue;
|
|
2150
|
-
const
|
|
2151
|
-
if (D <=
|
|
2201
|
+
const I = l(b), P = S(I, Math.max(0, p)) + 1, D = S(I, Math.max(0, y)) + 1;
|
|
2202
|
+
if (D <= P) continue;
|
|
2152
2203
|
const W = `${m}:${p}:${y}`, z = a && W === a ? "monaco-neovim-search-current" : "monaco-neovim-search-match";
|
|
2153
|
-
|
|
2154
|
-
range: new g.Range(b,
|
|
2204
|
+
u.push({
|
|
2205
|
+
range: new g.Range(b, P, b, D),
|
|
2155
2206
|
options: { inlineClassName: z }
|
|
2156
2207
|
});
|
|
2157
2208
|
}
|
|
2158
2209
|
this.ensureSearchStyle();
|
|
2159
2210
|
try {
|
|
2160
|
-
this.searchDecorationIds = this.editor.deltaDecorations(this.searchDecorationIds,
|
|
2211
|
+
this.searchDecorationIds = this.editor.deltaDecorations(this.searchDecorationIds, u);
|
|
2161
2212
|
} catch {
|
|
2162
2213
|
this.searchDecorationIds = [];
|
|
2163
2214
|
}
|
|
@@ -2167,9 +2218,9 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
2167
2218
|
const s = ge(e) === "V", n = [];
|
|
2168
2219
|
if (s) {
|
|
2169
2220
|
let r = 1 / 0, a = -1 / 0;
|
|
2170
|
-
for (const
|
|
2171
|
-
const
|
|
2172
|
-
r = Math.min(r,
|
|
2221
|
+
for (const u of t) {
|
|
2222
|
+
const d = u.getStartPosition(), f = u.getEndPosition();
|
|
2223
|
+
r = Math.min(r, d.lineNumber, f.lineNumber), a = Math.max(a, d.lineNumber, f.lineNumber);
|
|
2173
2224
|
}
|
|
2174
2225
|
Number.isFinite(r) && Number.isFinite(a) && a >= r && n.push({
|
|
2175
2226
|
range: new g.Range(r, 1, a, 1),
|
|
@@ -2177,9 +2228,9 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
2177
2228
|
});
|
|
2178
2229
|
} else
|
|
2179
2230
|
for (const r of t) {
|
|
2180
|
-
const a = r.getStartPosition(),
|
|
2231
|
+
const a = r.getStartPosition(), u = r.getEndPosition();
|
|
2181
2232
|
n.push({
|
|
2182
|
-
range: g.Range.fromPositions(a,
|
|
2233
|
+
range: g.Range.fromPositions(a, u),
|
|
2183
2234
|
options: { inlineClassName: "monaco-neovim-visual-inline" }
|
|
2184
2235
|
});
|
|
2185
2236
|
}
|
|
@@ -2192,19 +2243,27 @@ ${u}`), i < n && s.length > 0 && (u += `
|
|
|
2192
2243
|
applyNvimMode(t) {
|
|
2193
2244
|
const e = typeof t == "string" ? t : "";
|
|
2194
2245
|
if (!e || e === this.lastMode) return;
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2246
|
+
const i = this.lastMode;
|
|
2247
|
+
this.lastMode = e, v(e) && (this.ignoreNextInputEvent = !1);
|
|
2248
|
+
const s = $(e) && !this.recordingRegister;
|
|
2249
|
+
if (s !== this.delegateInsertToMonaco) {
|
|
2250
|
+
this.delegateInsertToMonaco = s;
|
|
2251
|
+
const n = this.ensureActiveState();
|
|
2252
|
+
s ? (this.setPreedit(null), this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0, n && (n.shadowLines = this.editor.getModel()?.getLinesContent() ?? null, n.pendingBufEdits = [], n.pendingFullSync = !1, n.pendingCursorSync = !1)) : (n && ((n.pendingBufEdits.length || n.pendingCursorSync || n.pendingFullSync) && this.flushPendingMonacoSync(), n.shadowLines = null, n.pendingBufEdits = [], n.pendingFullSync = !1, n.pendingCursorSync = !1), this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0);
|
|
2201
2253
|
}
|
|
2202
2254
|
if (this.exitingInsertMode && !$(e)) {
|
|
2203
2255
|
this.exitInsertTimer && (clearTimeout(this.exitInsertTimer), this.exitInsertTimer = null), this.exitingInsertMode = !1;
|
|
2204
|
-
const
|
|
2205
|
-
this.pendingKeysAfterExit = "",
|
|
2256
|
+
const n = this.pendingKeysAfterExit;
|
|
2257
|
+
this.pendingKeysAfterExit = "", n && this.sendInput(n);
|
|
2206
2258
|
}
|
|
2207
|
-
this.applyCursorStyle(e), this.opts.onModeChange && this.opts.onModeChange(e), this.updateVisualSelection(e),
|
|
2259
|
+
if (this.applyCursorStyle(e), this.opts.onModeChange && this.opts.onModeChange(e), this.updateVisualSelection(e), w(i) && !w(e))
|
|
2260
|
+
try {
|
|
2261
|
+
const n = this.editor.getPosition() ?? this.lastCursorPos;
|
|
2262
|
+
n && !this.compositionActive && (this.suppressCursorSync = !0, this.editor.setSelection(new g.Selection(n.lineNumber, n.column, n.lineNumber, n.column)), this.suppressCursorSync = !1);
|
|
2263
|
+
} catch {
|
|
2264
|
+
this.suppressCursorSync = !1;
|
|
2265
|
+
}
|
|
2266
|
+
this.scheduleSearchHighlightRefresh();
|
|
2208
2267
|
}
|
|
2209
2268
|
armInsertExit() {
|
|
2210
2269
|
this.exitingInsertMode = !0, this.pendingKeysAfterExit = "", this.exitInsertTimer && (clearTimeout(this.exitInsertTimer), this.exitInsertTimer = null), this.exitInsertTimer = window.setTimeout(() => {
|
|
@@ -2250,7 +2309,6 @@ vim.opt.ei = ei
|
|
|
2250
2309
|
}
|
|
2251
2310
|
handleKey(t) {
|
|
2252
2311
|
const e = t.browserEvent;
|
|
2253
|
-
if (e.defaultPrevented && e.key !== "Escape" && e.key !== "Enter") return;
|
|
2254
2312
|
if (this.exitingInsertMode) {
|
|
2255
2313
|
if (e.key === "Escape") {
|
|
2256
2314
|
t.preventDefault();
|
|
@@ -2282,7 +2340,7 @@ vim.opt.ei = ei
|
|
|
2282
2340
|
}
|
|
2283
2341
|
return;
|
|
2284
2342
|
}
|
|
2285
|
-
if (
|
|
2343
|
+
if (v(this.lastMode) && !this.compositionActive && !e.isComposing && !e.getModifierState?.("AltGraph") && !e.ctrlKey && !e.metaKey && typeof e.key == "string" && e.key.length === 1) {
|
|
2286
2344
|
const s = /^[\x20-\x7E]$/.test(e.key);
|
|
2287
2345
|
if (!!!(e.altKey && s))
|
|
2288
2346
|
return this.opts.shouldHandleKey(e), void 0;
|
|
@@ -2300,7 +2358,7 @@ vim.opt.ei = ei
|
|
|
2300
2358
|
}
|
|
2301
2359
|
handleMouse(t) {
|
|
2302
2360
|
if (this.delegateInsertToMonaco || !this.bufHandle || !t.target?.position) return;
|
|
2303
|
-
const { lineNumber: e, column: i } = t.target.position, s = this.editor.getModel(), n = Math.max(0, i - 1), r = s ? s.getLineContent(e) ?? "" : "", a = s ?
|
|
2361
|
+
const { lineNumber: e, column: i } = t.target.position, s = this.editor.getModel(), n = Math.max(0, i - 1), r = s ? s.getLineContent(e) ?? "" : "", a = s ? _(r, n) : n;
|
|
2304
2362
|
this.sendNotify("nvim_win_set_cursor", [0, [e, a]]);
|
|
2305
2363
|
}
|
|
2306
2364
|
handleSelection(t) {
|
|
@@ -2308,7 +2366,7 @@ vim.opt.ei = ei
|
|
|
2308
2366
|
const e = t.selection;
|
|
2309
2367
|
if (e && t.source === "mouse") {
|
|
2310
2368
|
if (e.isEmpty()) {
|
|
2311
|
-
|
|
2369
|
+
w(this.lastMode) && this.sendInput("<Esc>");
|
|
2312
2370
|
return;
|
|
2313
2371
|
}
|
|
2314
2372
|
this.pendingSelection = new g.Selection(
|
|
@@ -2328,7 +2386,7 @@ vim.opt.ei = ei
|
|
|
2328
2386
|
if (this.delegateInsertToMonaco || !this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
2329
2387
|
const e = this.editor.getModel();
|
|
2330
2388
|
if (!e) return;
|
|
2331
|
-
const i = t.selectionStartLineNumber, s = Math.max(0, t.selectionStartColumn - 1), n = t.positionLineNumber, r = Math.max(0, t.positionColumn - 1), a = e.getLineContent(i) ?? "",
|
|
2389
|
+
const i = t.selectionStartLineNumber, s = Math.max(0, t.selectionStartColumn - 1), n = t.positionLineNumber, r = Math.max(0, t.positionColumn - 1), a = e.getLineContent(i) ?? "", u = e.getLineContent(n) ?? "", d = _(a, s), f = _(u, r);
|
|
2332
2390
|
await this.execLua(`
|
|
2333
2391
|
local api = vim.api
|
|
2334
2392
|
local fn = vim.fn
|
|
@@ -2341,7 +2399,7 @@ end
|
|
|
2341
2399
|
api.nvim_win_set_cursor(0, { a_line, a_col0 })
|
|
2342
2400
|
api.nvim_feedkeys("v", "n", false)
|
|
2343
2401
|
api.nvim_win_set_cursor(0, { b_line, b_col0 })
|
|
2344
|
-
`, [i,
|
|
2402
|
+
`, [i, d, n, f]);
|
|
2345
2403
|
}
|
|
2346
2404
|
sendInput(t) {
|
|
2347
2405
|
this.sendNotify("nvim_input", [t]);
|
|
@@ -2396,7 +2454,12 @@ api.nvim_win_set_cursor(0, { b_line, b_col0 })
|
|
|
2396
2454
|
this.sendNotify("nvim_paste", [e, i, -1]);
|
|
2397
2455
|
}
|
|
2398
2456
|
handleMonacoModelChange(t) {
|
|
2399
|
-
if (!this.delegateInsertToMonaco
|
|
2457
|
+
if (!this.delegateInsertToMonaco) {
|
|
2458
|
+
if (this.applyingFromNvim || !this.session || !this.session.isRunning() || !this.bufHandle || this.compositionActive || t?.isComposing) return;
|
|
2459
|
+
t?.changes?.length && this.scheduleResync();
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
if (this.applyingFromNvim || !this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
2400
2463
|
const e = this.editor.getModel();
|
|
2401
2464
|
if (!e) return;
|
|
2402
2465
|
const i = this.ensureActiveState();
|
|
@@ -2415,16 +2478,14 @@ api.nvim_win_set_cursor(0, { b_line, b_col0 })
|
|
|
2415
2478
|
i.pendingFullSync = !0, i.pendingCursorSync = !0, i.shadowLines = e.getLinesContent(), this.scheduleFlushPendingMonacoSync();
|
|
2416
2479
|
return;
|
|
2417
2480
|
}
|
|
2418
|
-
const
|
|
2481
|
+
const u = i.shadowLines[r] ?? "", d = i.shadowLines[a] ?? "", f = Math.max(0, n.startColumn - 1), l = Math.max(0, n.endColumn - 1), c = _(u, f), h = _(d, l), m = String(s.text ?? ""), p = m.length ? m.split(/\r?\n/) : [];
|
|
2419
2482
|
try {
|
|
2420
|
-
const
|
|
2483
|
+
const y = Math.max(0, Number(s.rangeLength ?? 0) || 0);
|
|
2421
2484
|
r === a && !m.includes(`
|
|
2422
|
-
`) ? (
|
|
2485
|
+
`) ? (y > 0 && (this.dotRepeatBackspaces += y, this.dotRepeatKeys += "<BS>".repeat(y)), m && (this.dotRepeatKeys += k(m, !0)), this.dotRepeatKeys.length > 2e4 && (this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0)) : (this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0);
|
|
2423
2486
|
} catch {
|
|
2424
2487
|
}
|
|
2425
|
-
i.pendingBufEdits.push({ startRow: r, startColByte:
|
|
2426
|
-
const y = typeof performance < "u" && performance.now ? performance.now() : Date.now();
|
|
2427
|
-
this.ignoreNvimBufLinesUntil = y + Math.max(80, (this.opts.insertSyncDebounceMs || 20) * 4), this.scheduleFlushPendingMonacoSync();
|
|
2488
|
+
i.pendingBufEdits.push({ startRow: r, startColByte: c, endRow: a, endColByte: h, lines: p }), ye(i.shadowLines, r, f, a, l, m), i.pendingCursorSync = !0, this.scheduleFlushPendingMonacoSync();
|
|
2428
2489
|
}
|
|
2429
2490
|
scheduleCursorSyncToNvim() {
|
|
2430
2491
|
if (!this.delegateInsertToMonaco) return;
|
|
@@ -2459,7 +2520,7 @@ api.nvim_win_set_cursor(0, { b_line, b_col0 })
|
|
|
2459
2520
|
if (!this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
2460
2521
|
const t = this.editor.getModel(), e = this.editor.getPosition();
|
|
2461
2522
|
if (!t || !e) return;
|
|
2462
|
-
const i = e.lineNumber, s = t.getLineContent(i) ?? "", n =
|
|
2523
|
+
const i = e.lineNumber, s = t.getLineContent(i) ?? "", n = _(s, Math.max(0, e.column - 1));
|
|
2463
2524
|
this.sendNotify("nvim_win_set_cursor", [0, [i, n]]);
|
|
2464
2525
|
}
|
|
2465
2526
|
scheduleVisualSelectionRefresh() {
|
|
@@ -2606,8 +2667,8 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2606
2667
|
let a = typeof i.path == "string" ? String(i.path) : "";
|
|
2607
2668
|
if (!a)
|
|
2608
2669
|
try {
|
|
2609
|
-
const
|
|
2610
|
-
typeof
|
|
2670
|
+
const u = await this.rpcCall("nvim_buf_get_name", [0]);
|
|
2671
|
+
typeof u == "string" && (a = u);
|
|
2611
2672
|
} catch {
|
|
2612
2673
|
}
|
|
2613
2674
|
if (a || (a = this.opts.seedName), !s.writeFile) {
|
|
@@ -2624,10 +2685,10 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2624
2685
|
await this.rpcCall("nvim_buf_set_option", [0, "modified", !1]);
|
|
2625
2686
|
} catch {
|
|
2626
2687
|
}
|
|
2627
|
-
const
|
|
2628
|
-
|
|
2629
|
-
} catch (
|
|
2630
|
-
this.opts.status(`write failed: ${
|
|
2688
|
+
const u = this.getActiveState();
|
|
2689
|
+
u && (u.name && u.name !== a && this.buffersByName.delete(u.name), u.name = a, this.buffersByName.set(a, u.id)), this.opts.status(`written: ${a}`), e === "wq" && this.opts.status("wq requested (provide onHostCommand to close the editor)");
|
|
2690
|
+
} catch (u) {
|
|
2691
|
+
this.opts.status(`write failed: ${u?.message ?? u}`, !0);
|
|
2631
2692
|
}
|
|
2632
2693
|
return;
|
|
2633
2694
|
}
|
|
@@ -2650,12 +2711,12 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2650
2711
|
}
|
|
2651
2712
|
let a = [""];
|
|
2652
2713
|
try {
|
|
2653
|
-
const
|
|
2654
|
-
Array.isArray(
|
|
2714
|
+
const c = await this.rpcCall("nvim_buf_get_lines", [e, 0, -1, !1]);
|
|
2715
|
+
Array.isArray(c) && (a = c.map((h) => String(h ?? "")));
|
|
2655
2716
|
} catch {
|
|
2656
2717
|
}
|
|
2657
|
-
const
|
|
2658
|
-
`), f = s && g.languages.getLanguages().some((
|
|
2718
|
+
const u = g.Uri.from({ scheme: "nvim", authority: "buf", path: `/${e}` }), d = a.join(`
|
|
2719
|
+
`), f = s && g.languages.getLanguages().some((c) => c.id === s), l = g.editor.createModel(d, f ? s : void 0, u);
|
|
2659
2720
|
n = {
|
|
2660
2721
|
id: e,
|
|
2661
2722
|
name: i || "",
|
|
@@ -2704,7 +2765,7 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2704
2765
|
if (!n)
|
|
2705
2766
|
try {
|
|
2706
2767
|
const r = await this.rpcCall("nvim_create_buf", [!0, !1]);
|
|
2707
|
-
n =
|
|
2768
|
+
n = x(r) ?? Number(r);
|
|
2708
2769
|
} catch {
|
|
2709
2770
|
n = null;
|
|
2710
2771
|
}
|
|
@@ -2789,8 +2850,8 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2789
2850
|
if (Array.isArray(e) && e.length >= 2) {
|
|
2790
2851
|
const i = Number(e[0]), s = Number(e[1]), n = B(this.editor, i, s), r = new g.Position(n.line, n.col), a = typeof performance < "u" && performance.now ? performance.now() : Date.now();
|
|
2791
2852
|
if (this.optimisticCursorPos && this.optimisticCursorUntil > a) {
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2853
|
+
const u = this.optimisticCursorPrevPos;
|
|
2854
|
+
u && r.lineNumber === u.lineNumber && r.column === u.column || r.lineNumber < this.optimisticCursorPos.lineNumber || r.lineNumber === this.optimisticCursorPos.lineNumber && r.column < this.optimisticCursorPos.column || (this.optimisticCursorPos = null, this.optimisticCursorPrevPos = null, this.optimisticCursorUntil = 0, this.updateCursor(r.lineNumber, r.column));
|
|
2794
2855
|
} else
|
|
2795
2856
|
this.optimisticCursorPos = null, this.optimisticCursorPrevPos = null, this.optimisticCursorUntil = 0, this.updateCursor(r.lineNumber, r.column);
|
|
2796
2857
|
}
|
|
@@ -2814,7 +2875,7 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2814
2875
|
s === this.lastCursorStyle && n === this.lastCursorBlink && r === this.lastCursorWidth || (this.editor.updateOptions({ cursorStyle: s, cursorBlinking: n, cursorWidth: r }), this.lastCursorStyle = s, this.lastCursorBlink = n, this.lastCursorWidth = r);
|
|
2815
2876
|
}
|
|
2816
2877
|
async updateVisualSelection(t) {
|
|
2817
|
-
const e =
|
|
2878
|
+
const e = w(t), i = ++this.visualSelectionToken;
|
|
2818
2879
|
if (!e) {
|
|
2819
2880
|
this.clearVisualDecorations();
|
|
2820
2881
|
return;
|
|
@@ -2859,7 +2920,7 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2859
2920
|
return null;
|
|
2860
2921
|
}
|
|
2861
2922
|
async seedBuffer(t, e) {
|
|
2862
|
-
const i =
|
|
2923
|
+
const i = x(t);
|
|
2863
2924
|
if (!i || i <= 0) return null;
|
|
2864
2925
|
const s = e ?? this.opts.seedLines;
|
|
2865
2926
|
if (!s || !s.length) return null;
|
|
@@ -2870,13 +2931,13 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2870
2931
|
}
|
|
2871
2932
|
}
|
|
2872
2933
|
}
|
|
2873
|
-
function
|
|
2934
|
+
function Ce(o, t = {}) {
|
|
2874
2935
|
return new le(o, t);
|
|
2875
2936
|
}
|
|
2876
2937
|
function M(o, t, e) {
|
|
2877
2938
|
return Math.min(Math.max(o, t), e);
|
|
2878
2939
|
}
|
|
2879
|
-
function
|
|
2940
|
+
function A(o) {
|
|
2880
2941
|
try {
|
|
2881
2942
|
return new TextEncoder().encode(String(o ?? "")).length;
|
|
2882
2943
|
} catch {
|
|
@@ -2887,10 +2948,10 @@ function B(o, t, e) {
|
|
|
2887
2948
|
const i = Math.max(1, Number(t) || 1), s = Math.max(1, (Number(e) || 0) + 1), n = o.getModel();
|
|
2888
2949
|
if (!n)
|
|
2889
2950
|
return { line: i, col: s };
|
|
2890
|
-
const r = n.getLineCount(), a = M(i, 1, r),
|
|
2891
|
-
return { line: a, col:
|
|
2951
|
+
const r = n.getLineCount(), a = M(i, 1, r), u = n.getLineContent(a) ?? "", d = n.getLineMaxColumn(a), f = Math.max(0, Number(e) || 0), l = S(u, f), c = M(l + 1, 1, d);
|
|
2952
|
+
return { line: a, col: c };
|
|
2892
2953
|
}
|
|
2893
|
-
function
|
|
2954
|
+
function k(o, t = !0) {
|
|
2894
2955
|
const e = String(o ?? "");
|
|
2895
2956
|
if (!e) return "";
|
|
2896
2957
|
const i = e.replace(/\r\n/g, `
|
|
@@ -2901,65 +2962,65 @@ function L(o, t = !0) {
|
|
|
2901
2962
|
function ce(o) {
|
|
2902
2963
|
const t = o.key;
|
|
2903
2964
|
if (!t || t === "Dead" || t === "Unidentified") return null;
|
|
2904
|
-
const e = !!o.getModifierState?.("AltGraph"), i = o.ctrlKey && !e, s = o.altKey && !e, n = o.metaKey && !e, r = o.shiftKey, a = (l) => l === "<" ? "lt" : l,
|
|
2905
|
-
const
|
|
2906
|
-
i &&
|
|
2965
|
+
const e = !!o.getModifierState?.("AltGraph"), i = o.ctrlKey && !e, s = o.altKey && !e, n = o.metaKey && !e, r = o.shiftKey, a = (l) => l === "<" ? "lt" : l, u = (l) => l === "<" ? "<lt>" : l, d = (l, c = !1) => {
|
|
2966
|
+
const h = [];
|
|
2967
|
+
i && h.push("C-"), c && r && h.push("S-"), s && h.push("A-"), n && h.push("D-");
|
|
2907
2968
|
const m = a(l);
|
|
2908
|
-
return
|
|
2969
|
+
return h.length ? `<${h.join("")}${m}>` : `<${m}>`;
|
|
2909
2970
|
};
|
|
2910
2971
|
if (typeof o.code == "string" && o.code.startsWith("Numpad") || typeof KeyboardEvent?.DOM_KEY_LOCATION_NUMPAD == "number" && o.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD) {
|
|
2911
2972
|
switch (o.code) {
|
|
2912
2973
|
case "NumpadEnter":
|
|
2913
|
-
return
|
|
2974
|
+
return d("kEnter", !0);
|
|
2914
2975
|
case "NumpadAdd":
|
|
2915
|
-
return
|
|
2976
|
+
return d("kPlus", !0);
|
|
2916
2977
|
case "NumpadSubtract":
|
|
2917
|
-
return
|
|
2978
|
+
return d("kMinus", !0);
|
|
2918
2979
|
case "NumpadMultiply":
|
|
2919
|
-
return
|
|
2980
|
+
return d("kMultiply", !0);
|
|
2920
2981
|
case "NumpadDivide":
|
|
2921
|
-
return
|
|
2982
|
+
return d("kDivide", !0);
|
|
2922
2983
|
case "NumpadDecimal":
|
|
2923
|
-
return
|
|
2984
|
+
return d("kPoint", !0);
|
|
2924
2985
|
}
|
|
2925
|
-
if (/^\d$/.test(t)) return
|
|
2986
|
+
if (/^\d$/.test(t)) return d(`k${t}`, !0);
|
|
2926
2987
|
}
|
|
2927
2988
|
switch (t) {
|
|
2928
2989
|
case "Backspace":
|
|
2929
|
-
return
|
|
2990
|
+
return d("BS", !0);
|
|
2930
2991
|
case "Enter":
|
|
2931
|
-
return
|
|
2992
|
+
return d("CR", !0);
|
|
2932
2993
|
case "Escape":
|
|
2933
|
-
return
|
|
2994
|
+
return d("Esc", !0);
|
|
2934
2995
|
case "Tab":
|
|
2935
|
-
return r && !i && !s && !n ? "<S-Tab>" :
|
|
2996
|
+
return r && !i && !s && !n ? "<S-Tab>" : d("Tab", !0);
|
|
2936
2997
|
case "ArrowUp":
|
|
2937
|
-
return
|
|
2998
|
+
return d("Up", !0);
|
|
2938
2999
|
case "ArrowDown":
|
|
2939
|
-
return
|
|
3000
|
+
return d("Down", !0);
|
|
2940
3001
|
case "ArrowLeft":
|
|
2941
|
-
return
|
|
3002
|
+
return d("Left", !0);
|
|
2942
3003
|
case "ArrowRight":
|
|
2943
|
-
return
|
|
3004
|
+
return d("Right", !0);
|
|
2944
3005
|
case "Delete":
|
|
2945
|
-
return
|
|
3006
|
+
return d("Del", !0);
|
|
2946
3007
|
case "Home":
|
|
2947
|
-
return
|
|
3008
|
+
return d("Home", !0);
|
|
2948
3009
|
case "End":
|
|
2949
|
-
return
|
|
3010
|
+
return d("End", !0);
|
|
2950
3011
|
case "PageUp":
|
|
2951
|
-
return
|
|
3012
|
+
return d("PageUp", !0);
|
|
2952
3013
|
case "PageDown":
|
|
2953
|
-
return
|
|
3014
|
+
return d("PageDown", !0);
|
|
2954
3015
|
case "Insert":
|
|
2955
|
-
return
|
|
3016
|
+
return d("Insert", !0);
|
|
2956
3017
|
}
|
|
2957
|
-
if (/^F\d{1,2}$/.test(t)) return
|
|
3018
|
+
if (/^F\d{1,2}$/.test(t)) return d(t, !0);
|
|
2958
3019
|
if (t.length === 1) {
|
|
2959
|
-
if (!i && !s && !n) return
|
|
3020
|
+
if (!i && !s && !n) return u(t);
|
|
2960
3021
|
if (t === " " && i && !s && !n) return "<Nul>";
|
|
2961
|
-
const l = /^[A-Za-z]$/.test(t) ? t.toLowerCase() : t,
|
|
2962
|
-
return `<${(i ? "C-" : "") + (s ? "A-" : "") + (n ? "D-" : "")}${
|
|
3022
|
+
const l = /^[A-Za-z]$/.test(t) ? t.toLowerCase() : t, c = a(l);
|
|
3023
|
+
return `<${(i ? "C-" : "") + (s ? "A-" : "") + (n ? "D-" : "")}${c}>`;
|
|
2963
3024
|
}
|
|
2964
3025
|
return null;
|
|
2965
3026
|
}
|
|
@@ -2993,7 +3054,7 @@ function ue(o) {
|
|
|
2993
3054
|
function he(o) {
|
|
2994
3055
|
return o instanceof Uint8Array ? o : o instanceof ArrayBuffer ? new Uint8Array(o) : Array.isArray(o) ? new Uint8Array(o) : Number.isInteger(o) ? new Uint8Array([o & 255]) : o && o.type === "Buffer" && Array.isArray(o.data) ? new Uint8Array(o.data) : null;
|
|
2995
3056
|
}
|
|
2996
|
-
function
|
|
3057
|
+
function x(o) {
|
|
2997
3058
|
if (o && typeof o == "object" && typeof o.type == "number") {
|
|
2998
3059
|
const e = he(o.data);
|
|
2999
3060
|
if (e) {
|
|
@@ -3004,27 +3065,27 @@ function S(o) {
|
|
|
3004
3065
|
const t = Number(o);
|
|
3005
3066
|
return Number.isInteger(t) && t > 0 ? t : null;
|
|
3006
3067
|
}
|
|
3007
|
-
function
|
|
3068
|
+
function S(o, t) {
|
|
3008
3069
|
let e = 0, i = 0;
|
|
3009
3070
|
const s = Math.max(0, Number(t) || 0);
|
|
3010
3071
|
for (; e < s; ) {
|
|
3011
3072
|
if (i >= o.length)
|
|
3012
3073
|
return i + (s - e);
|
|
3013
|
-
const n = o.codePointAt(i), r =
|
|
3074
|
+
const n = o.codePointAt(i), r = L(n ?? 0);
|
|
3014
3075
|
e += r, i += r === 4 ? 2 : 1;
|
|
3015
3076
|
}
|
|
3016
3077
|
return i;
|
|
3017
3078
|
}
|
|
3018
|
-
function
|
|
3079
|
+
function _(o, t) {
|
|
3019
3080
|
const e = Math.max(0, Number(t) || 0);
|
|
3020
3081
|
let i = 0, s = 0;
|
|
3021
3082
|
for (; s < e && s < o.length; ) {
|
|
3022
|
-
const n = o.codePointAt(s), r =
|
|
3083
|
+
const n = o.codePointAt(s), r = L(n ?? 0);
|
|
3023
3084
|
i += r, s += r === 4 ? 2 : 1;
|
|
3024
3085
|
}
|
|
3025
3086
|
return i;
|
|
3026
3087
|
}
|
|
3027
|
-
function
|
|
3088
|
+
function L(o) {
|
|
3028
3089
|
return o == null ? 0 : o <= 127 ? 1 : o <= 2047 ? 2 : o >= 55296 && o <= 57343 ? 4 : o < 65535 ? 3 : 4;
|
|
3029
3090
|
}
|
|
3030
3091
|
function de(o) {
|
|
@@ -3044,16 +3105,16 @@ function F(o, t, e) {
|
|
|
3044
3105
|
const n = i.getLineContent(s) ?? "", r = Math.max(0, Number(t.col) || 0);
|
|
3045
3106
|
let a = r;
|
|
3046
3107
|
if (e) {
|
|
3047
|
-
const f =
|
|
3108
|
+
const f = S(n, r);
|
|
3048
3109
|
if (f < n.length) {
|
|
3049
3110
|
const l = n.codePointAt(f);
|
|
3050
|
-
a = r +
|
|
3111
|
+
a = r + L(l ?? 0);
|
|
3051
3112
|
}
|
|
3052
3113
|
}
|
|
3053
|
-
const
|
|
3054
|
-
return { lineNumber: s, column: M(
|
|
3114
|
+
const u = S(n, a) + 1, d = i.getLineMaxColumn(s);
|
|
3115
|
+
return { lineNumber: s, column: M(u, 1, d) };
|
|
3055
3116
|
}
|
|
3056
|
-
function
|
|
3117
|
+
function w(o) {
|
|
3057
3118
|
const t = typeof o == "string" ? o : "";
|
|
3058
3119
|
return t.includes("v") || t.includes("V") || t.includes("") || t.includes("s") || t.includes("S") || t.includes("");
|
|
3059
3120
|
}
|
|
@@ -3087,7 +3148,7 @@ function K(o) {
|
|
|
3087
3148
|
function pe(o) {
|
|
3088
3149
|
return `#${Number(o >>> 0).toString(16).padStart(6, "0").slice(-6)}`;
|
|
3089
3150
|
}
|
|
3090
|
-
function
|
|
3151
|
+
function C(o, t, e, i) {
|
|
3091
3152
|
return o.addEventListener(t, e, i), { dispose: () => o.removeEventListener(t, e, i) };
|
|
3092
3153
|
}
|
|
3093
3154
|
function $(o) {
|
|
@@ -3098,22 +3159,22 @@ function ge(o) {
|
|
|
3098
3159
|
const t = typeof o == "string" ? o : "";
|
|
3099
3160
|
return t.length ? t[t.length - 1] : "";
|
|
3100
3161
|
}
|
|
3101
|
-
function
|
|
3162
|
+
function v(o) {
|
|
3102
3163
|
const t = typeof o == "string" ? o : "";
|
|
3103
3164
|
return t === "c" || t.startsWith("c");
|
|
3104
3165
|
}
|
|
3105
3166
|
function ye(o, t, e, i, s, n) {
|
|
3106
|
-
const r = o[t] ?? "", a = o[i] ?? "",
|
|
3107
|
-
let
|
|
3167
|
+
const r = o[t] ?? "", a = o[i] ?? "", u = r.slice(0, Math.max(0, e)), d = a.slice(Math.max(0, s)), l = String(n ?? "").split(/\r?\n/);
|
|
3168
|
+
let c;
|
|
3108
3169
|
if (l.length <= 1)
|
|
3109
|
-
|
|
3170
|
+
c = [`${u}${l[0] ?? ""}${d}`];
|
|
3110
3171
|
else {
|
|
3111
|
-
const
|
|
3112
|
-
|
|
3172
|
+
const h = `${u}${l[0] ?? ""}`, m = `${l[l.length - 1] ?? ""}${d}`, p = l.slice(1, -1);
|
|
3173
|
+
c = [h, ...p, m];
|
|
3113
3174
|
}
|
|
3114
|
-
o.splice(t, Math.max(0, i - t + 1), ...
|
|
3175
|
+
o.splice(t, Math.max(0, i - t + 1), ...c);
|
|
3115
3176
|
}
|
|
3116
|
-
function
|
|
3177
|
+
function T(o) {
|
|
3117
3178
|
if (!o) return "";
|
|
3118
3179
|
if (typeof o == "string") return o;
|
|
3119
3180
|
if (!Array.isArray(o)) return "";
|
|
@@ -3124,7 +3185,7 @@ function N(o) {
|
|
|
3124
3185
|
continue;
|
|
3125
3186
|
}
|
|
3126
3187
|
if (Array.isArray(e)) {
|
|
3127
|
-
typeof e[1] == "string" ? t += e[1] : typeof e[0] == "string" ? t += e[0] : t +=
|
|
3188
|
+
typeof e[1] == "string" ? t += e[1] : typeof e[0] == "string" ? t += e[0] : t += T(e);
|
|
3128
3189
|
continue;
|
|
3129
3190
|
}
|
|
3130
3191
|
e && typeof e == "object" && typeof e.text == "string" && (t += e.text);
|
|
@@ -3151,12 +3212,12 @@ function be(o) {
|
|
|
3151
3212
|
}
|
|
3152
3213
|
return t.filter((e) => e.word.length > 0);
|
|
3153
3214
|
}
|
|
3154
|
-
const
|
|
3215
|
+
const _e = new URL("./nvimWorker.js", import.meta.url), we = new URL("./nvimWorkerAsyncify.js", import.meta.url);
|
|
3155
3216
|
export {
|
|
3156
3217
|
le as MonacoNeovimClient,
|
|
3157
3218
|
te as NeovimWasmSession,
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3219
|
+
Ce as createMonacoNeovim,
|
|
3220
|
+
_e as defaultWorkerUrl,
|
|
3221
|
+
we as defaultWorkerUrlAsyncify,
|
|
3222
|
+
Z as isSharedArrayBufferAvailable
|
|
3162
3223
|
};
|