@monaco-neovim-wasm/lib 0.1.7 → 0.1.9
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 +790 -529
- package/dist/monacoNeovim.d.ts +31 -0
- package/dist/nvimWorker.js +1548 -229
- package/dist/nvimWorkerAsyncify.js +1608 -289
- package/package.json +2 -2
- package/dist/msgpack-BSNDwQ9a.js +0 -1351
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
class
|
|
1
|
+
import * as g from "monaco-editor";
|
|
2
|
+
class U {
|
|
3
3
|
buffer;
|
|
4
4
|
ctrl;
|
|
5
5
|
data;
|
|
6
6
|
capacity;
|
|
7
|
-
constructor(t =
|
|
7
|
+
constructor(t = R) {
|
|
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) {
|
|
11
11
|
let e;
|
|
12
12
|
if (t instanceof Uint8Array ? e = t : t instanceof ArrayBuffer || t instanceof SharedArrayBuffer ? e = new Uint8Array(t) : e = new Uint8Array(t), !e.byteLength) return !0;
|
|
13
|
-
const i = Atomics.load(this.ctrl, 0), s = Atomics.load(this.ctrl, 1), n = s >= i ? s - i : this.capacity - (i - s),
|
|
14
|
-
if (e.byteLength >
|
|
15
|
-
const
|
|
16
|
-
return e.byteLength <=
|
|
13
|
+
const i = Atomics.load(this.ctrl, 0), s = Atomics.load(this.ctrl, 1), n = s >= i ? s - i : this.capacity - (i - s), r = this.capacity - n - 1;
|
|
14
|
+
if (e.byteLength > r) return !1;
|
|
15
|
+
const a = this.capacity - s;
|
|
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 R = 262144;
|
|
20
|
+
function V(o = R) {
|
|
21
|
+
return new U(o);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function A(o) {
|
|
24
24
|
const t = [];
|
|
25
|
-
return
|
|
25
|
+
return T(o, t), new Uint8Array(t);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
if (
|
|
27
|
+
function T(o, t) {
|
|
28
|
+
if (o == null) {
|
|
29
29
|
t.push(192);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
if (typeof
|
|
33
|
-
t.push(
|
|
32
|
+
if (typeof o == "boolean") {
|
|
33
|
+
t.push(o ? 195 : 194);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
if (typeof
|
|
37
|
-
|
|
36
|
+
if (typeof o == "number") {
|
|
37
|
+
Q(o, t);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
if (typeof
|
|
41
|
-
|
|
40
|
+
if (typeof o == "string") {
|
|
41
|
+
q(o, t);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
if (typeof
|
|
45
|
-
|
|
44
|
+
if (typeof o == "bigint") {
|
|
45
|
+
O(o, t);
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
if (Array.isArray(
|
|
49
|
-
|
|
48
|
+
if (Array.isArray(o)) {
|
|
49
|
+
G(o, t);
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
52
|
+
if (o instanceof Uint8Array) {
|
|
53
|
+
j(o, t);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
56
|
+
if (Z(o)) {
|
|
57
|
+
Y(o, t);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
if (typeof
|
|
61
|
-
|
|
60
|
+
if (typeof o == "object") {
|
|
61
|
+
J(o, t);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
throw new Error("Unsupported type in msgpack encode");
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
if (!Number.isFinite(
|
|
68
|
-
if (Number.isInteger(
|
|
69
|
-
if (
|
|
70
|
-
t.push(
|
|
66
|
+
function Q(o, t) {
|
|
67
|
+
if (!Number.isFinite(o)) throw new Error("Cannot encode non-finite number");
|
|
68
|
+
if (Number.isInteger(o)) {
|
|
69
|
+
if (o >= 0 && o <= 127) {
|
|
70
|
+
t.push(o);
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
if (
|
|
74
|
-
t.push(224 |
|
|
73
|
+
if (o < 0 && o >= -32) {
|
|
74
|
+
t.push(224 | o + 32);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
if (
|
|
78
|
-
t.push(208,
|
|
77
|
+
if (o >= -128 && o <= 127) {
|
|
78
|
+
t.push(208, o + 256 & 255);
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
82
|
-
t.push(209,
|
|
81
|
+
if (o >= -32768 && o <= 32767) {
|
|
82
|
+
t.push(209, o >> 8 & 255, o & 255);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
86
|
-
t.push(210,
|
|
85
|
+
if (o >= -2147483648 && o <= 2147483647) {
|
|
86
|
+
t.push(210, o >> 24 & 255, o >> 16 & 255, o >> 8 & 255, o & 255);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
O(BigInt(o), t);
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
const e = new ArrayBuffer(8);
|
|
93
|
-
new DataView(e).setFloat64(0,
|
|
93
|
+
new DataView(e).setFloat64(0, o), t.push(203, ...new Uint8Array(e));
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function O(o, t) {
|
|
96
96
|
const e = new ArrayBuffer(8);
|
|
97
|
-
new DataView(e).setBigInt64(0, BigInt(
|
|
97
|
+
new DataView(e).setBigInt64(0, BigInt(o)), t.push(211, ...new Uint8Array(e));
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
const i = new TextEncoder().encode(
|
|
99
|
+
function q(o, t) {
|
|
100
|
+
const i = new TextEncoder().encode(o), s = i.length;
|
|
101
101
|
s <= 31 ? t.push(160 | s) : s <= 255 ? t.push(217, s) : s <= 65535 ? t.push(218, s >> 8 & 255, s & 255) : t.push(219, s >> 24 & 255, s >> 16 & 255, s >> 8 & 255, s & 255), t.push(...i);
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const e =
|
|
105
|
-
e <= 255 ? t.push(196, e) : e <= 65535 ? t.push(197, e >> 8 & 255, e & 255) : t.push(198, e >> 24 & 255, e >> 16 & 255, e >> 8 & 255, e & 255), t.push(...
|
|
103
|
+
function j(o, t) {
|
|
104
|
+
const e = o.length;
|
|
105
|
+
e <= 255 ? t.push(196, e) : e <= 65535 ? t.push(197, e >> 8 & 255, e & 255) : t.push(198, e >> 24 & 255, e >> 16 & 255, e >> 8 & 255, e & 255), t.push(...o);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
const e =
|
|
107
|
+
function G(o, t) {
|
|
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
|
-
for (const i of
|
|
111
|
-
|
|
110
|
+
for (const i of o)
|
|
111
|
+
T(i, t);
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
const e = Object.keys(
|
|
113
|
+
function J(o, t) {
|
|
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
|
+
T(s, t), T(o[s], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
const e =
|
|
121
|
-
e === 1 ? t.push(212,
|
|
119
|
+
function Y(o, t) {
|
|
120
|
+
const e = o.data.length;
|
|
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
|
-
t.push(
|
|
123
|
+
t.push(o.data[i]);
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
return !!(
|
|
125
|
+
function Z(o) {
|
|
126
|
+
return !!(o && typeof o == "object" && typeof o.type == "number" && o.data instanceof Uint8Array);
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function X() {
|
|
129
129
|
return typeof SharedArrayBuffer < "u" && typeof crossOriginIsolated < "u" && crossOriginIsolated;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
131
|
+
function ee(o) {
|
|
132
|
+
return o.byteOffset === 0 && o.byteLength === o.buffer.byteLength ? o : o.slice();
|
|
133
133
|
}
|
|
134
|
-
class
|
|
134
|
+
class te {
|
|
135
135
|
init;
|
|
136
136
|
worker = null;
|
|
137
137
|
sharedInput = null;
|
|
@@ -149,7 +149,7 @@ class Y {
|
|
|
149
149
|
worker: t.worker ?? null,
|
|
150
150
|
workerUrl: t.workerUrl ?? null,
|
|
151
151
|
createWorker: t.createWorker ?? null,
|
|
152
|
-
sharedInputBytes: t.sharedInputBytes ??
|
|
152
|
+
sharedInputBytes: t.sharedInputBytes ?? R,
|
|
153
153
|
inputMode: t.inputMode ?? "shared",
|
|
154
154
|
rpcTimeoutMs: t.rpcTimeoutMs ?? 8e3,
|
|
155
155
|
maxQueuedBytes: t.maxQueuedBytes ?? 4 * 1024 * 1024,
|
|
@@ -167,26 +167,26 @@ class Y {
|
|
|
167
167
|
return this.workerExitCode;
|
|
168
168
|
}
|
|
169
169
|
async start(t) {
|
|
170
|
-
const { cols: e, rows: i, wasmPath: s, runtimePath: n, env:
|
|
171
|
-
if (this.inputMode = t.inputMode ?? this.init.inputMode, this.inputMode === "shared" && !
|
|
170
|
+
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" && !X())
|
|
172
172
|
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
|
|
173
|
+
const c = this.worker;
|
|
174
|
+
if (this.stop({ terminate: !this.init.reuseWorker, silent: !0 }), this.sharedInput = this.inputMode === "shared" ? V(this.init.sharedInputBytes) : null, this.workerExited = !1, this.workerExitCode = 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 && c ? this.worker = c : this.worker = this.init.workerUrl ? new Worker(this.init.workerUrl, { type: "module" }) : null, !this.worker) throw new Error("worker/workerUrl is required");
|
|
175
|
+
this.worker.onmessage = (f) => this.handleWorkerMessage(f.data);
|
|
176
|
+
const h = {
|
|
177
177
|
type: "start",
|
|
178
178
|
cols: Number(e) || 80,
|
|
179
179
|
rows: Number(i) || 24,
|
|
180
180
|
wasmPath: String(s ?? ""),
|
|
181
181
|
runtimePath: String(n ?? ""),
|
|
182
182
|
inputBuffer: this.sharedInput?.buffer ?? null,
|
|
183
|
-
env:
|
|
184
|
-
files:
|
|
183
|
+
env: r ?? void 0,
|
|
184
|
+
files: a ?? void 0
|
|
185
185
|
};
|
|
186
186
|
try {
|
|
187
|
-
this.worker.postMessage(
|
|
187
|
+
this.worker.postMessage(h, []);
|
|
188
188
|
} catch {
|
|
189
|
-
this.worker.postMessage(
|
|
189
|
+
this.worker.postMessage(h);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
stop(t = {}) {
|
|
@@ -211,7 +211,7 @@ class Y {
|
|
|
211
211
|
}
|
|
212
212
|
notify(t, e = []) {
|
|
213
213
|
if (!this.worker || this.workerExited) return;
|
|
214
|
-
const i =
|
|
214
|
+
const i = A([2, t, e]);
|
|
215
215
|
this.postInput(i);
|
|
216
216
|
}
|
|
217
217
|
call(t, e = []) {
|
|
@@ -221,14 +221,14 @@ class Y {
|
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
223
|
if (this.workerExited) {
|
|
224
|
-
const
|
|
225
|
-
s(new Error(
|
|
224
|
+
const a = this.workerExitCode;
|
|
225
|
+
s(new Error(a != null ? `nvim exited (${a})` : "nvim exited"));
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
228
|
const n = this.reqId++;
|
|
229
229
|
this.pending.set(n, { resolve: i, reject: s, ts: Date.now(), method: t });
|
|
230
|
-
const
|
|
231
|
-
this.postInput(
|
|
230
|
+
const r = A([0, n, t, e]);
|
|
231
|
+
this.postInput(r), setTimeout(() => {
|
|
232
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}`)));
|
|
233
233
|
}, this.init.rpcTimeoutMs);
|
|
234
234
|
});
|
|
@@ -240,21 +240,21 @@ class Y {
|
|
|
240
240
|
await this.call("nvim_get_api_info", []);
|
|
241
241
|
return;
|
|
242
242
|
} catch {
|
|
243
|
-
await new Promise((
|
|
243
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
244
244
|
}
|
|
245
245
|
throw new Error("nvim_get_api_info timed out");
|
|
246
246
|
}
|
|
247
247
|
respond(t, e, i) {
|
|
248
248
|
if (!this.worker || this.workerExited) return;
|
|
249
|
-
const s =
|
|
249
|
+
const s = A([1, t, e, i]);
|
|
250
250
|
this.postInput(s);
|
|
251
251
|
}
|
|
252
252
|
handleWorkerMessage(t) {
|
|
253
253
|
const e = t?.type;
|
|
254
254
|
if (e === "rpc-response") {
|
|
255
|
-
const { msgid: i, error: s, result: n } = t,
|
|
256
|
-
if (!
|
|
257
|
-
this.pending.delete(i), s ?
|
|
255
|
+
const { msgid: i, error: s, result: n } = t, r = this.pending.get(i);
|
|
256
|
+
if (!r) return;
|
|
257
|
+
this.pending.delete(i), s ? r.reject(new Error(String(s))) : r.resolve(n);
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
260
|
if (e === "rpc-notify") {
|
|
@@ -308,8 +308,8 @@ class Y {
|
|
|
308
308
|
if (e === "exit") {
|
|
309
309
|
const i = t, s = i.code, n = i.lastStderr;
|
|
310
310
|
if (this.workerExited = !0, this.workerExitCode = s, this.pending.size) {
|
|
311
|
-
const
|
|
312
|
-
this.pending.forEach((
|
|
311
|
+
const r = n ? `: ${n.trim()}` : "", a = new Error(`nvim exited (${s})${r}`);
|
|
312
|
+
this.pending.forEach((c) => c.reject(a)), this.pending.clear();
|
|
313
313
|
}
|
|
314
314
|
try {
|
|
315
315
|
this.init.handlers.onExit?.(s, n);
|
|
@@ -319,7 +319,7 @@ class Y {
|
|
|
319
319
|
}
|
|
320
320
|
postInput(t) {
|
|
321
321
|
if (!t || !t.buffer) return;
|
|
322
|
-
const e =
|
|
322
|
+
const e = ee(t);
|
|
323
323
|
if (!(!this.worker || this.workerExited)) {
|
|
324
324
|
if (this.inputMode === "shared") {
|
|
325
325
|
if (!this.sharedInput || this.inputQueueHead >= this.inputQueue.length && this.sharedInput.push(e))
|
|
@@ -359,19 +359,19 @@ class Y {
|
|
|
359
359
|
}
|
|
360
360
|
} else {
|
|
361
361
|
let e = 0, i = 0;
|
|
362
|
-
for (let
|
|
363
|
-
const
|
|
364
|
-
if (
|
|
365
|
-
if (i > 0 && e +
|
|
366
|
-
e +=
|
|
362
|
+
for (let r = this.inputQueueHead; r < this.inputQueue.length; r += 1) {
|
|
363
|
+
const a = this.inputQueue[r];
|
|
364
|
+
if (a?.byteLength) {
|
|
365
|
+
if (i > 0 && e + a.byteLength > 262144) break;
|
|
366
|
+
e += a.byteLength, i += 1;
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
if (i <= 0 || e <= 0) return;
|
|
370
370
|
const s = new Uint8Array(e);
|
|
371
371
|
let n = 0;
|
|
372
|
-
for (let
|
|
373
|
-
const
|
|
374
|
-
s.set(
|
|
372
|
+
for (let r = 0; r < i; r += 1) {
|
|
373
|
+
const a = this.inputQueue[this.inputQueueHead + r];
|
|
374
|
+
s.set(a, n), n += a.byteLength;
|
|
375
375
|
}
|
|
376
376
|
this.inputQueueHead += i, this.inputQueuedBytes -= e, this.postStdin(s);
|
|
377
377
|
}
|
|
@@ -389,7 +389,7 @@ class Y {
|
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
|
-
const
|
|
392
|
+
const ie = `if !exists('g:monaco_neovim_wasm_chan')
|
|
393
393
|
finish
|
|
394
394
|
endif
|
|
395
395
|
|
|
@@ -452,7 +452,7 @@ onoremap <silent> gk <Cmd>call <SID>up_down('up')<CR>
|
|
|
452
452
|
nnoremap <silent> gj <Cmd>call <SID>up_down('down')<CR>
|
|
453
453
|
xnoremap <silent> gj <Cmd>call <SID>up_down('down')<CR>
|
|
454
454
|
onoremap <silent> gj <Cmd>call <SID>up_down('down')<CR>
|
|
455
|
-
`,
|
|
455
|
+
`, ne = `if !exists('g:monaco_neovim_wasm_chan')
|
|
456
456
|
finish
|
|
457
457
|
endif
|
|
458
458
|
|
|
@@ -553,7 +553,7 @@ onoremap <silent> <C-f> <Cmd>call <SID>scroll('down', 'page')<CR>
|
|
|
553
553
|
nnoremap <silent> <C-b> <Cmd>call <SID>scroll('up', 'page')<CR>
|
|
554
554
|
xnoremap <silent> <C-b> <Cmd>call <SID>scroll('up', 'page')<CR>
|
|
555
555
|
onoremap <silent> <C-b> <Cmd>call <SID>scroll('up', 'page')<CR>
|
|
556
|
-
`,
|
|
556
|
+
`, se = `if !exists('g:monaco_neovim_wasm_chan')
|
|
557
557
|
finish
|
|
558
558
|
endif
|
|
559
559
|
|
|
@@ -604,7 +604,7 @@ cnoreabbrev <expr> q <SID>abbr('q', 'MonacoQuit')
|
|
|
604
604
|
cnoreabbrev <expr> quit <SID>abbr('quit', 'MonacoQuit')
|
|
605
605
|
cnoreabbrev <expr> wq <SID>abbr('wq', 'MonacoWq')
|
|
606
606
|
cnoreabbrev <expr> x <SID>abbr('x', 'MonacoWq')
|
|
607
|
-
`,
|
|
607
|
+
`, re = [
|
|
608
608
|
"-- Monaco + Neovim (WASM)",
|
|
609
609
|
"-- Click into the editor, press i, and start typing.",
|
|
610
610
|
"",
|
|
@@ -613,7 +613,7 @@ cnoreabbrev <expr> x <SID>abbr('x', 'MonacoWq')
|
|
|
613
613
|
"end",
|
|
614
614
|
"",
|
|
615
615
|
"print(greet('monaco'))"
|
|
616
|
-
],
|
|
616
|
+
], oe = `
|
|
617
617
|
local api, fn = vim.api, vim.fn
|
|
618
618
|
|
|
619
619
|
local function virtcol2byte(winid, lnum, virtcol)
|
|
@@ -697,7 +697,7 @@ local function get_selections(win)
|
|
|
697
697
|
end
|
|
698
698
|
|
|
699
699
|
return get_selections(...)
|
|
700
|
-
`,
|
|
700
|
+
`, ae = `
|
|
701
701
|
local api, fn = vim.api, vim.fn
|
|
702
702
|
|
|
703
703
|
local function get_visible_range(s, e)
|
|
@@ -786,7 +786,7 @@ end
|
|
|
786
786
|
|
|
787
787
|
return run(...)
|
|
788
788
|
`;
|
|
789
|
-
class
|
|
789
|
+
class le {
|
|
790
790
|
editor;
|
|
791
791
|
opts;
|
|
792
792
|
session = null;
|
|
@@ -826,6 +826,8 @@ class se {
|
|
|
826
826
|
searchRefreshPending = !1;
|
|
827
827
|
execLuaAvailable = null;
|
|
828
828
|
visualSelectionRefreshTimer = null;
|
|
829
|
+
selectionSyncTimer = null;
|
|
830
|
+
pendingSelection = null;
|
|
829
831
|
lastCursorStyle = null;
|
|
830
832
|
lastCursorBlink = null;
|
|
831
833
|
lastCursorWidth = null;
|
|
@@ -834,6 +836,10 @@ class se {
|
|
|
834
836
|
nextSeedLines = null;
|
|
835
837
|
cmdlineEl = null;
|
|
836
838
|
cmdlineVisible = !1;
|
|
839
|
+
cmdlineTextRaw = null;
|
|
840
|
+
cmdlineCursorByte = null;
|
|
841
|
+
cmdlineCursorOffsetBytes = 0;
|
|
842
|
+
cmdlineCursorContentBytes = 0;
|
|
837
843
|
messageEl = null;
|
|
838
844
|
messageTimer = null;
|
|
839
845
|
popupEl = null;
|
|
@@ -844,7 +850,18 @@ class se {
|
|
|
844
850
|
compositionActive = !1;
|
|
845
851
|
pendingResyncAfterComposition = !1;
|
|
846
852
|
ignoreNextInputEvent = !1;
|
|
853
|
+
ignoreNvimBufLinesUntil = 0;
|
|
854
|
+
exitingInsertMode = !1;
|
|
855
|
+
pendingKeysAfterExit = "";
|
|
856
|
+
exitInsertTimer = null;
|
|
857
|
+
dotRepeatKeys = "";
|
|
858
|
+
dotRepeatBackspaces = 0;
|
|
847
859
|
ignoreTextKeydownUntil = 0;
|
|
860
|
+
lastImeCommitAt = 0;
|
|
861
|
+
lastImeCommitText = "";
|
|
862
|
+
recordingRegister = "";
|
|
863
|
+
recordingRefreshArmed = !1;
|
|
864
|
+
recordingRefreshTimer = null;
|
|
848
865
|
optimisticCursorUntil = 0;
|
|
849
866
|
optimisticCursorPos = null;
|
|
850
867
|
optimisticCursorPrevPos = null;
|
|
@@ -856,6 +873,33 @@ class se {
|
|
|
856
873
|
modelContentDisposable = null;
|
|
857
874
|
originalOptions = null;
|
|
858
875
|
resyncTimer = null;
|
|
876
|
+
debugLog(t) {
|
|
877
|
+
if (this.opts.debug)
|
|
878
|
+
try {
|
|
879
|
+
const e = `[monaco-neovim] ${t}`;
|
|
880
|
+
this.opts.debugLog ? this.opts.debugLog(e) : typeof console < "u" && console.debug && console.debug(e);
|
|
881
|
+
} catch {
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
scheduleRecordingRefresh() {
|
|
885
|
+
this.recordingRefreshTimer || (this.recordingRefreshTimer = window.setTimeout(() => {
|
|
886
|
+
this.recordingRefreshTimer = null, this.refreshRecordingState();
|
|
887
|
+
}, 0));
|
|
888
|
+
}
|
|
889
|
+
async refreshRecordingState() {
|
|
890
|
+
if (!(!this.session || !this.session.isRunning()))
|
|
891
|
+
try {
|
|
892
|
+
const t = await this.rpcCall("nvim_call_function", ["reg_recording", []]);
|
|
893
|
+
this.recordingRegister = typeof t == "string" ? t : String(t ?? "");
|
|
894
|
+
} catch {
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
sendCmdlineImeText(t) {
|
|
898
|
+
const e = String(t ?? "");
|
|
899
|
+
if (!e) return;
|
|
900
|
+
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(L(e, !0)), this.ignoreTextKeydownUntil = i + 60);
|
|
902
|
+
}
|
|
859
903
|
constructor(t, e = {}) {
|
|
860
904
|
this.editor = t, this.opts = {
|
|
861
905
|
worker: e.worker ?? null,
|
|
@@ -866,7 +910,7 @@ class se {
|
|
|
866
910
|
inputMode: e.inputMode ?? "shared",
|
|
867
911
|
env: e.env,
|
|
868
912
|
files: e.files,
|
|
869
|
-
sharedInputBytes: e.sharedInputBytes ??
|
|
913
|
+
sharedInputBytes: e.sharedInputBytes ?? R,
|
|
870
914
|
cols: e.cols ?? 120,
|
|
871
915
|
rows: e.rows ?? 40,
|
|
872
916
|
minCols: e.minCols ?? 20,
|
|
@@ -892,7 +936,7 @@ class se {
|
|
|
892
936
|
onHostCommand: e.onHostCommand,
|
|
893
937
|
status: e.status ?? (() => {
|
|
894
938
|
}),
|
|
895
|
-
seedLines: e.seedLines ??
|
|
939
|
+
seedLines: e.seedLines ?? re,
|
|
896
940
|
seedName: e.seedName ?? "monaco-demo.lua",
|
|
897
941
|
seedFiletype: e.seedFiletype ?? "lua",
|
|
898
942
|
uiAttach: e.uiAttach ?? !0,
|
|
@@ -921,8 +965,11 @@ class se {
|
|
|
921
965
|
onMessage: e.onMessage,
|
|
922
966
|
onPopupmenu: e.onPopupmenu,
|
|
923
967
|
cmdlineContainer: e.cmdlineContainer,
|
|
968
|
+
insertSyncDebounceMs: Number.isFinite(e.insertSyncDebounceMs) ? Math.max(0, Number(e.insertSyncDebounceMs)) : 20,
|
|
969
|
+
debug: e.debug ?? !1,
|
|
970
|
+
debugLog: e.debugLog,
|
|
924
971
|
shouldHandleKey: e.shouldHandleKey ?? (() => !0),
|
|
925
|
-
translateKey: e.translateKey ??
|
|
972
|
+
translateKey: e.translateKey ?? ce
|
|
926
973
|
}, this.ctrlKeysNormal = this.opts.ctrlKeysForNormalMode ? new Set(this.opts.ctrlKeysForNormalMode.map((i) => String(i).toLowerCase())) : null, this.ctrlKeysInsert = this.opts.ctrlKeysForInsertMode ? new Set(this.opts.ctrlKeysForInsertMode.map((i) => String(i).toLowerCase())) : null, this.altKeysNormal = this.opts.altKeysForNormalMode ? new Set(this.opts.altKeysForNormalMode.map((i) => String(i).toLowerCase())) : null, this.altKeysInsert = this.opts.altKeysForInsertMode ? new Set(this.opts.altKeysForInsertMode.map((i) => String(i).toLowerCase())) : null, this.metaKeysNormal = this.opts.metaKeysForNormalMode ? new Set(this.opts.metaKeysForNormalMode.map((i) => String(i).toLowerCase())) : null, this.metaKeysInsert = this.opts.metaKeysForInsertMode ? new Set(this.opts.metaKeysForInsertMode.map((i) => String(i).toLowerCase())) : null;
|
|
927
974
|
}
|
|
928
975
|
async start(t) {
|
|
@@ -935,8 +982,8 @@ class se {
|
|
|
935
982
|
this.notifyChain = this.notifyChain.then(() => this.handleNotify(s, n)).catch(() => {
|
|
936
983
|
});
|
|
937
984
|
},
|
|
938
|
-
onRequest: (s, n,
|
|
939
|
-
this.handleRequest(s, n,
|
|
985
|
+
onRequest: (s, n, r) => {
|
|
986
|
+
this.handleRequest(s, n, r);
|
|
940
987
|
},
|
|
941
988
|
onClipboardCopy: (s, n) => {
|
|
942
989
|
this.handleClipboardCopy(s);
|
|
@@ -959,8 +1006,8 @@ class se {
|
|
|
959
1006
|
this.opts.status(`start failed: ${s ?? "unknown"}`, !0);
|
|
960
1007
|
},
|
|
961
1008
|
onExit: (s, n) => {
|
|
962
|
-
const
|
|
963
|
-
this.opts.status(`nvim exited (${s})${
|
|
1009
|
+
const r = n ? `: ${n.trim()}` : "";
|
|
1010
|
+
this.opts.status(`nvim exited (${s})${r}`, s !== 0);
|
|
964
1011
|
try {
|
|
965
1012
|
this.opts.onExit?.(s, n);
|
|
966
1013
|
} catch {
|
|
@@ -974,7 +1021,7 @@ class se {
|
|
|
974
1021
|
this.opts.status(s, !0);
|
|
975
1022
|
}
|
|
976
1023
|
};
|
|
977
|
-
if (!this.session || !this.opts.reuseWorker ? this.session = new
|
|
1024
|
+
if (!this.session || !this.opts.reuseWorker ? this.session = new te({
|
|
978
1025
|
worker: this.opts.worker,
|
|
979
1026
|
workerUrl: this.opts.workerUrl,
|
|
980
1027
|
inputMode: this.opts.inputMode,
|
|
@@ -991,12 +1038,12 @@ class se {
|
|
|
991
1038
|
runtimePath: this.opts.runtimePath,
|
|
992
1039
|
inputMode: this.opts.inputMode,
|
|
993
1040
|
env: this.opts.env,
|
|
994
|
-
files:
|
|
1041
|
+
files: fe(me(
|
|
995
1042
|
this.opts.files,
|
|
996
1043
|
this.opts.wrappedLineMotions || this.opts.scrollMotions || this.opts.hostCommands ? [
|
|
997
|
-
{ path: "home/.config/nvim/monaco-neovim-wasm/motion.vim", data:
|
|
998
|
-
{ path: "home/.config/nvim/monaco-neovim-wasm/scrolling.vim", data:
|
|
999
|
-
{ path: "home/.config/nvim/monaco-neovim-wasm/host-commands.vim", data:
|
|
1044
|
+
{ path: "home/.config/nvim/monaco-neovim-wasm/motion.vim", data: ie },
|
|
1045
|
+
{ path: "home/.config/nvim/monaco-neovim-wasm/scrolling.vim", data: ne },
|
|
1046
|
+
{ path: "home/.config/nvim/monaco-neovim-wasm/host-commands.vim", data: se }
|
|
1000
1047
|
] : []
|
|
1001
1048
|
))
|
|
1002
1049
|
}), this.opts.status("starting..."), this.primeSent = !1, setTimeout(() => {
|
|
@@ -1008,7 +1055,7 @@ class se {
|
|
|
1008
1055
|
}
|
|
1009
1056
|
}
|
|
1010
1057
|
stop(t = !1) {
|
|
1011
|
-
this.session && (this.opts.reuseWorker ? this.session.stop({ terminate: !1, silent: !0 }) : (this.session.dispose(), this.session = null)), this.bufHandle = null, this.primeSent = !1, this.visualSelectionActive = !1, this.delegateInsertToMonaco = !1, this.applyingFromNvim = !1, this.clearBufferStates(), this.cursorSyncTimer && (clearTimeout(this.cursorSyncTimer), this.cursorSyncTimer = null), this.nvimChannelId = null, this.hostAutocmdInstalled = !1, this.notifyChain = Promise.resolve(), this.visualSelectionRefreshTimer && (clearTimeout(this.visualSelectionRefreshTimer), this.visualSelectionRefreshTimer = null), this.cursorRefreshTimer && (clearTimeout(this.cursorRefreshTimer), this.cursorRefreshTimer = null), this.cursorRefreshPending = !1, this.cursorRefreshInFlight = !1, this.setCmdline(null), this.setMessage(null), this.setPopupmenu(null, -1), this.resyncTimer && (clearTimeout(this.resyncTimer), this.resyncTimer = null), this.resizeTimer && (clearTimeout(this.resizeTimer), this.resizeTimer = null), t || this.opts.status("stopped", !0), this.disposeEditorListeners();
|
|
1058
|
+
this.session && (this.opts.reuseWorker ? this.session.stop({ terminate: !1, silent: !0 }) : (this.session.dispose(), this.session = null)), this.bufHandle = null, this.primeSent = !1, this.visualSelectionActive = !1, this.delegateInsertToMonaco = !1, this.recordingRegister = "", this.recordingRefreshArmed = !1, this.recordingRefreshTimer && (clearTimeout(this.recordingRefreshTimer), this.recordingRefreshTimer = null), this.exitingInsertMode = !1, this.pendingKeysAfterExit = "", this.exitInsertTimer && (clearTimeout(this.exitInsertTimer), this.exitInsertTimer = null), this.applyingFromNvim = !1, this.clearBufferStates(), this.cursorSyncTimer && (clearTimeout(this.cursorSyncTimer), this.cursorSyncTimer = null), this.nvimChannelId = null, this.hostAutocmdInstalled = !1, this.notifyChain = Promise.resolve(), this.visualSelectionRefreshTimer && (clearTimeout(this.visualSelectionRefreshTimer), this.visualSelectionRefreshTimer = null), this.cursorRefreshTimer && (clearTimeout(this.cursorRefreshTimer), this.cursorRefreshTimer = null), this.selectionSyncTimer && (clearTimeout(this.selectionSyncTimer), this.selectionSyncTimer = null), this.pendingSelection = null, this.cursorRefreshPending = !1, this.cursorRefreshInFlight = !1, this.setCmdline(null), this.setMessage(null), this.setPopupmenu(null, -1), this.resyncTimer && (clearTimeout(this.resyncTimer), this.resyncTimer = null), this.resizeTimer && (clearTimeout(this.resizeTimer), this.resizeTimer = null), t || this.opts.status("stopped", !0), this.disposeEditorListeners();
|
|
1012
1059
|
}
|
|
1013
1060
|
dispose() {
|
|
1014
1061
|
this.session && (this.session.dispose(), this.session = null), this.stop(!0);
|
|
@@ -1025,6 +1072,10 @@ class se {
|
|
|
1025
1072
|
input(t) {
|
|
1026
1073
|
this.sendNotify("nvim_input", [String(t ?? "")]);
|
|
1027
1074
|
}
|
|
1075
|
+
type(t, e = !0) {
|
|
1076
|
+
const i = L(String(t ?? ""), e);
|
|
1077
|
+
i && this.sendNotify("nvim_input", [i]);
|
|
1078
|
+
}
|
|
1028
1079
|
paste(t) {
|
|
1029
1080
|
this.pasteText(t);
|
|
1030
1081
|
}
|
|
@@ -1032,14 +1083,14 @@ class se {
|
|
|
1032
1083
|
const i = String(t ?? ""), s = Array.isArray(e) ? e : [];
|
|
1033
1084
|
if (this.execLuaAvailable !== !1)
|
|
1034
1085
|
try {
|
|
1035
|
-
const
|
|
1036
|
-
return this.execLuaAvailable = !0,
|
|
1037
|
-
} catch (
|
|
1038
|
-
const
|
|
1039
|
-
if (
|
|
1086
|
+
const r = await this.rpcCall("nvim_exec_lua", [i, s]);
|
|
1087
|
+
return this.execLuaAvailable = !0, r;
|
|
1088
|
+
} catch (r) {
|
|
1089
|
+
const a = r?.message || String(r);
|
|
1090
|
+
if (a.includes("Invalid method") && a.includes("nvim_exec_lua"))
|
|
1040
1091
|
this.execLuaAvailable = !1;
|
|
1041
1092
|
else
|
|
1042
|
-
throw
|
|
1093
|
+
throw r;
|
|
1043
1094
|
}
|
|
1044
1095
|
const n = `(function(...)
|
|
1045
1096
|
${i}
|
|
@@ -1060,7 +1111,7 @@ end)(unpack(_A))`;
|
|
|
1060
1111
|
}
|
|
1061
1112
|
attachEditorListeners() {
|
|
1062
1113
|
this.disposeEditorListeners();
|
|
1063
|
-
const t =
|
|
1114
|
+
const t = g.editor.EditorOption;
|
|
1064
1115
|
try {
|
|
1065
1116
|
const e = this.editor.getOption(t.fontInfo);
|
|
1066
1117
|
this.initialCursorWidth = this.editor.getOption(t.cursorWidth) || 0, this.typicalFullWidth = e?.typicalFullwidthCharacterWidth || 2;
|
|
@@ -1096,6 +1147,7 @@ end)(unpack(_A))`;
|
|
|
1096
1147
|
this.editor.onDidChangeModel(() => this.attachActiveModelListener()),
|
|
1097
1148
|
this.editor.onKeyDown((e) => this.handleKey(e)),
|
|
1098
1149
|
this.editor.onMouseDown((e) => this.handleMouse(e)),
|
|
1150
|
+
this.editor.onDidChangeCursorSelection((e) => this.handleSelection(e)),
|
|
1099
1151
|
this.editor.onDidChangeCursorPosition((e) => {
|
|
1100
1152
|
const i = this.editor.getPosition();
|
|
1101
1153
|
if (i && (this.lastCursorPos = i), this.delegateInsertToMonaco) {
|
|
@@ -1124,8 +1176,8 @@ end)(unpack(_A))`;
|
|
|
1124
1176
|
}
|
|
1125
1177
|
computeGridSize() {
|
|
1126
1178
|
try {
|
|
1127
|
-
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(
|
|
1128
|
-
if (Number.isFinite(
|
|
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)), c = Math.max(this.opts.minRows, Math.floor(i / r));
|
|
1180
|
+
if (Number.isFinite(a) && Number.isFinite(c) && a > 0 && c > 0) return { cols: a, rows: c };
|
|
1129
1181
|
} catch {
|
|
1130
1182
|
}
|
|
1131
1183
|
return { cols: this.opts.cols, rows: this.opts.rows };
|
|
@@ -1148,7 +1200,7 @@ end)(unpack(_A))`;
|
|
|
1148
1200
|
const e = document.createElement("div");
|
|
1149
1201
|
e.style.position = "absolute", e.style.display = "none", e.style.pointerEvents = "none", e.style.zIndex = "40", e.style.whiteSpace = "pre", e.style.padding = "0 1px", e.style.background = "rgba(0, 0, 0, 0.15)", e.style.borderBottom = "1px solid rgba(255, 255, 255, 0.6)", e.style.borderRadius = "2px";
|
|
1150
1202
|
try {
|
|
1151
|
-
const i = this.editor.getOption(
|
|
1203
|
+
const i = this.editor.getOption(g.editor.EditorOption.fontInfo);
|
|
1152
1204
|
i?.fontFamily && (e.style.fontFamily = i.fontFamily), i?.fontSize && (e.style.fontSize = `${i.fontSize}px`), i?.lineHeight && (e.style.lineHeight = `${i.lineHeight}px`);
|
|
1153
1205
|
} catch {
|
|
1154
1206
|
}
|
|
@@ -1167,11 +1219,11 @@ end)(unpack(_A))`;
|
|
|
1167
1219
|
if (!t || this.cmdlineVisible) return;
|
|
1168
1220
|
const e = this.editor.getModel();
|
|
1169
1221
|
if (!e) return;
|
|
1170
|
-
const i = this.editor.getSelection(), n = (i && !i.isEmpty() ? i.getStartPosition() : null) ?? this.editor.getPosition() ?? this.lastCursorPos ?? new
|
|
1171
|
-
let
|
|
1172
|
-
|
|
1173
|
-
const
|
|
1174
|
-
this.optimisticCursorPrevPos =
|
|
1222
|
+
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, c = n.column;
|
|
1224
|
+
r.length <= 1 ? c += Array.from(r[0] ?? "").length : (a += r.length - 1, c = 1 + Array.from(r[r.length - 1] ?? "").length);
|
|
1225
|
+
const h = e.validatePosition(new g.Position(a, c)), f = this.editor.getPosition() ?? this.lastCursorPos ?? n;
|
|
1226
|
+
this.optimisticCursorPrevPos = f, this.optimisticCursorPos = h, this.optimisticCursorUntil = (typeof performance < "u" && performance.now ? performance.now() : Date.now()) + 120, this.lastCursorPos = h, !this.compositionActive && (this.suppressCursorSync = !0, this.editor.setPosition(h), this.suppressCursorSync = !1);
|
|
1175
1227
|
}
|
|
1176
1228
|
positionPreedit() {
|
|
1177
1229
|
if (!this.preeditEl || !this.preeditVisible) return;
|
|
@@ -1290,14 +1342,14 @@ end)(unpack(_A))`;
|
|
|
1290
1342
|
await this.rpcCall("nvim_ui_attach", [this.uiCols || this.opts.cols, this.uiRows || this.opts.rows, this.opts.uiAttachOptions]);
|
|
1291
1343
|
} catch {
|
|
1292
1344
|
}
|
|
1293
|
-
for (const
|
|
1294
|
-
|
|
1345
|
+
for (const r of this.opts.startupCommands)
|
|
1346
|
+
r && this.sendNotify("nvim_command", [r]);
|
|
1295
1347
|
if (this.opts.startupLua)
|
|
1296
1348
|
try {
|
|
1297
1349
|
await this.execLua(this.opts.startupLua, []);
|
|
1298
1350
|
} catch {
|
|
1299
1351
|
}
|
|
1300
|
-
const t = await this.rpcCall("nvim_get_current_buf", []), e =
|
|
1352
|
+
const t = await this.rpcCall("nvim_get_current_buf", []), e = S(t) ?? 1;
|
|
1301
1353
|
if (this.bufHandle = e, await this.rpcCall("nvim_buf_attach", [e, !0, {}]) !== !0) throw new Error("nvim_buf_attach failed");
|
|
1302
1354
|
this.ensureActiveState(), this.opts.syncTabstop && this.syncTabstopFromMonaco();
|
|
1303
1355
|
const s = await this.rpcCall("nvim_buf_get_lines", [e, 0, -1, !1]);
|
|
@@ -1305,13 +1357,13 @@ end)(unpack(_A))`;
|
|
|
1305
1357
|
const n = await this.seedBuffer(e, this.nextSeedLines);
|
|
1306
1358
|
this.nextSeedLines = null, n && n.length && this.applyBuffer(n);
|
|
1307
1359
|
try {
|
|
1308
|
-
const
|
|
1309
|
-
if (
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1360
|
+
const r = this.ensureActiveState();
|
|
1361
|
+
if (r) {
|
|
1362
|
+
const a = await this.rpcCall("nvim_buf_get_name", [e]);
|
|
1363
|
+
r.name = typeof a == "string" ? a : "", r.name && this.buffersByName.set(r.name, e);
|
|
1312
1364
|
try {
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1365
|
+
const c = await this.rpcCall("nvim_buf_get_option", [e, "filetype"]);
|
|
1366
|
+
r.filetype = typeof c == "string" ? c : "";
|
|
1315
1367
|
} catch {
|
|
1316
1368
|
}
|
|
1317
1369
|
}
|
|
@@ -1381,13 +1433,13 @@ end)(unpack(_A))`;
|
|
|
1381
1433
|
return;
|
|
1382
1434
|
}
|
|
1383
1435
|
if (t === "monaco_cursor") {
|
|
1384
|
-
const [i, s] = e, n =
|
|
1436
|
+
const [i, s] = e, n = B(this.editor, Number(i), Number(s));
|
|
1385
1437
|
if (this.delegateInsertToMonaco) {
|
|
1386
|
-
const
|
|
1387
|
-
this.lastCursorPos =
|
|
1438
|
+
const r = this.editor.getModel(), a = r ? r.validatePosition(new g.Position(n.line, n.col)) : new g.Position(n.line, n.col);
|
|
1439
|
+
this.lastCursorPos = a;
|
|
1388
1440
|
return;
|
|
1389
1441
|
}
|
|
1390
|
-
this.updateCursor(n.line, n.col),
|
|
1442
|
+
this.updateCursor(n.line, n.col), I(this.lastMode) && this.scheduleVisualSelectionRefresh();
|
|
1391
1443
|
return;
|
|
1392
1444
|
}
|
|
1393
1445
|
if (t === "monaco_mode") {
|
|
@@ -1395,30 +1447,52 @@ end)(unpack(_A))`;
|
|
|
1395
1447
|
this.applyNvimMode(i);
|
|
1396
1448
|
return;
|
|
1397
1449
|
}
|
|
1450
|
+
if (t === "monaco_recording") {
|
|
1451
|
+
const i = typeof e?.[0] == "string" ? String(e[0]) : "";
|
|
1452
|
+
this.recordingRegister = i;
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1398
1455
|
if (t === "nvim_buf_lines_event") {
|
|
1399
|
-
const [i, s, n,
|
|
1400
|
-
if (!
|
|
1401
|
-
const
|
|
1402
|
-
if (!
|
|
1403
|
-
if (this.bufHandle != null &&
|
|
1456
|
+
const [i, s, n, r, a] = e, c = S(i);
|
|
1457
|
+
if (!c) return;
|
|
1458
|
+
const h = this.bufHandle != null && c === this.bufHandle ? this.ensureActiveState() : this.buffers.get(c) ?? null;
|
|
1459
|
+
if (!h) return;
|
|
1460
|
+
if (this.bufHandle != null && c === this.bufHandle && this.compositionActive) {
|
|
1404
1461
|
this.pendingResyncAfterComposition = !0;
|
|
1405
1462
|
return;
|
|
1406
1463
|
}
|
|
1407
|
-
const
|
|
1408
|
-
if (
|
|
1464
|
+
const f = h.model, l = Number(n), u = Number(r), d = Array.isArray(a) ? a.map((p) => String(p ?? "")) : null;
|
|
1465
|
+
if (f && Number.isInteger(l) && Number.isInteger(u) && l >= 0 && u >= l && d)
|
|
1409
1466
|
try {
|
|
1410
|
-
this.bufHandle != null &&
|
|
1467
|
+
const p = this.bufHandle != null && c === this.bufHandle && this.editor.getModel() === f;
|
|
1468
|
+
if (p && this.delegateInsertToMonaco) {
|
|
1469
|
+
const y = this.computeLinePatch(f, l, u, d);
|
|
1470
|
+
let b = !1;
|
|
1471
|
+
try {
|
|
1472
|
+
b = f.getValueInRange(y.range) === y.text;
|
|
1473
|
+
} catch {
|
|
1474
|
+
}
|
|
1475
|
+
if (!b) {
|
|
1476
|
+
const w = typeof performance < "u" && performance.now ? performance.now() : Date.now();
|
|
1477
|
+
if (h.pendingFullSync || h.pendingBufEdits.length || w < this.ignoreNvimBufLinesUntil) return;
|
|
1478
|
+
this.applyLinePatchToModel(f, l, u, d);
|
|
1479
|
+
try {
|
|
1480
|
+
h.shadowLines = f.getLinesContent();
|
|
1481
|
+
} catch {
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
} else p ? this.applyLinePatch(f, l, u, d) : this.applyLinePatchToModel(f, l, u, d);
|
|
1411
1485
|
} catch {
|
|
1412
1486
|
}
|
|
1413
1487
|
else
|
|
1414
1488
|
try {
|
|
1415
|
-
const
|
|
1416
|
-
this.bufHandle != null &&
|
|
1489
|
+
const p = await this.rpcCall("nvim_buf_get_lines", [c, 0, -1, !1]), y = Array.isArray(p) ? p : [""];
|
|
1490
|
+
this.bufHandle != null && c === this.bufHandle && this.editor.getModel() === f ? this.applyBuffer(y) : this.setModelText(f, y);
|
|
1417
1491
|
} catch {
|
|
1418
1492
|
}
|
|
1419
|
-
this.bufHandle != null &&
|
|
1493
|
+
this.bufHandle != null && c === this.bufHandle && I(this.lastMode) && this.scheduleVisualSelectionRefresh();
|
|
1420
1494
|
} else if (t === "nvim_buf_detach_event") {
|
|
1421
|
-
const i =
|
|
1495
|
+
const i = S(e?.[0]);
|
|
1422
1496
|
if (i && this.buffers.has(i)) {
|
|
1423
1497
|
const s = this.buffers.get(i);
|
|
1424
1498
|
if (s.name && this.buffersByName.delete(s.name), s.createdModel)
|
|
@@ -1431,42 +1505,38 @@ end)(unpack(_A))`;
|
|
|
1431
1505
|
i && this.bufHandle === i && (this.bufHandle = null);
|
|
1432
1506
|
} else t === "redraw" && this.handleRedraw(e);
|
|
1433
1507
|
}
|
|
1434
|
-
|
|
1435
|
-
const n = t.getLineCount(),
|
|
1436
|
-
let
|
|
1437
|
-
`);
|
|
1438
|
-
e >= n && i >= n && s.length > 0 && (c = `
|
|
1439
|
-
${c}`), i < n && s.length > 0 && (c += `
|
|
1508
|
+
computeLinePatch(t, e, i, s) {
|
|
1509
|
+
const n = t.getLineCount(), r = Math.min(e, n), a = Math.min(i, n), c = 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) : c, l = a < n ? new g.Position(a + 1, 1) : c;
|
|
1510
|
+
let u = s.join(`
|
|
1440
1511
|
`);
|
|
1441
|
-
|
|
1512
|
+
return e >= n && i >= n && s.length > 0 && (u = `
|
|
1513
|
+
${u}`), i < n && s.length > 0 && (u += `
|
|
1514
|
+
`), { range: new g.Range(f.lineNumber, f.column, l.lineNumber, l.column), text: u };
|
|
1515
|
+
}
|
|
1516
|
+
applyLinePatch(t, e, i, s) {
|
|
1517
|
+
const n = this.lastCursorPos ?? this.editor.getPosition() ?? new g.Position(1, 1), r = this.computeLinePatch(t, e, i, s);
|
|
1442
1518
|
try {
|
|
1443
|
-
if (t.getValueInRange(
|
|
1519
|
+
if (t.getValueInRange(r.range) === r.text) return;
|
|
1444
1520
|
} catch {
|
|
1445
1521
|
}
|
|
1446
|
-
if (this.suppressCursorSync = !0, this.applyingFromNvim = !0, t.applyEdits([{ range:
|
|
1447
|
-
const
|
|
1448
|
-
if (
|
|
1522
|
+
if (this.suppressCursorSync = !0, this.applyingFromNvim = !0, t.applyEdits([{ range: r.range, text: r.text }]), this.applyingFromNvim = !1, n && this.editor.setPosition(n), this.suppressCursorSync = !1, this.delegateInsertToMonaco) {
|
|
1523
|
+
const a = this.getActiveState();
|
|
1524
|
+
if (a && a.model === t)
|
|
1449
1525
|
try {
|
|
1450
|
-
|
|
1526
|
+
a.shadowLines = t.getLinesContent();
|
|
1451
1527
|
} catch {
|
|
1452
1528
|
}
|
|
1453
1529
|
}
|
|
1454
1530
|
}
|
|
1455
1531
|
applyLinePatchToModel(t, e, i, s) {
|
|
1456
|
-
const n =
|
|
1457
|
-
let f = s.join(`
|
|
1458
|
-
`);
|
|
1459
|
-
e >= n && i >= n && s.length > 0 && (f = `
|
|
1460
|
-
${f}`), i < n && s.length > 0 && (f += `
|
|
1461
|
-
`);
|
|
1462
|
-
const p = new m.Range(u.lineNumber, u.column, h.lineNumber, h.column);
|
|
1532
|
+
const n = this.computeLinePatch(t, e, i, s);
|
|
1463
1533
|
try {
|
|
1464
|
-
if (t.getValueInRange(
|
|
1534
|
+
if (t.getValueInRange(n.range) === n.text) return;
|
|
1465
1535
|
} catch {
|
|
1466
1536
|
}
|
|
1467
1537
|
this.applyingFromNvim = !0;
|
|
1468
1538
|
try {
|
|
1469
|
-
t.applyEdits([{ range:
|
|
1539
|
+
t.applyEdits([{ range: n.range, text: n.text }]);
|
|
1470
1540
|
} catch {
|
|
1471
1541
|
}
|
|
1472
1542
|
this.applyingFromNvim = !1;
|
|
@@ -1508,7 +1578,7 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1508
1578
|
}
|
|
1509
1579
|
}
|
|
1510
1580
|
setCmdline(t) {
|
|
1511
|
-
if (this.opts.onCmdline)
|
|
1581
|
+
if (this.cmdlineTextRaw = t, this.cmdlineCursorByte = null, this.cmdlineCursorOffsetBytes = 0, this.cmdlineCursorContentBytes = 0, this.opts.onCmdline)
|
|
1512
1582
|
try {
|
|
1513
1583
|
this.opts.onCmdline(t);
|
|
1514
1584
|
} catch {
|
|
@@ -1521,6 +1591,15 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1521
1591
|
this.cmdlineEl.textContent = t, this.cmdlineEl.style.display = "block", this.cmdlineVisible = !0;
|
|
1522
1592
|
}
|
|
1523
1593
|
}
|
|
1594
|
+
setCmdlineCursor(t) {
|
|
1595
|
+
if (!this.cmdlineEl || !this.cmdlineVisible || !this.cmdlineTextRaw) return;
|
|
1596
|
+
if (t == null || !Number.isFinite(t)) {
|
|
1597
|
+
this.cmdlineEl.textContent = this.cmdlineTextRaw, this.cmdlineCursorByte = null;
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
const e = this.cmdlineTextRaw, i = Math.max(0, Math.min(Number(t) || 0, k(e))), s = Math.max(0, Math.min(e.length, v(e, i)));
|
|
1601
|
+
this.cmdlineCursorByte = i, this.cmdlineEl.textContent = `${e.slice(0, s)}▏${e.slice(s)}`;
|
|
1602
|
+
}
|
|
1524
1603
|
setMessage(t) {
|
|
1525
1604
|
if (this.opts.onMessage)
|
|
1526
1605
|
try {
|
|
@@ -1552,10 +1631,10 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1552
1631
|
for (let i = 0; i < t.length; i += 1) {
|
|
1553
1632
|
const s = t[i], n = document.createElement("div");
|
|
1554
1633
|
n.style.padding = "2px 10px", n.style.display = "flex", n.style.gap = "10px", n.style.justifyContent = "space-between", n.style.background = i === e ? "rgba(255,255,255,0.12)" : "transparent";
|
|
1555
|
-
const
|
|
1556
|
-
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1634
|
+
const r = document.createElement("span");
|
|
1635
|
+
r.textContent = s.word ?? "";
|
|
1636
|
+
const a = document.createElement("span");
|
|
1637
|
+
a.style.opacity = "0.7", a.textContent = s.menu ?? s.kind ?? "", n.appendChild(r), n.appendChild(a), this.popupEl.appendChild(n);
|
|
1559
1638
|
}
|
|
1560
1639
|
this.popupEl.style.display = "block";
|
|
1561
1640
|
}
|
|
@@ -1583,10 +1662,10 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1583
1662
|
} catch {
|
|
1584
1663
|
}
|
|
1585
1664
|
if (i === "wrappedLine" && (e === "down" || e === "up")) {
|
|
1586
|
-
const
|
|
1587
|
-
for (let
|
|
1665
|
+
const a = e === "down" ? "cursorDown" : "cursorUp";
|
|
1666
|
+
for (let c = 0; c < s; c += 1)
|
|
1588
1667
|
try {
|
|
1589
|
-
this.editor.trigger("monaco-neovim-wasm",
|
|
1668
|
+
this.editor.trigger("monaco-neovim-wasm", a, null);
|
|
1590
1669
|
} catch {
|
|
1591
1670
|
}
|
|
1592
1671
|
return !0;
|
|
@@ -1594,8 +1673,8 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1594
1673
|
return !1;
|
|
1595
1674
|
};
|
|
1596
1675
|
this.suppressCursorSync = !0, n();
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1676
|
+
const r = this.editor.getPosition();
|
|
1677
|
+
r && (this.lastCursorPos = r, this.applyScrolloff(r)), this.suppressCursorSync = !1, this.scheduleSearchHighlightRefresh();
|
|
1599
1678
|
}
|
|
1600
1679
|
getScrolloffLines() {
|
|
1601
1680
|
return this.opts.scrolloff != null ? Math.max(0, Math.floor(this.opts.scrolloff)) : this.opts.syncScrolloff ? Math.max(0, Math.floor(this.nvimScrolloff)) : 0;
|
|
@@ -1606,89 +1685,89 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1606
1685
|
if (e <= 0) return !1;
|
|
1607
1686
|
const i = t ?? this.editor.getPosition();
|
|
1608
1687
|
if (!i) return !1;
|
|
1609
|
-
const s = Math.max(1, Number(this.editor.getOption(
|
|
1688
|
+
const s = Math.max(1, Number(this.editor.getOption(g.editor.EditorOption.lineHeight)) || 0), n = e * s;
|
|
1610
1689
|
if (n <= 0) return !1;
|
|
1611
|
-
let
|
|
1690
|
+
let r = 0;
|
|
1612
1691
|
try {
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1692
|
+
const m = this.editor.getLayoutInfo();
|
|
1693
|
+
r = Math.max(0, Number(m?.contentHeight ?? m?.height ?? 0) || 0);
|
|
1615
1694
|
} catch {
|
|
1616
1695
|
}
|
|
1617
|
-
if (
|
|
1618
|
-
const
|
|
1696
|
+
if (r <= 0) return !1;
|
|
1697
|
+
const a = () => {
|
|
1619
1698
|
try {
|
|
1620
1699
|
this.editor.revealPositionInCenterIfOutsideViewport(i);
|
|
1621
1700
|
} catch {
|
|
1622
1701
|
}
|
|
1623
1702
|
};
|
|
1624
|
-
let
|
|
1703
|
+
let c = null;
|
|
1625
1704
|
try {
|
|
1626
|
-
|
|
1705
|
+
c = this.editor.getScrolledVisiblePosition(i);
|
|
1627
1706
|
} catch {
|
|
1628
1707
|
}
|
|
1629
|
-
if (!
|
|
1630
|
-
|
|
1708
|
+
if (!c) {
|
|
1709
|
+
a();
|
|
1631
1710
|
try {
|
|
1632
|
-
|
|
1711
|
+
c = this.editor.getScrolledVisiblePosition(i);
|
|
1633
1712
|
} catch {
|
|
1634
1713
|
}
|
|
1635
1714
|
}
|
|
1636
|
-
if (!
|
|
1637
|
-
const
|
|
1715
|
+
if (!c || !Number.isFinite(c.top) || !Number.isFinite(c.height)) return !1;
|
|
1716
|
+
const h = this.editor.getScrollTop(), f = c.top, l = c.top + c.height, u = Math.max(0, r - n);
|
|
1638
1717
|
let d = 0;
|
|
1639
|
-
if (
|
|
1718
|
+
if (f < n ? d = f - n : l > u && (d = l - u), !d) return !1;
|
|
1640
1719
|
try {
|
|
1641
|
-
this.editor.setScrollTop(Math.max(0,
|
|
1720
|
+
this.editor.setScrollTop(Math.max(0, h + d));
|
|
1642
1721
|
} catch {
|
|
1643
1722
|
}
|
|
1644
1723
|
return !0;
|
|
1645
1724
|
}
|
|
1646
1725
|
applyMonacoScroll(t) {
|
|
1647
|
-
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,
|
|
1648
|
-
let
|
|
1649
|
-
if (e === "page")
|
|
1650
|
-
else if (e === "halfPage")
|
|
1651
|
-
else if (e === "line")
|
|
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), c = this.editor.getOption(g.editor.EditorOption.fontInfo), h = Math.max(1, Number(c?.lineHeight ?? 0) || 0), f = Math.max(1, a - 2), l = Math.max(1, Math.floor(f / 2));
|
|
1727
|
+
let u = s;
|
|
1728
|
+
if (e === "page") u = f * s;
|
|
1729
|
+
else if (e === "halfPage") u = l * s;
|
|
1730
|
+
else if (e === "line") u = s;
|
|
1652
1731
|
else return !1;
|
|
1653
1732
|
const d = i === "up" ? -1 : i === "down" ? 1 : 0;
|
|
1654
1733
|
if (!d) return !1;
|
|
1655
1734
|
this.suppressCursorSync = !0;
|
|
1656
1735
|
try {
|
|
1657
|
-
const
|
|
1736
|
+
const p = this.editor.getScrollTop(), y = Math.max(0, p + d * u * h);
|
|
1658
1737
|
this.editor.setScrollTop(y);
|
|
1659
1738
|
} catch {
|
|
1660
1739
|
}
|
|
1661
|
-
let
|
|
1740
|
+
let m = !1;
|
|
1662
1741
|
if (n)
|
|
1663
1742
|
try {
|
|
1664
1743
|
this.applyMonacoCursorMove({
|
|
1665
1744
|
to: d > 0 ? "down" : "up",
|
|
1666
|
-
by:
|
|
1667
|
-
value:
|
|
1668
|
-
}),
|
|
1745
|
+
by: r,
|
|
1746
|
+
value: u
|
|
1747
|
+
}), m = !0;
|
|
1669
1748
|
} catch {
|
|
1670
1749
|
}
|
|
1671
|
-
return this.suppressCursorSync = !1,
|
|
1750
|
+
return this.suppressCursorSync = !1, m;
|
|
1672
1751
|
}
|
|
1673
1752
|
applyMonacoReveal(t) {
|
|
1674
1753
|
const e = typeof t.direction == "string" ? t.direction : "", i = !!t.resetCursor, s = this.editor.getPosition();
|
|
1675
1754
|
if (!s) return !1;
|
|
1676
|
-
const n = s.lineNumber,
|
|
1755
|
+
const n = s.lineNumber, r = Math.max(1, this.uiRows || this.opts.rows), a = this.editor.getOption(g.editor.EditorOption.fontInfo), c = Math.max(1, Number(a?.lineHeight ?? 0) || 0);
|
|
1677
1756
|
this.suppressCursorSync = !0;
|
|
1678
1757
|
try {
|
|
1679
1758
|
if (e === "top") {
|
|
1680
|
-
const
|
|
1681
|
-
this.editor.setScrollTop(
|
|
1759
|
+
const h = this.editor.getTopForLineNumber(n);
|
|
1760
|
+
this.editor.setScrollTop(h);
|
|
1682
1761
|
} else if (e === "center")
|
|
1683
1762
|
this.editor.revealLineInCenter(n);
|
|
1684
1763
|
else if (e === "bottom") {
|
|
1685
|
-
const
|
|
1686
|
-
this.editor.setScrollTop(
|
|
1764
|
+
const h = this.editor.getTopForLineNumber(n), f = Math.max(0, h - (r - 1) * c);
|
|
1765
|
+
this.editor.setScrollTop(f);
|
|
1687
1766
|
}
|
|
1688
1767
|
if (i) {
|
|
1689
|
-
const
|
|
1690
|
-
if (
|
|
1691
|
-
const
|
|
1768
|
+
const h = this.editor.getModel();
|
|
1769
|
+
if (h) {
|
|
1770
|
+
const f = h.getLineContent(n) ?? "", l = /\S/.exec(f), u = l ? l.index + 1 : 1, d = h.validatePosition(new g.Position(n, u));
|
|
1692
1771
|
this.editor.setPosition(d), this.lastCursorPos = d;
|
|
1693
1772
|
}
|
|
1694
1773
|
}
|
|
@@ -1702,30 +1781,30 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1702
1781
|
const i = this.editor.getModel();
|
|
1703
1782
|
if (!i) return;
|
|
1704
1783
|
const s = Math.max(1, Number(t.value ?? 1) || 1);
|
|
1705
|
-
let n = 1,
|
|
1784
|
+
let n = 1, r = i.getLineCount();
|
|
1706
1785
|
try {
|
|
1707
|
-
const
|
|
1708
|
-
|
|
1786
|
+
const u = this.editor.getVisibleRanges();
|
|
1787
|
+
u && u.length && (n = Math.min(...u.map((d) => d.startLineNumber)), r = Math.max(...u.map((d) => d.endLineNumber)));
|
|
1709
1788
|
} catch {
|
|
1710
1789
|
}
|
|
1711
|
-
n = Math.max(1, Math.min(n, i.getLineCount())),
|
|
1712
|
-
let
|
|
1790
|
+
n = Math.max(1, Math.min(n, i.getLineCount())), r = Math.max(1, Math.min(r, i.getLineCount())), r < n && (r = n);
|
|
1791
|
+
let a = n;
|
|
1713
1792
|
if (e === "top")
|
|
1714
|
-
|
|
1793
|
+
a = n + (s - 1);
|
|
1715
1794
|
else if (e === "middle")
|
|
1716
|
-
|
|
1795
|
+
a = Math.floor((n + r) / 2);
|
|
1717
1796
|
else if (e === "bottom")
|
|
1718
|
-
|
|
1797
|
+
a = r - (s - 1);
|
|
1719
1798
|
else
|
|
1720
1799
|
return;
|
|
1721
|
-
|
|
1722
|
-
const
|
|
1800
|
+
a = Math.max(n, Math.min(r, a));
|
|
1801
|
+
const c = i.getLineContent(a) ?? "", h = /\S/.exec(c), f = h ? h.index + 1 : 1, l = i.validatePosition(new g.Position(a, f));
|
|
1723
1802
|
this.suppressCursorSync = !0;
|
|
1724
1803
|
try {
|
|
1725
|
-
this.editor.setPosition(
|
|
1804
|
+
this.editor.setPosition(l);
|
|
1726
1805
|
} catch {
|
|
1727
1806
|
}
|
|
1728
|
-
this.lastCursorPos =
|
|
1807
|
+
this.lastCursorPos = l, this.suppressCursorSync = !1;
|
|
1729
1808
|
}
|
|
1730
1809
|
syncTabstopFromMonaco() {
|
|
1731
1810
|
const t = this.editor.getModel();
|
|
@@ -1759,12 +1838,17 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1759
1838
|
continue;
|
|
1760
1839
|
}
|
|
1761
1840
|
if (i === "cmdline_show") {
|
|
1762
|
-
const
|
|
1763
|
-
this.setCmdline(
|
|
1841
|
+
const r = n[0], a = Math.max(0, Number(n[1] ?? 0) || 0), c = typeof n[2] == "string" ? n[2] : "", h = typeof n[3] == "string" ? n[3] : "", f = Math.max(0, Number(n[4] ?? 0) || 0), l = h || c || "", u = " ".repeat(f), d = N(r), m = `${u}${l}${d}`;
|
|
1842
|
+
this.setCmdline(m);
|
|
1843
|
+
const p = k(`${u}${l}`), y = k(d);
|
|
1844
|
+
this.cmdlineCursorOffsetBytes = p, this.cmdlineCursorContentBytes = y;
|
|
1845
|
+
const b = a <= y ? this.cmdlineCursorOffsetBytes + a : a;
|
|
1846
|
+
this.setCmdlineCursor(b), this.scheduleSearchHighlightRefresh();
|
|
1764
1847
|
continue;
|
|
1765
1848
|
}
|
|
1766
1849
|
if (i === "cmdline_pos") {
|
|
1767
|
-
|
|
1850
|
+
const r = Math.max(0, Number(n[0] ?? 0) || 0), a = this.cmdlineCursorOffsetBytes > 0 && r <= this.cmdlineCursorContentBytes ? this.cmdlineCursorOffsetBytes + r : r;
|
|
1851
|
+
this.setCmdlineCursor(a), this.scheduleSearchHighlightRefresh();
|
|
1768
1852
|
continue;
|
|
1769
1853
|
}
|
|
1770
1854
|
if (i === "msg_clear") {
|
|
@@ -1772,26 +1856,26 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1772
1856
|
continue;
|
|
1773
1857
|
}
|
|
1774
1858
|
if (i === "msg_show") {
|
|
1775
|
-
const
|
|
1776
|
-
if (
|
|
1859
|
+
const r = typeof n[0] == "string" ? n[0] : "", a = n[1], c = !!n[2], h = !!n[4], f = N(a);
|
|
1860
|
+
if (r === "empty" && !f) {
|
|
1777
1861
|
this.setMessage(null);
|
|
1778
1862
|
continue;
|
|
1779
1863
|
}
|
|
1780
|
-
if (!
|
|
1781
|
-
if (
|
|
1782
|
-
this.setMessage(`${this.messageEl.textContent}${
|
|
1864
|
+
if (!f) continue;
|
|
1865
|
+
if (h && this.messageEl?.textContent) {
|
|
1866
|
+
this.setMessage(`${this.messageEl.textContent}${f}`);
|
|
1783
1867
|
continue;
|
|
1784
1868
|
}
|
|
1785
|
-
if (
|
|
1786
|
-
this.setMessage(
|
|
1869
|
+
if (c) {
|
|
1870
|
+
this.setMessage(f);
|
|
1787
1871
|
continue;
|
|
1788
1872
|
}
|
|
1789
|
-
this.setMessage(
|
|
1873
|
+
this.setMessage(f);
|
|
1790
1874
|
continue;
|
|
1791
1875
|
}
|
|
1792
1876
|
if (i === "msg_showmode" || i === "msg_showcmd" || i === "msg_ruler") {
|
|
1793
|
-
const
|
|
1794
|
-
this.setMessage(
|
|
1877
|
+
const r = n[0], a = N(r);
|
|
1878
|
+
this.setMessage(a || null);
|
|
1795
1879
|
continue;
|
|
1796
1880
|
}
|
|
1797
1881
|
if (i === "popupmenu_hide") {
|
|
@@ -1799,18 +1883,18 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1799
1883
|
continue;
|
|
1800
1884
|
}
|
|
1801
1885
|
if (i === "popupmenu_show") {
|
|
1802
|
-
const
|
|
1803
|
-
this.setPopupmenu(
|
|
1886
|
+
const r = n[0], a = Number(n[1] ?? -1), c = be(r);
|
|
1887
|
+
this.setPopupmenu(c, Number.isFinite(a) ? a : -1);
|
|
1804
1888
|
continue;
|
|
1805
1889
|
}
|
|
1806
1890
|
if (i === "popupmenu_select") {
|
|
1807
|
-
const
|
|
1808
|
-
this.updatePopupmenuSelection(Number.isFinite(
|
|
1891
|
+
const r = Number(n[0] ?? -1);
|
|
1892
|
+
this.updatePopupmenuSelection(Number.isFinite(r) ? r : -1);
|
|
1809
1893
|
continue;
|
|
1810
1894
|
}
|
|
1811
1895
|
if (i === "mode_change") {
|
|
1812
|
-
const
|
|
1813
|
-
this.applyNvimMode(
|
|
1896
|
+
const r = typeof n[0] == "string" ? n[0] : "";
|
|
1897
|
+
this.applyNvimMode(r);
|
|
1814
1898
|
continue;
|
|
1815
1899
|
}
|
|
1816
1900
|
}
|
|
@@ -1818,108 +1902,119 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1818
1902
|
initTextInputListeners() {
|
|
1819
1903
|
const t = this.editor.getDomNode();
|
|
1820
1904
|
if (!t) return;
|
|
1821
|
-
const e =
|
|
1822
|
-
if (!e.length) return;
|
|
1823
|
-
const i = (c) => {
|
|
1905
|
+
const e = (l) => {
|
|
1824
1906
|
try {
|
|
1825
|
-
|
|
1907
|
+
l.stopImmediatePropagation?.();
|
|
1826
1908
|
} catch {
|
|
1827
1909
|
}
|
|
1828
1910
|
try {
|
|
1829
|
-
|
|
1911
|
+
l.stopPropagation();
|
|
1830
1912
|
} catch {
|
|
1831
1913
|
}
|
|
1832
|
-
},
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
if (
|
|
1842
|
-
|
|
1914
|
+
}, i = (l) => {
|
|
1915
|
+
try {
|
|
1916
|
+
const u = l;
|
|
1917
|
+
return !u || typeof u.tagName != "string" || u.tagName !== "TEXTAREA" || !u.classList?.contains?.("inputarea") ? null : u;
|
|
1918
|
+
} catch {
|
|
1919
|
+
return null;
|
|
1920
|
+
}
|
|
1921
|
+
}, s = (l) => {
|
|
1922
|
+
if (this.compositionActive || l.isComposing || l.getModifierState?.("AltGraph")) return;
|
|
1923
|
+
if (x(this.lastMode) && !this.delegateInsertToMonaco && !this.exitingInsertMode && !l.ctrlKey && !l.metaKey && typeof l.key == "string" && l.key.length === 1) {
|
|
1924
|
+
const p = /^[\x20-\x7E]$/.test(l.key);
|
|
1925
|
+
if (!!!(l.altKey && p)) {
|
|
1926
|
+
if (!this.opts.shouldHandleKey(l)) return;
|
|
1927
|
+
e(l);
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (!l.ctrlKey && !l.altKey && !l.metaKey) return;
|
|
1932
|
+
const u = this.modifiedKeyName(l);
|
|
1933
|
+
if (!u || !this.opts.shouldHandleKey(l)) return;
|
|
1934
|
+
const d = this.delegateInsertToMonaco && !this.exitingInsertMode;
|
|
1935
|
+
if (this.hasExplicitModAllowlist(d)) {
|
|
1936
|
+
if (!this.shouldForwardModifiedKeys(l, d)) return;
|
|
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;
|
|
1938
|
+
const m = this.opts.translateKey(l);
|
|
1939
|
+
if (m) {
|
|
1940
|
+
e(l);
|
|
1843
1941
|
try {
|
|
1844
|
-
|
|
1942
|
+
l.preventDefault();
|
|
1845
1943
|
} catch {
|
|
1846
1944
|
}
|
|
1847
|
-
|
|
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) : (d && 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));
|
|
1848
1946
|
}
|
|
1849
1947
|
}, n = () => {
|
|
1850
|
-
if (this.compositionActive = !0, this.delegateInsertToMonaco) {
|
|
1948
|
+
if (this.compositionActive = !0, this.debugLog(`compositionstart delegateInsert=${this.delegateInsertToMonaco} mode=${JSON.stringify(this.lastMode)}`), this.delegateInsertToMonaco) {
|
|
1851
1949
|
this.setPreedit(null);
|
|
1852
1950
|
return;
|
|
1853
1951
|
}
|
|
1854
1952
|
this.setPreedit("");
|
|
1855
|
-
},
|
|
1856
|
-
this.compositionActive = !1, this.setPreedit(null)
|
|
1857
|
-
}, l = (c) => {
|
|
1858
|
-
if (this.compositionActive = !1, this.setPreedit(null), this.delegateInsertToMonaco) {
|
|
1953
|
+
}, r = (l) => {
|
|
1954
|
+
if (this.compositionActive = !1, this.setPreedit(null), this.debugLog(`compositionend delegateInsert=${this.delegateInsertToMonaco} mode=${JSON.stringify(this.lastMode)} data=${JSON.stringify(l.data ?? "")}`), this.delegateInsertToMonaco) {
|
|
1859
1955
|
this.scheduleCursorSyncToNvim();
|
|
1860
1956
|
return;
|
|
1861
1957
|
}
|
|
1862
|
-
const
|
|
1958
|
+
const u = l.target;
|
|
1959
|
+
if (x(this.lastMode)) {
|
|
1960
|
+
const d = typeof l.data == "string" ? l.data : "", m = !d && u?.value ? String(u.value) : "", p = d || m;
|
|
1961
|
+
p && this.sendCmdlineImeText(p);
|
|
1962
|
+
}
|
|
1863
1963
|
try {
|
|
1964
|
+
const d = i(u);
|
|
1864
1965
|
d && (d.value = "");
|
|
1865
1966
|
} catch {
|
|
1866
1967
|
}
|
|
1867
1968
|
this.pendingResyncAfterComposition && (this.pendingResyncAfterComposition = !1, this.scheduleResync());
|
|
1868
|
-
}, a = (
|
|
1969
|
+
}, a = (l) => {
|
|
1869
1970
|
if (this.compositionActive || (this.compositionActive = !0), this.delegateInsertToMonaco) return;
|
|
1870
|
-
const
|
|
1871
|
-
this.setPreedit(
|
|
1872
|
-
},
|
|
1873
|
-
this.delegateInsertToMonaco ||
|
|
1874
|
-
}, h = (
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1971
|
+
const u = i(l.target), d = typeof l.data == "string" ? l.data : u?.value ? String(u.value) : "";
|
|
1972
|
+
this.setPreedit(d || "");
|
|
1973
|
+
}, c = (l) => {
|
|
1974
|
+
i(l.target) && (this.delegateInsertToMonaco && !this.exitingInsertMode || e(l));
|
|
1975
|
+
}, h = (l) => {
|
|
1976
|
+
const u = i(l.target);
|
|
1977
|
+
if (!u || this.delegateInsertToMonaco && !this.exitingInsertMode) return;
|
|
1978
|
+
e(l);
|
|
1979
|
+
const d = l;
|
|
1878
1980
|
if (this.ignoreNextInputEvent) {
|
|
1879
1981
|
this.ignoreNextInputEvent = !1;
|
|
1880
1982
|
try {
|
|
1881
|
-
|
|
1983
|
+
u && (u.value = "");
|
|
1882
1984
|
} catch {
|
|
1883
1985
|
}
|
|
1884
1986
|
return;
|
|
1885
1987
|
}
|
|
1886
|
-
if (!this.compositionActive)
|
|
1988
|
+
if (!this.compositionActive) {
|
|
1989
|
+
if (x(this.lastMode)) {
|
|
1990
|
+
const m = typeof d.data == "string" ? d.data : "", p = !m && u?.value ? String(u.value) : "", y = m || p;
|
|
1991
|
+
y && this.sendCmdlineImeText(y);
|
|
1992
|
+
}
|
|
1887
1993
|
try {
|
|
1888
|
-
|
|
1994
|
+
u && (u.value = "");
|
|
1889
1995
|
} catch {
|
|
1890
1996
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
i(
|
|
1894
|
-
|
|
1895
|
-
|
|
1997
|
+
}
|
|
1998
|
+
}, f = (l) => {
|
|
1999
|
+
if (!i(l.target) || this.delegateInsertToMonaco && !this.exitingInsertMode) return;
|
|
2000
|
+
e(l);
|
|
2001
|
+
const u = l.clipboardData?.getData("text/plain") ?? "";
|
|
2002
|
+
u && (l.preventDefault(), this.ignoreNextInputEvent = !0, this.pasteText(u));
|
|
1896
2003
|
try {
|
|
1897
|
-
|
|
2004
|
+
l.target?.value && (l.target.value = "");
|
|
1898
2005
|
} catch {
|
|
1899
2006
|
}
|
|
1900
2007
|
};
|
|
1901
2008
|
this.disposables.push(
|
|
1902
2009
|
// Capture phase to ensure we see events even if Monaco stops propagation.
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
2010
|
+
_(t, "keydown", s, !0),
|
|
2011
|
+
_(t, "beforeinput", c, !0),
|
|
2012
|
+
_(t, "input", h, !0),
|
|
2013
|
+
_(t, "paste", f, !0),
|
|
2014
|
+
_(t, "compositionstart", n, !0),
|
|
2015
|
+
_(t, "compositionupdate", a, !0),
|
|
2016
|
+
_(t, "compositionend", r, !0)
|
|
1907
2017
|
);
|
|
1908
|
-
for (const c of e)
|
|
1909
|
-
this.disposables.push(
|
|
1910
|
-
b(c, "beforeinput", u, !0),
|
|
1911
|
-
b(c, "input", h, !0),
|
|
1912
|
-
b(c, "compositionstart", (d) => {
|
|
1913
|
-
n();
|
|
1914
|
-
}, !0),
|
|
1915
|
-
b(c, "compositionupdate", (d) => {
|
|
1916
|
-
a(d);
|
|
1917
|
-
}, !0),
|
|
1918
|
-
b(c, "compositionend", (d) => {
|
|
1919
|
-
l(d);
|
|
1920
|
-
}, !0),
|
|
1921
|
-
b(c, "paste", f, !0)
|
|
1922
|
-
);
|
|
1923
2018
|
}
|
|
1924
2019
|
scheduleResync() {
|
|
1925
2020
|
this.resyncTimer || (this.resyncTimer = window.setTimeout(() => {
|
|
@@ -1940,7 +2035,7 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
1940
2035
|
const i = (t && t.length ? t : [""]).join(`
|
|
1941
2036
|
`);
|
|
1942
2037
|
if (e.getValue() === i) return;
|
|
1943
|
-
const s = this.lastCursorPos ?? this.editor.getPosition() ?? new
|
|
2038
|
+
const s = this.lastCursorPos ?? this.editor.getPosition() ?? new g.Position(1, 1);
|
|
1944
2039
|
if (this.suppressCursorSync = !0, this.applyingFromNvim = !0, e.setValue(i), this.applyingFromNvim = !1, s && this.editor.setPosition(s), this.suppressCursorSync = !1, this.delegateInsertToMonaco) {
|
|
1945
2040
|
const n = this.getActiveState();
|
|
1946
2041
|
if (n && n.model === e)
|
|
@@ -2021,11 +2116,11 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2021
2116
|
let e = 1, i = t.getLineCount();
|
|
2022
2117
|
try {
|
|
2023
2118
|
const n = this.editor.getVisibleRanges();
|
|
2024
|
-
n && n.length && (e = Math.min(...n.map((
|
|
2119
|
+
n && n.length && (e = Math.min(...n.map((r) => r.startLineNumber)), i = Math.max(...n.map((r) => r.endLineNumber)));
|
|
2025
2120
|
} catch {
|
|
2026
2121
|
}
|
|
2027
2122
|
e = Math.max(1, Math.min(e, t.getLineCount())), i = Math.max(1, Math.min(i, t.getLineCount()));
|
|
2028
|
-
const s = await this.execLua(
|
|
2123
|
+
const s = await this.execLua(ae, [e, i]);
|
|
2029
2124
|
this.applySearchHighlights(s, t);
|
|
2030
2125
|
} catch {
|
|
2031
2126
|
}
|
|
@@ -2042,49 +2137,49 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2042
2137
|
this.clearSearchHighlights();
|
|
2043
2138
|
return;
|
|
2044
2139
|
}
|
|
2045
|
-
const n = Array.isArray(i.matches) ? i.matches : [],
|
|
2046
|
-
if (
|
|
2047
|
-
const d = e.getLineContent(
|
|
2048
|
-
return
|
|
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, c = [], h = 2e3, f = /* @__PURE__ */ new Map(), l = (u) => {
|
|
2141
|
+
if (f.has(u)) return f.get(u);
|
|
2142
|
+
const d = e.getLineContent(u) ?? "";
|
|
2143
|
+
return f.set(u, d), d;
|
|
2049
2144
|
};
|
|
2050
|
-
for (let
|
|
2051
|
-
const d = n[
|
|
2052
|
-
if (!Number.isFinite(
|
|
2053
|
-
const
|
|
2054
|
-
if (
|
|
2055
|
-
const
|
|
2056
|
-
if (
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
range: new
|
|
2060
|
-
options: { inlineClassName:
|
|
2145
|
+
for (let u = 0; u < n.length && c.length < h; u += 1) {
|
|
2146
|
+
const d = n[u], m = Number(d?.l), p = Number(d?.s), y = Number(d?.e);
|
|
2147
|
+
if (!Number.isFinite(m) || !Number.isFinite(p) || !Number.isFinite(y)) continue;
|
|
2148
|
+
const b = m + 1;
|
|
2149
|
+
if (b < 1 || b > e.getLineCount()) continue;
|
|
2150
|
+
const w = l(b), E = v(w, Math.max(0, p)) + 1, D = v(w, Math.max(0, y)) + 1;
|
|
2151
|
+
if (D <= E) continue;
|
|
2152
|
+
const W = `${m}:${p}:${y}`, z = a && W === a ? "monaco-neovim-search-current" : "monaco-neovim-search-match";
|
|
2153
|
+
c.push({
|
|
2154
|
+
range: new g.Range(b, E, b, D),
|
|
2155
|
+
options: { inlineClassName: z }
|
|
2061
2156
|
});
|
|
2062
2157
|
}
|
|
2063
2158
|
this.ensureSearchStyle();
|
|
2064
2159
|
try {
|
|
2065
|
-
this.searchDecorationIds = this.editor.deltaDecorations(this.searchDecorationIds,
|
|
2160
|
+
this.searchDecorationIds = this.editor.deltaDecorations(this.searchDecorationIds, c);
|
|
2066
2161
|
} catch {
|
|
2067
2162
|
this.searchDecorationIds = [];
|
|
2068
2163
|
}
|
|
2069
2164
|
}
|
|
2070
2165
|
applyVisualDecorations(t, e) {
|
|
2071
2166
|
this.ensureVisualStyle();
|
|
2072
|
-
const s =
|
|
2167
|
+
const s = ge(e) === "V", n = [];
|
|
2073
2168
|
if (s) {
|
|
2074
|
-
let
|
|
2075
|
-
for (const
|
|
2076
|
-
const
|
|
2077
|
-
|
|
2169
|
+
let r = 1 / 0, a = -1 / 0;
|
|
2170
|
+
for (const c of t) {
|
|
2171
|
+
const h = c.getStartPosition(), f = c.getEndPosition();
|
|
2172
|
+
r = Math.min(r, h.lineNumber, f.lineNumber), a = Math.max(a, h.lineNumber, f.lineNumber);
|
|
2078
2173
|
}
|
|
2079
|
-
Number.isFinite(
|
|
2080
|
-
range: new
|
|
2174
|
+
Number.isFinite(r) && Number.isFinite(a) && a >= r && n.push({
|
|
2175
|
+
range: new g.Range(r, 1, a, 1),
|
|
2081
2176
|
options: { isWholeLine: !0, className: "monaco-neovim-visual-line" }
|
|
2082
2177
|
});
|
|
2083
2178
|
} else
|
|
2084
|
-
for (const
|
|
2085
|
-
const
|
|
2179
|
+
for (const r of t) {
|
|
2180
|
+
const a = r.getStartPosition(), c = r.getEndPosition();
|
|
2086
2181
|
n.push({
|
|
2087
|
-
range:
|
|
2182
|
+
range: g.Range.fromPositions(a, c),
|
|
2088
2183
|
options: { inlineClassName: "monaco-neovim-visual-inline" }
|
|
2089
2184
|
});
|
|
2090
2185
|
}
|
|
@@ -2097,26 +2192,89 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2097
2192
|
applyNvimMode(t) {
|
|
2098
2193
|
const e = typeof t == "string" ? t : "";
|
|
2099
2194
|
if (!e || e === this.lastMode) return;
|
|
2100
|
-
this.lastMode = e;
|
|
2101
|
-
const i =
|
|
2195
|
+
this.lastMode = e, x(e) && (this.ignoreNextInputEvent = !1);
|
|
2196
|
+
const i = $(e) && !this.recordingRegister;
|
|
2102
2197
|
if (i !== this.delegateInsertToMonaco) {
|
|
2103
2198
|
this.delegateInsertToMonaco = i;
|
|
2104
2199
|
const s = this.ensureActiveState();
|
|
2105
|
-
i ? (this.setPreedit(null), s && (s.shadowLines = this.editor.getModel()?.getLinesContent() ?? null, s.pendingBufEdits = [], s.pendingFullSync = !1, s.pendingCursorSync = !1)) : s && ((s.pendingBufEdits.length || s.pendingCursorSync || s.pendingFullSync) && this.flushPendingMonacoSync(), s.shadowLines = null, s.pendingBufEdits = [], s.pendingFullSync = !1, s.pendingCursorSync = !1);
|
|
2200
|
+
i ? (this.setPreedit(null), this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0, s && (s.shadowLines = this.editor.getModel()?.getLinesContent() ?? null, s.pendingBufEdits = [], s.pendingFullSync = !1, s.pendingCursorSync = !1)) : (s && ((s.pendingBufEdits.length || s.pendingCursorSync || s.pendingFullSync) && this.flushPendingMonacoSync(), s.shadowLines = null, s.pendingBufEdits = [], s.pendingFullSync = !1, s.pendingCursorSync = !1), this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0);
|
|
2201
|
+
}
|
|
2202
|
+
if (this.exitingInsertMode && !$(e)) {
|
|
2203
|
+
this.exitInsertTimer && (clearTimeout(this.exitInsertTimer), this.exitInsertTimer = null), this.exitingInsertMode = !1;
|
|
2204
|
+
const s = this.pendingKeysAfterExit;
|
|
2205
|
+
this.pendingKeysAfterExit = "", s && this.sendInput(s);
|
|
2106
2206
|
}
|
|
2107
2207
|
this.applyCursorStyle(e), this.opts.onModeChange && this.opts.onModeChange(e), this.updateVisualSelection(e), this.scheduleSearchHighlightRefresh();
|
|
2108
2208
|
}
|
|
2209
|
+
armInsertExit() {
|
|
2210
|
+
this.exitingInsertMode = !0, this.pendingKeysAfterExit = "", this.exitInsertTimer && (clearTimeout(this.exitInsertTimer), this.exitInsertTimer = null), this.exitInsertTimer = window.setTimeout(() => {
|
|
2211
|
+
if (this.exitInsertTimer = null, !this.exitingInsertMode) return;
|
|
2212
|
+
this.exitingInsertMode = !1;
|
|
2213
|
+
const t = this.pendingKeysAfterExit;
|
|
2214
|
+
this.pendingKeysAfterExit = "", t && this.sendInput(t);
|
|
2215
|
+
}, 200);
|
|
2216
|
+
}
|
|
2217
|
+
syncDotRepeatToNvim() {
|
|
2218
|
+
if (!this.session || !this.session.isRunning()) return;
|
|
2219
|
+
const t = this.dotRepeatKeys, e = this.dotRepeatBackspaces;
|
|
2220
|
+
if (this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0, !t) return;
|
|
2221
|
+
this.execLua(`
|
|
2222
|
+
local api = vim.api
|
|
2223
|
+
local keys, bs = ...
|
|
2224
|
+
keys = type(keys) == "string" and keys or ""
|
|
2225
|
+
if keys == "" then
|
|
2226
|
+
return
|
|
2227
|
+
end
|
|
2228
|
+
local mode = (api.nvim_get_mode() or {}).mode or ""
|
|
2229
|
+
if not mode:match("^[iR]") then
|
|
2230
|
+
return
|
|
2231
|
+
end
|
|
2232
|
+
local ei = vim.opt.ei:get()
|
|
2233
|
+
vim.opt.ei = "all"
|
|
2234
|
+
local curr_win = api.nvim_get_current_win()
|
|
2235
|
+
local temp_buf = api.nvim_create_buf(false, true)
|
|
2236
|
+
local temp_win = api.nvim_open_win(temp_buf, true, { external = true, width = 1, height = 1 })
|
|
2237
|
+
bs = tonumber(bs) or 0
|
|
2238
|
+
if bs > 0 then
|
|
2239
|
+
pcall(api.nvim_buf_set_lines, temp_buf, 0, -1, false, { ("x"):rep(bs) })
|
|
2240
|
+
pcall(api.nvim_win_set_cursor, temp_win, { 1, bs })
|
|
2241
|
+
end
|
|
2242
|
+
local tc = api.nvim_replace_termcodes(keys, true, true, true)
|
|
2243
|
+
api.nvim_feedkeys(tc, "n", true)
|
|
2244
|
+
pcall(api.nvim_set_current_win, curr_win)
|
|
2245
|
+
pcall(api.nvim_win_close, temp_win, true)
|
|
2246
|
+
pcall(api.nvim_buf_delete, temp_buf, { force = true })
|
|
2247
|
+
vim.opt.ei = ei
|
|
2248
|
+
`, [t, e]).catch(() => {
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2109
2251
|
handleKey(t) {
|
|
2110
2252
|
const e = t.browserEvent;
|
|
2111
|
-
if (e.defaultPrevented && e.key !== "Escape") return;
|
|
2253
|
+
if (e.defaultPrevented && e.key !== "Escape" && e.key !== "Enter") return;
|
|
2254
|
+
if (this.exitingInsertMode) {
|
|
2255
|
+
if (e.key === "Escape") {
|
|
2256
|
+
t.preventDefault();
|
|
2257
|
+
return;
|
|
2258
|
+
}
|
|
2259
|
+
if (e.key === "Process" || e.keyCode === 229) {
|
|
2260
|
+
this.compositionActive = !0;
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
if (this.compositionActive || e.isComposing || !this.opts.shouldHandleKey(e) || this.hasExplicitModAllowlist(!1) && !this.shouldForwardModifiedKeys(e, !1))
|
|
2264
|
+
return;
|
|
2265
|
+
const s = this.opts.translateKey(e);
|
|
2266
|
+
if (!s) return;
|
|
2267
|
+
this.ignoreNextInputEvent = !0, t.preventDefault(), this.pendingKeysAfterExit += s;
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2112
2270
|
if (this.delegateInsertToMonaco) {
|
|
2113
2271
|
if (e.key === "Escape") {
|
|
2114
|
-
t.preventDefault(), this.flushPendingMonacoSync(), this.sendInput("<Esc>");
|
|
2272
|
+
t.preventDefault(), this.armInsertExit(), this.flushPendingMonacoSync(), this.syncDotRepeatToNvim(), this.sendInput("<Esc>");
|
|
2115
2273
|
return;
|
|
2116
2274
|
}
|
|
2117
2275
|
if (!this.opts.shouldHandleKey(e) || this.hasExplicitModAllowlist(!0) && !this.shouldForwardModifiedKeys(e, !0))
|
|
2118
2276
|
return;
|
|
2119
|
-
if (e.ctrlKey || e.altKey || e.metaKey) {
|
|
2277
|
+
if ((e.ctrlKey || e.altKey || e.metaKey) && !e.getModifierState?.("AltGraph")) {
|
|
2120
2278
|
const s = this.opts.translateKey(e);
|
|
2121
2279
|
if (!s) return;
|
|
2122
2280
|
t.preventDefault(), this.flushPendingMonacoSync(), this.sendInput(s);
|
|
@@ -2124,6 +2282,11 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2124
2282
|
}
|
|
2125
2283
|
return;
|
|
2126
2284
|
}
|
|
2285
|
+
if (x(this.lastMode) && !this.compositionActive && !e.isComposing && !e.getModifierState?.("AltGraph") && !e.ctrlKey && !e.metaKey && typeof e.key == "string" && e.key.length === 1) {
|
|
2286
|
+
const s = /^[\x20-\x7E]$/.test(e.key);
|
|
2287
|
+
if (!!!(e.altKey && s))
|
|
2288
|
+
return this.opts.shouldHandleKey(e), void 0;
|
|
2289
|
+
}
|
|
2127
2290
|
if (this.ignoreTextKeydownUntil > 0 && typeof e.key == "string" && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (typeof performance < "u" && performance.now ? performance.now() : Date.now()) < this.ignoreTextKeydownUntil)
|
|
2128
2291
|
return;
|
|
2129
2292
|
if (e.key === "Process" || e.keyCode === 229) {
|
|
@@ -2133,12 +2296,52 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2133
2296
|
if (this.compositionActive || e.isComposing || !this.opts.shouldHandleKey(e) || this.hasExplicitModAllowlist(!1) && !this.shouldForwardModifiedKeys(e, !1))
|
|
2134
2297
|
return;
|
|
2135
2298
|
const i = this.opts.translateKey(e);
|
|
2136
|
-
i && (this.ignoreNextInputEvent = !0, t.preventDefault(), this.sendInput(i));
|
|
2299
|
+
i && (this.ignoreNextInputEvent = !0, t.preventDefault(), this.lastMode.startsWith("n") && (i === "q" ? this.recordingRegister ? (this.recordingRegister = "", this.scheduleRecordingRefresh()) : this.recordingRefreshArmed = !0 : this.recordingRefreshArmed && typeof i == "string" && i.length === 1 && (this.recordingRefreshArmed = !1, this.recordingRegister = i, this.scheduleRecordingRefresh())), this.sendInput(i));
|
|
2137
2300
|
}
|
|
2138
2301
|
handleMouse(t) {
|
|
2139
2302
|
if (this.delegateInsertToMonaco || !this.bufHandle || !t.target?.position) return;
|
|
2140
|
-
const { lineNumber: e, column: i } = t.target.position, s = this.editor.getModel(), n = Math.max(0, i - 1),
|
|
2141
|
-
this.sendNotify("nvim_win_set_cursor", [0, [e,
|
|
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 ? C(r, n) : n;
|
|
2304
|
+
this.sendNotify("nvim_win_set_cursor", [0, [e, a]]);
|
|
2305
|
+
}
|
|
2306
|
+
handleSelection(t) {
|
|
2307
|
+
if (this.delegateInsertToMonaco || !this.session || !this.session.isRunning() || !this.bufHandle || this.suppressCursorSync || this.compositionActive || t?.isComposing) return;
|
|
2308
|
+
const e = t.selection;
|
|
2309
|
+
if (e && t.source === "mouse") {
|
|
2310
|
+
if (e.isEmpty()) {
|
|
2311
|
+
I(this.lastMode) && this.sendInput("<Esc>");
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
this.pendingSelection = new g.Selection(
|
|
2315
|
+
e.selectionStartLineNumber,
|
|
2316
|
+
e.selectionStartColumn,
|
|
2317
|
+
e.positionLineNumber,
|
|
2318
|
+
e.positionColumn
|
|
2319
|
+
), !this.selectionSyncTimer && (this.selectionSyncTimer = window.setTimeout(() => {
|
|
2320
|
+
this.selectionSyncTimer = null;
|
|
2321
|
+
const i = this.pendingSelection;
|
|
2322
|
+
this.pendingSelection = null, i && this.syncVisualSelectionToNvim(i).catch(() => {
|
|
2323
|
+
});
|
|
2324
|
+
}, 80));
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
async syncVisualSelectionToNvim(t) {
|
|
2328
|
+
if (this.delegateInsertToMonaco || !this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
2329
|
+
const e = this.editor.getModel();
|
|
2330
|
+
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) ?? "", c = e.getLineContent(n) ?? "", h = C(a, s), f = C(c, r);
|
|
2332
|
+
await this.execLua(`
|
|
2333
|
+
local api = vim.api
|
|
2334
|
+
local fn = vim.fn
|
|
2335
|
+
local a_line, a_col0, b_line, b_col0 = ...
|
|
2336
|
+
local mode = api.nvim_get_mode().mode or ""
|
|
2337
|
+
if mode:match("[vV\\022]") then
|
|
2338
|
+
local esc = api.nvim_replace_termcodes("<Esc>", true, true, true)
|
|
2339
|
+
api.nvim_feedkeys(esc, "n", false)
|
|
2340
|
+
end
|
|
2341
|
+
api.nvim_win_set_cursor(0, { a_line, a_col0 })
|
|
2342
|
+
api.nvim_feedkeys("v", "n", false)
|
|
2343
|
+
api.nvim_win_set_cursor(0, { b_line, b_col0 })
|
|
2344
|
+
`, [i, h, n, f]);
|
|
2142
2345
|
}
|
|
2143
2346
|
sendInput(t) {
|
|
2144
2347
|
this.sendNotify("nvim_input", [t]);
|
|
@@ -2206,14 +2409,22 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2206
2409
|
i.pendingFullSync = !0, i.pendingCursorSync = !0, i.shadowLines = e.getLinesContent(), this.scheduleFlushPendingMonacoSync();
|
|
2207
2410
|
return;
|
|
2208
2411
|
}
|
|
2209
|
-
const s = t.changes[0], n = s.range,
|
|
2210
|
-
if (
|
|
2211
|
-
if (i.shadowLines[
|
|
2412
|
+
const s = t.changes[0], n = s.range, r = n.startLineNumber - 1, a = n.endLineNumber - 1;
|
|
2413
|
+
if (r < 0 || a < 0) return;
|
|
2414
|
+
if (i.shadowLines[r] == null || i.shadowLines[a] == null) {
|
|
2212
2415
|
i.pendingFullSync = !0, i.pendingCursorSync = !0, i.shadowLines = e.getLinesContent(), this.scheduleFlushPendingMonacoSync();
|
|
2213
2416
|
return;
|
|
2214
2417
|
}
|
|
2215
|
-
const
|
|
2216
|
-
|
|
2418
|
+
const c = i.shadowLines[r] ?? "", h = i.shadowLines[a] ?? "", f = Math.max(0, n.startColumn - 1), l = Math.max(0, n.endColumn - 1), u = C(c, f), d = C(h, l), m = String(s.text ?? ""), p = m.length ? m.split(/\r?\n/) : [];
|
|
2419
|
+
try {
|
|
2420
|
+
const b = Math.max(0, Number(s.rangeLength ?? 0) || 0);
|
|
2421
|
+
r === a && !m.includes(`
|
|
2422
|
+
`) ? (b > 0 && (this.dotRepeatBackspaces += b, this.dotRepeatKeys += "<BS>".repeat(b)), m && (this.dotRepeatKeys += L(m, !0)), this.dotRepeatKeys.length > 2e4 && (this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0)) : (this.dotRepeatKeys = "", this.dotRepeatBackspaces = 0);
|
|
2423
|
+
} catch {
|
|
2424
|
+
}
|
|
2425
|
+
i.pendingBufEdits.push({ startRow: r, startColByte: u, endRow: a, endColByte: d, lines: p }), ye(i.shadowLines, r, f, a, l, m), i.pendingCursorSync = !0;
|
|
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();
|
|
2217
2428
|
}
|
|
2218
2429
|
scheduleCursorSyncToNvim() {
|
|
2219
2430
|
if (!this.delegateInsertToMonaco) return;
|
|
@@ -2221,9 +2432,11 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2221
2432
|
t && (t.pendingCursorSync = !0, this.scheduleFlushPendingMonacoSync());
|
|
2222
2433
|
}
|
|
2223
2434
|
scheduleFlushPendingMonacoSync() {
|
|
2224
|
-
|
|
2435
|
+
if (this.cursorSyncTimer) return;
|
|
2436
|
+
const t = Math.max(0, Number(this.opts.insertSyncDebounceMs) || 0);
|
|
2437
|
+
this.cursorSyncTimer = window.setTimeout(() => {
|
|
2225
2438
|
this.cursorSyncTimer = null, this.flushPendingMonacoSync();
|
|
2226
|
-
},
|
|
2439
|
+
}, t);
|
|
2227
2440
|
}
|
|
2228
2441
|
flushPendingMonacoSync() {
|
|
2229
2442
|
if (!this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
@@ -2231,7 +2444,7 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2231
2444
|
if (!t) return;
|
|
2232
2445
|
const e = this.editor.getModel();
|
|
2233
2446
|
if (e && t.model === e) {
|
|
2234
|
-
if (t.pendingFullSync) {
|
|
2447
|
+
if (!t.pendingFullSync && t.pendingBufEdits.length > 1 && (t.pendingFullSync = !0), t.pendingFullSync) {
|
|
2235
2448
|
const i = e.getLinesContent();
|
|
2236
2449
|
this.sendNotify("nvim_buf_set_lines", [this.bufHandle, 0, -1, !1, i]), t.pendingFullSync = !1, t.pendingBufEdits = [], t.shadowLines = i.slice();
|
|
2237
2450
|
} else if (t.pendingBufEdits.length) {
|
|
@@ -2246,7 +2459,7 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2246
2459
|
if (!this.session || !this.session.isRunning() || !this.bufHandle) return;
|
|
2247
2460
|
const t = this.editor.getModel(), e = this.editor.getPosition();
|
|
2248
2461
|
if (!t || !e) return;
|
|
2249
|
-
const i = e.lineNumber, s = t.getLineContent(i) ?? "", n =
|
|
2462
|
+
const i = e.lineNumber, s = t.getLineContent(i) ?? "", n = C(s, Math.max(0, e.column - 1));
|
|
2250
2463
|
this.sendNotify("nvim_win_set_cursor", [0, [i, n]]);
|
|
2251
2464
|
}
|
|
2252
2465
|
scheduleVisualSelectionRefresh() {
|
|
@@ -2260,7 +2473,7 @@ ${f}`), i < n && s.length > 0 && (f += `
|
|
|
2260
2473
|
const t = await this.rpcCall("nvim_get_api_info", []), e = Array.isArray(t) ? Number(t[0]) : NaN;
|
|
2261
2474
|
if (!Number.isFinite(e) || e <= 0) return;
|
|
2262
2475
|
this.nvimChannelId = e;
|
|
2263
|
-
const i = this.opts.wrappedLineMotions ? "true" : "false", s = this.opts.scrollMotions ? "true" : "false", n = this.opts.syncScrolloff && this.opts.scrolloff == null ? "true" : "false",
|
|
2476
|
+
const i = this.opts.wrappedLineMotions ? "true" : "false", s = this.opts.scrollMotions ? "true" : "false", n = this.opts.syncScrolloff && this.opts.scrolloff == null ? "true" : "false", r = this.opts.hostCommands ? "true" : "false", a = `
|
|
2264
2477
|
local chan = ...
|
|
2265
2478
|
local api = vim.api
|
|
2266
2479
|
vim.g.monaco_neovim_wasm_chan = chan
|
|
@@ -2280,6 +2493,11 @@ local function send_scrolloff()
|
|
|
2280
2493
|
vim.rpcnotify(chan, "monaco_scrolloff", so)
|
|
2281
2494
|
end
|
|
2282
2495
|
|
|
2496
|
+
local function send_recording()
|
|
2497
|
+
local r = vim.fn.reg_recording() or ""
|
|
2498
|
+
vim.rpcnotify(chan, "monaco_recording", r)
|
|
2499
|
+
end
|
|
2500
|
+
|
|
2283
2501
|
if ${i} then
|
|
2284
2502
|
pcall(vim.cmd, "silent! source $HOME/.config/nvim/monaco-neovim-wasm/motion.vim")
|
|
2285
2503
|
end
|
|
@@ -2287,7 +2505,7 @@ end
|
|
|
2287
2505
|
if ${s} then
|
|
2288
2506
|
pcall(vim.cmd, "silent! source $HOME/.config/nvim/monaco-neovim-wasm/scrolling.vim")
|
|
2289
2507
|
end
|
|
2290
|
-
if ${
|
|
2508
|
+
if ${r} then
|
|
2291
2509
|
pcall(vim.cmd, "silent! source $HOME/.config/nvim/monaco-neovim-wasm/host-commands.vim")
|
|
2292
2510
|
end
|
|
2293
2511
|
|
|
@@ -2304,6 +2522,10 @@ api.nvim_create_autocmd({ "VisualEnter", "VisualLeave" }, {
|
|
|
2304
2522
|
group = group,
|
|
2305
2523
|
callback = function() send_mode(); send_cursor() end,
|
|
2306
2524
|
})
|
|
2525
|
+
api.nvim_create_autocmd({ "RecordingEnter", "RecordingLeave" }, {
|
|
2526
|
+
group = group,
|
|
2527
|
+
callback = function() send_recording() end,
|
|
2528
|
+
})
|
|
2307
2529
|
if ${n} then
|
|
2308
2530
|
api.nvim_create_autocmd({ "OptionSet" }, {
|
|
2309
2531
|
group = group,
|
|
@@ -2332,13 +2554,14 @@ api.nvim_create_autocmd({ "BufDelete" }, {
|
|
|
2332
2554
|
send_mode()
|
|
2333
2555
|
send_cursor()
|
|
2334
2556
|
send_scrolloff()
|
|
2557
|
+
send_recording()
|
|
2335
2558
|
vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
2336
2559
|
buf = api.nvim_get_current_buf(),
|
|
2337
2560
|
name = api.nvim_buf_get_name(api.nvim_get_current_buf()) or "",
|
|
2338
2561
|
filetype = (vim.bo[api.nvim_get_current_buf()] and vim.bo[api.nvim_get_current_buf()].filetype) or "",
|
|
2339
2562
|
})
|
|
2340
2563
|
`;
|
|
2341
|
-
await this.execLua(
|
|
2564
|
+
await this.execLua(a, [e]), this.hostAutocmdInstalled = !0;
|
|
2342
2565
|
} catch {
|
|
2343
2566
|
}
|
|
2344
2567
|
}
|
|
@@ -2369,42 +2592,42 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2369
2592
|
return;
|
|
2370
2593
|
}
|
|
2371
2594
|
try {
|
|
2372
|
-
const
|
|
2373
|
-
if (
|
|
2374
|
-
const
|
|
2375
|
-
await this.openText({ path: n, text:
|
|
2376
|
-
} catch (
|
|
2377
|
-
this.opts.status(`edit failed: ${
|
|
2595
|
+
const r = await s.readFile(n);
|
|
2596
|
+
if (r == null) return;
|
|
2597
|
+
const a = r instanceof Uint8Array ? new TextDecoder().decode(r) : String(r);
|
|
2598
|
+
await this.openText({ path: n, text: a }), this.opts.status(`opened: ${n}`);
|
|
2599
|
+
} catch (r) {
|
|
2600
|
+
this.opts.status(`edit failed: ${r?.message ?? r}`, !0);
|
|
2378
2601
|
}
|
|
2379
2602
|
return;
|
|
2380
2603
|
}
|
|
2381
2604
|
if (e === "write" || e === "wq") {
|
|
2382
|
-
const n = this.editor.getModel(),
|
|
2383
|
-
let
|
|
2384
|
-
if (!
|
|
2605
|
+
const n = this.editor.getModel(), r = n ? n.getValue() : "";
|
|
2606
|
+
let a = typeof i.path == "string" ? String(i.path) : "";
|
|
2607
|
+
if (!a)
|
|
2385
2608
|
try {
|
|
2386
|
-
const
|
|
2387
|
-
typeof
|
|
2609
|
+
const c = await this.rpcCall("nvim_buf_get_name", [0]);
|
|
2610
|
+
typeof c == "string" && (a = c);
|
|
2388
2611
|
} catch {
|
|
2389
2612
|
}
|
|
2390
|
-
if (
|
|
2613
|
+
if (a || (a = this.opts.seedName), !s.writeFile) {
|
|
2391
2614
|
this.opts.status("write: fileSystem.writeFile not set", !0);
|
|
2392
2615
|
return;
|
|
2393
2616
|
}
|
|
2394
2617
|
try {
|
|
2395
|
-
await s.writeFile(
|
|
2618
|
+
await s.writeFile(a, r);
|
|
2396
2619
|
try {
|
|
2397
|
-
await this.rpcCall("nvim_buf_set_name", [0,
|
|
2620
|
+
await this.rpcCall("nvim_buf_set_name", [0, a]);
|
|
2398
2621
|
} catch {
|
|
2399
2622
|
}
|
|
2400
2623
|
try {
|
|
2401
2624
|
await this.rpcCall("nvim_buf_set_option", [0, "modified", !1]);
|
|
2402
2625
|
} catch {
|
|
2403
2626
|
}
|
|
2404
|
-
const
|
|
2405
|
-
|
|
2406
|
-
} catch (
|
|
2407
|
-
this.opts.status(`write failed: ${
|
|
2627
|
+
const c = this.getActiveState();
|
|
2628
|
+
c && (c.name && c.name !== a && this.buffersByName.delete(c.name), c.name = a, this.buffersByName.set(a, c.id)), this.opts.status(`written: ${a}`), e === "wq" && this.opts.status("wq requested (provide onHostCommand to close the editor)");
|
|
2629
|
+
} catch (c) {
|
|
2630
|
+
this.opts.status(`write failed: ${c?.message ?? c}`, !0);
|
|
2408
2631
|
}
|
|
2409
2632
|
return;
|
|
2410
2633
|
}
|
|
@@ -2425,19 +2648,19 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2425
2648
|
await this.rpcCall("nvim_buf_attach", [e, !1, {}]);
|
|
2426
2649
|
} catch {
|
|
2427
2650
|
}
|
|
2428
|
-
let
|
|
2651
|
+
let a = [""];
|
|
2429
2652
|
try {
|
|
2430
|
-
const
|
|
2431
|
-
Array.isArray(
|
|
2653
|
+
const u = await this.rpcCall("nvim_buf_get_lines", [e, 0, -1, !1]);
|
|
2654
|
+
Array.isArray(u) && (a = u.map((d) => String(d ?? "")));
|
|
2432
2655
|
} catch {
|
|
2433
2656
|
}
|
|
2434
|
-
const
|
|
2435
|
-
`),
|
|
2657
|
+
const c = g.Uri.from({ scheme: "nvim", authority: "buf", path: `/${e}` }), h = a.join(`
|
|
2658
|
+
`), f = s && g.languages.getLanguages().some((u) => u.id === s), l = g.editor.createModel(h, f ? s : void 0, c);
|
|
2436
2659
|
n = {
|
|
2437
2660
|
id: e,
|
|
2438
2661
|
name: i || "",
|
|
2439
2662
|
filetype: s || "",
|
|
2440
|
-
model:
|
|
2663
|
+
model: l,
|
|
2441
2664
|
createdModel: !0,
|
|
2442
2665
|
shadowLines: null,
|
|
2443
2666
|
pendingBufEdits: [],
|
|
@@ -2480,8 +2703,8 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2480
2703
|
let n = this.buffersByName.get(s) ?? null;
|
|
2481
2704
|
if (!n)
|
|
2482
2705
|
try {
|
|
2483
|
-
const
|
|
2484
|
-
n =
|
|
2706
|
+
const r = await this.rpcCall("nvim_create_buf", [!0, !1]);
|
|
2707
|
+
n = S(r) ?? Number(r);
|
|
2485
2708
|
} catch {
|
|
2486
2709
|
n = null;
|
|
2487
2710
|
}
|
|
@@ -2537,10 +2760,10 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2537
2760
|
navigator.clipboard.readText().then((s) => e(s || "")).catch(() => e(""));
|
|
2538
2761
|
}
|
|
2539
2762
|
updateCursor(t, e) {
|
|
2540
|
-
const i = this.editor.getModel(), s = Math.max(1, Number(t) || 1), n = Math.max(1, Number(e) || 1),
|
|
2541
|
-
if (this.lastCursorPos =
|
|
2542
|
-
const
|
|
2543
|
-
|
|
2763
|
+
const i = this.editor.getModel(), s = Math.max(1, Number(t) || 1), n = Math.max(1, Number(e) || 1), r = i ? i.validatePosition(new g.Position(s, n)) : new g.Position(s, n);
|
|
2764
|
+
if (this.lastCursorPos = r, this.compositionActive) return;
|
|
2765
|
+
const a = this.editor.getPosition();
|
|
2766
|
+
a && a.lineNumber === r.lineNumber && a.column === r.column || (this.suppressCursorSync = !0, this.editor.setPosition(this.lastCursorPos), this.visualSelectionActive && this.editor.setSelection(new g.Selection(r.lineNumber, r.column, r.lineNumber, r.column)), this.applyScrolloff(this.lastCursorPos) || this.editor.revealPositionInCenterIfOutsideViewport(this.lastCursorPos), this.suppressCursorSync = !1), this.scheduleSearchHighlightRefresh();
|
|
2544
2767
|
}
|
|
2545
2768
|
scheduleCursorRefresh() {
|
|
2546
2769
|
if (this.compositionActive || this.cursorRefreshTimer) return;
|
|
@@ -2564,12 +2787,12 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2564
2787
|
try {
|
|
2565
2788
|
const e = await this.rpcCall("nvim_win_get_cursor", [0]);
|
|
2566
2789
|
if (Array.isArray(e) && e.length >= 2) {
|
|
2567
|
-
const i = Number(e[0]), s = Number(e[1]), n =
|
|
2568
|
-
if (this.optimisticCursorPos && this.optimisticCursorUntil >
|
|
2569
|
-
const
|
|
2570
|
-
|
|
2790
|
+
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
|
+
if (this.optimisticCursorPos && this.optimisticCursorUntil > a) {
|
|
2792
|
+
const c = this.optimisticCursorPrevPos;
|
|
2793
|
+
c && r.lineNumber === c.lineNumber && r.column === c.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));
|
|
2571
2794
|
} else
|
|
2572
|
-
this.optimisticCursorPos = null, this.optimisticCursorPrevPos = null, this.optimisticCursorUntil = 0, this.updateCursor(
|
|
2795
|
+
this.optimisticCursorPos = null, this.optimisticCursorPrevPos = null, this.optimisticCursorUntil = 0, this.updateCursor(r.lineNumber, r.column);
|
|
2573
2796
|
}
|
|
2574
2797
|
if (!this.lastMode)
|
|
2575
2798
|
try {
|
|
@@ -2587,11 +2810,11 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2587
2810
|
}
|
|
2588
2811
|
}
|
|
2589
2812
|
applyCursorStyle(t) {
|
|
2590
|
-
const e = typeof t == "string" ? t : "", i = e.startsWith("i") || e.startsWith("R"), s = i ? "line" : "block", n = i ? "blink" : "solid",
|
|
2591
|
-
s === this.lastCursorStyle && n === this.lastCursorBlink &&
|
|
2813
|
+
const e = typeof t == "string" ? t : "", i = e.startsWith("i") || e.startsWith("R"), s = i ? "line" : "block", n = i ? "blink" : "solid", r = i ? this.initialCursorWidth || 1 : this.typicalFullWidth;
|
|
2814
|
+
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);
|
|
2592
2815
|
}
|
|
2593
2816
|
async updateVisualSelection(t) {
|
|
2594
|
-
const e =
|
|
2817
|
+
const e = I(t), i = ++this.visualSelectionToken;
|
|
2595
2818
|
if (!e) {
|
|
2596
2819
|
this.clearVisualDecorations();
|
|
2597
2820
|
return;
|
|
@@ -2604,13 +2827,13 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2604
2827
|
}
|
|
2605
2828
|
}
|
|
2606
2829
|
async fetchVisualRanges() {
|
|
2607
|
-
const t = await this.execLua(
|
|
2608
|
-
return Array.isArray(t) ? t.map(
|
|
2830
|
+
const t = await this.execLua(oe, []);
|
|
2831
|
+
return Array.isArray(t) ? t.map(de(this.editor)).filter((i) => !!i) : [];
|
|
2609
2832
|
}
|
|
2610
2833
|
async syncVisualSelectionColor() {
|
|
2611
2834
|
try {
|
|
2612
|
-
const e = await this.fetchVisualBg() || "#3e4451", i =
|
|
2613
|
-
|
|
2835
|
+
const e = await this.fetchVisualBg() || "#3e4451", i = H(e, 0.45), s = H(e, 0.3);
|
|
2836
|
+
g.editor.defineTheme(this.opts.visualThemeName, {
|
|
2614
2837
|
base: "vs-dark",
|
|
2615
2838
|
inherit: !0,
|
|
2616
2839
|
rules: [],
|
|
@@ -2624,19 +2847,19 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2624
2847
|
}
|
|
2625
2848
|
async fetchVisualBg() {
|
|
2626
2849
|
try {
|
|
2627
|
-
const t = await this.rpcCall("nvim_get_hl", [0, { name: "Visual", link: !1 }]), e =
|
|
2850
|
+
const t = await this.rpcCall("nvim_get_hl", [0, { name: "Visual", link: !1 }]), e = K(t);
|
|
2628
2851
|
if (e) return e;
|
|
2629
2852
|
} catch {
|
|
2630
2853
|
}
|
|
2631
2854
|
try {
|
|
2632
|
-
const t = await this.rpcCall("nvim_get_hl_by_name", ["Visual", !0]), e =
|
|
2855
|
+
const t = await this.rpcCall("nvim_get_hl_by_name", ["Visual", !0]), e = K(t);
|
|
2633
2856
|
if (e) return e;
|
|
2634
2857
|
} catch {
|
|
2635
2858
|
}
|
|
2636
2859
|
return null;
|
|
2637
2860
|
}
|
|
2638
2861
|
async seedBuffer(t, e) {
|
|
2639
|
-
const i =
|
|
2862
|
+
const i = S(t);
|
|
2640
2863
|
if (!i || i <= 0) return null;
|
|
2641
2864
|
const s = e ?? this.opts.seedLines;
|
|
2642
2865
|
if (!s || !s.length) return null;
|
|
@@ -2647,71 +2870,105 @@ vim.rpcnotify(chan, "monaco_buf_enter", {
|
|
|
2647
2870
|
}
|
|
2648
2871
|
}
|
|
2649
2872
|
}
|
|
2650
|
-
function
|
|
2651
|
-
return new
|
|
2873
|
+
function _e(o, t = {}) {
|
|
2874
|
+
return new le(o, t);
|
|
2652
2875
|
}
|
|
2653
|
-
function
|
|
2654
|
-
return Math.min(Math.max(
|
|
2876
|
+
function M(o, t, e) {
|
|
2877
|
+
return Math.min(Math.max(o, t), e);
|
|
2655
2878
|
}
|
|
2656
|
-
function
|
|
2657
|
-
|
|
2879
|
+
function k(o) {
|
|
2880
|
+
try {
|
|
2881
|
+
return new TextEncoder().encode(String(o ?? "")).length;
|
|
2882
|
+
} catch {
|
|
2883
|
+
return String(o ?? "").length;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
function B(o, t, e) {
|
|
2887
|
+
const i = Math.max(1, Number(t) || 1), s = Math.max(1, (Number(e) || 0) + 1), n = o.getModel();
|
|
2658
2888
|
if (!n)
|
|
2659
2889
|
return { line: i, col: s };
|
|
2660
|
-
const
|
|
2661
|
-
return { line:
|
|
2890
|
+
const r = n.getLineCount(), a = M(i, 1, r), c = n.getLineContent(a) ?? "", h = n.getLineMaxColumn(a), f = Math.max(0, Number(e) || 0), l = v(c, f), u = M(l + 1, 1, h);
|
|
2891
|
+
return { line: a, col: u };
|
|
2892
|
+
}
|
|
2893
|
+
function L(o, t = !0) {
|
|
2894
|
+
const e = String(o ?? "");
|
|
2895
|
+
if (!e) return "";
|
|
2896
|
+
const i = e.replace(/\r\n/g, `
|
|
2897
|
+
`).replace(/\r/g, `
|
|
2898
|
+
`).replace(/</g, "<lt>");
|
|
2899
|
+
return t ? i.replace(/\n/g, "<CR>") : i;
|
|
2662
2900
|
}
|
|
2663
|
-
function
|
|
2664
|
-
const t =
|
|
2901
|
+
function ce(o) {
|
|
2902
|
+
const t = o.key;
|
|
2665
2903
|
if (!t || t === "Dead" || t === "Unidentified") return null;
|
|
2666
|
-
const e =
|
|
2667
|
-
const
|
|
2668
|
-
|
|
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, c = (l) => l === "<" ? "<lt>" : l, h = (l, u = !1) => {
|
|
2905
|
+
const d = [];
|
|
2906
|
+
i && d.push("C-"), u && r && d.push("S-"), s && d.push("A-"), n && d.push("D-");
|
|
2907
|
+
const m = a(l);
|
|
2908
|
+
return d.length ? `<${d.join("")}${m}>` : `<${m}>`;
|
|
2669
2909
|
};
|
|
2910
|
+
if (typeof o.code == "string" && o.code.startsWith("Numpad") || typeof KeyboardEvent?.DOM_KEY_LOCATION_NUMPAD == "number" && o.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD) {
|
|
2911
|
+
switch (o.code) {
|
|
2912
|
+
case "NumpadEnter":
|
|
2913
|
+
return h("kEnter", !0);
|
|
2914
|
+
case "NumpadAdd":
|
|
2915
|
+
return h("kPlus", !0);
|
|
2916
|
+
case "NumpadSubtract":
|
|
2917
|
+
return h("kMinus", !0);
|
|
2918
|
+
case "NumpadMultiply":
|
|
2919
|
+
return h("kMultiply", !0);
|
|
2920
|
+
case "NumpadDivide":
|
|
2921
|
+
return h("kDivide", !0);
|
|
2922
|
+
case "NumpadDecimal":
|
|
2923
|
+
return h("kPoint", !0);
|
|
2924
|
+
}
|
|
2925
|
+
if (/^\d$/.test(t)) return h(`k${t}`, !0);
|
|
2926
|
+
}
|
|
2670
2927
|
switch (t) {
|
|
2671
2928
|
case "Backspace":
|
|
2672
|
-
return
|
|
2929
|
+
return h("BS", !0);
|
|
2673
2930
|
case "Enter":
|
|
2674
|
-
return
|
|
2931
|
+
return h("CR", !0);
|
|
2675
2932
|
case "Escape":
|
|
2676
|
-
return
|
|
2933
|
+
return h("Esc", !0);
|
|
2677
2934
|
case "Tab":
|
|
2678
|
-
return
|
|
2935
|
+
return r && !i && !s && !n ? "<S-Tab>" : h("Tab", !0);
|
|
2679
2936
|
case "ArrowUp":
|
|
2680
|
-
return
|
|
2937
|
+
return h("Up", !0);
|
|
2681
2938
|
case "ArrowDown":
|
|
2682
|
-
return
|
|
2939
|
+
return h("Down", !0);
|
|
2683
2940
|
case "ArrowLeft":
|
|
2684
|
-
return
|
|
2941
|
+
return h("Left", !0);
|
|
2685
2942
|
case "ArrowRight":
|
|
2686
|
-
return
|
|
2943
|
+
return h("Right", !0);
|
|
2687
2944
|
case "Delete":
|
|
2688
|
-
return
|
|
2945
|
+
return h("Del", !0);
|
|
2689
2946
|
case "Home":
|
|
2690
|
-
return
|
|
2947
|
+
return h("Home", !0);
|
|
2691
2948
|
case "End":
|
|
2692
|
-
return
|
|
2949
|
+
return h("End", !0);
|
|
2693
2950
|
case "PageUp":
|
|
2694
|
-
return
|
|
2951
|
+
return h("PageUp", !0);
|
|
2695
2952
|
case "PageDown":
|
|
2696
|
-
return
|
|
2953
|
+
return h("PageDown", !0);
|
|
2697
2954
|
case "Insert":
|
|
2698
|
-
return
|
|
2955
|
+
return h("Insert", !0);
|
|
2699
2956
|
}
|
|
2700
|
-
if (/^F\d{1,2}$/.test(t)) return
|
|
2957
|
+
if (/^F\d{1,2}$/.test(t)) return h(t, !0);
|
|
2701
2958
|
if (t.length === 1) {
|
|
2702
|
-
if (!
|
|
2703
|
-
if (t === " " &&
|
|
2704
|
-
const l = /^[A-Za-z]$/.test(t) ? t.toLowerCase() : t;
|
|
2705
|
-
return `<${(
|
|
2959
|
+
if (!i && !s && !n) return c(t);
|
|
2960
|
+
if (t === " " && i && !s && !n) return "<Nul>";
|
|
2961
|
+
const l = /^[A-Za-z]$/.test(t) ? t.toLowerCase() : t, u = a(l);
|
|
2962
|
+
return `<${(i ? "C-" : "") + (s ? "A-" : "") + (n ? "D-" : "")}${u}>`;
|
|
2706
2963
|
}
|
|
2707
2964
|
return null;
|
|
2708
2965
|
}
|
|
2709
|
-
function
|
|
2710
|
-
if (!
|
|
2711
|
-
const t =
|
|
2712
|
-
if (
|
|
2966
|
+
function ue(o) {
|
|
2967
|
+
if (!o || o.length === 0) return null;
|
|
2968
|
+
const t = o[0];
|
|
2969
|
+
if (o.length === 1)
|
|
2713
2970
|
return t <= 127 ? t : t - 256;
|
|
2714
|
-
const e = new DataView(
|
|
2971
|
+
const e = new DataView(o.buffer, o.byteOffset, o.byteLength);
|
|
2715
2972
|
switch (t) {
|
|
2716
2973
|
case 204:
|
|
2717
2974
|
return e.getUint8(1);
|
|
@@ -2733,77 +2990,77 @@ function re(r) {
|
|
|
2733
2990
|
return t;
|
|
2734
2991
|
}
|
|
2735
2992
|
}
|
|
2736
|
-
function
|
|
2737
|
-
return
|
|
2993
|
+
function he(o) {
|
|
2994
|
+
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;
|
|
2738
2995
|
}
|
|
2739
|
-
function
|
|
2740
|
-
if (
|
|
2741
|
-
const e =
|
|
2996
|
+
function S(o) {
|
|
2997
|
+
if (o && typeof o == "object" && typeof o.type == "number") {
|
|
2998
|
+
const e = he(o.data);
|
|
2742
2999
|
if (e) {
|
|
2743
|
-
const i =
|
|
3000
|
+
const i = ue(e);
|
|
2744
3001
|
if (i != null && i > 0) return i;
|
|
2745
3002
|
}
|
|
2746
3003
|
}
|
|
2747
|
-
const t = Number(
|
|
3004
|
+
const t = Number(o);
|
|
2748
3005
|
return Number.isInteger(t) && t > 0 ? t : null;
|
|
2749
3006
|
}
|
|
2750
|
-
function v(
|
|
3007
|
+
function v(o, t) {
|
|
2751
3008
|
let e = 0, i = 0;
|
|
2752
3009
|
const s = Math.max(0, Number(t) || 0);
|
|
2753
3010
|
for (; e < s; ) {
|
|
2754
|
-
if (i >=
|
|
3011
|
+
if (i >= o.length)
|
|
2755
3012
|
return i + (s - e);
|
|
2756
|
-
const n =
|
|
2757
|
-
e +=
|
|
3013
|
+
const n = o.codePointAt(i), r = P(n ?? 0);
|
|
3014
|
+
e += r, i += r === 4 ? 2 : 1;
|
|
2758
3015
|
}
|
|
2759
3016
|
return i;
|
|
2760
3017
|
}
|
|
2761
|
-
function
|
|
3018
|
+
function C(o, t) {
|
|
2762
3019
|
const e = Math.max(0, Number(t) || 0);
|
|
2763
3020
|
let i = 0, s = 0;
|
|
2764
|
-
for (; s < e && s <
|
|
2765
|
-
const n =
|
|
2766
|
-
i +=
|
|
3021
|
+
for (; s < e && s < o.length; ) {
|
|
3022
|
+
const n = o.codePointAt(s), r = P(n ?? 0);
|
|
3023
|
+
i += r, s += r === 4 ? 2 : 1;
|
|
2767
3024
|
}
|
|
2768
3025
|
return i;
|
|
2769
3026
|
}
|
|
2770
|
-
function
|
|
2771
|
-
return
|
|
3027
|
+
function P(o) {
|
|
3028
|
+
return o == null ? 0 : o <= 127 ? 1 : o <= 2047 ? 2 : o >= 55296 && o <= 57343 ? 4 : o < 65535 ? 3 : 4;
|
|
2772
3029
|
}
|
|
2773
|
-
function
|
|
3030
|
+
function de(o) {
|
|
2774
3031
|
return (t) => {
|
|
2775
3032
|
if (!t || !t.start || !t.end) return null;
|
|
2776
|
-
const e =
|
|
2777
|
-
return !e || !i ? null : new
|
|
3033
|
+
const e = F(o, t.start, !1), i = F(o, t.end, !!t.inclusive);
|
|
3034
|
+
return !e || !i ? null : new g.Selection(e.lineNumber, e.column, i.lineNumber, i.column);
|
|
2778
3035
|
};
|
|
2779
3036
|
}
|
|
2780
|
-
function
|
|
3037
|
+
function F(o, t, e) {
|
|
2781
3038
|
if (!t || typeof t.line != "number" || typeof t.col != "number") return null;
|
|
2782
|
-
const i =
|
|
3039
|
+
const i = o.getModel(), s = M(t.line + 1, 1, i?.getLineCount() || 1 / 0);
|
|
2783
3040
|
if (!i) {
|
|
2784
|
-
const
|
|
2785
|
-
return { lineNumber: s, column:
|
|
3041
|
+
const f = Math.max(1, t.col + 1);
|
|
3042
|
+
return { lineNumber: s, column: f + (e ? 1 : 0) };
|
|
2786
3043
|
}
|
|
2787
|
-
const n = i.getLineContent(s) ?? "",
|
|
2788
|
-
let
|
|
3044
|
+
const n = i.getLineContent(s) ?? "", r = Math.max(0, Number(t.col) || 0);
|
|
3045
|
+
let a = r;
|
|
2789
3046
|
if (e) {
|
|
2790
|
-
const
|
|
2791
|
-
if (
|
|
2792
|
-
const
|
|
2793
|
-
|
|
3047
|
+
const f = v(n, r);
|
|
3048
|
+
if (f < n.length) {
|
|
3049
|
+
const l = n.codePointAt(f);
|
|
3050
|
+
a = r + P(l ?? 0);
|
|
2794
3051
|
}
|
|
2795
3052
|
}
|
|
2796
|
-
const
|
|
2797
|
-
return { lineNumber: s, column:
|
|
3053
|
+
const c = v(n, a) + 1, h = i.getLineMaxColumn(s);
|
|
3054
|
+
return { lineNumber: s, column: M(c, 1, h) };
|
|
2798
3055
|
}
|
|
2799
|
-
function
|
|
2800
|
-
const t = typeof
|
|
3056
|
+
function I(o) {
|
|
3057
|
+
const t = typeof o == "string" ? o : "";
|
|
2801
3058
|
return t.includes("v") || t.includes("V") || t.includes("") || t.includes("s") || t.includes("S") || t.includes("");
|
|
2802
3059
|
}
|
|
2803
|
-
function
|
|
2804
|
-
if (!
|
|
3060
|
+
function fe(o) {
|
|
3061
|
+
if (!o || !Array.isArray(o) || o.length === 0) return;
|
|
2805
3062
|
const t = new TextEncoder(), e = [];
|
|
2806
|
-
for (const i of
|
|
3063
|
+
for (const i of o) {
|
|
2807
3064
|
if (!i) continue;
|
|
2808
3065
|
const s = String(i.path ?? "");
|
|
2809
3066
|
if (!s) continue;
|
|
@@ -2812,68 +3069,72 @@ function ce(r) {
|
|
|
2812
3069
|
}
|
|
2813
3070
|
return e.length ? e : void 0;
|
|
2814
3071
|
}
|
|
2815
|
-
function
|
|
2816
|
-
const e = Array.isArray(t) ? t.filter(Boolean) : [], i = Array.isArray(
|
|
3072
|
+
function me(o, t) {
|
|
3073
|
+
const e = Array.isArray(t) ? t.filter(Boolean) : [], i = Array.isArray(o) ? o.filter(Boolean) : [], s = [...e, ...i];
|
|
2817
3074
|
return s.length ? s : void 0;
|
|
2818
3075
|
}
|
|
2819
|
-
function
|
|
2820
|
-
const e =
|
|
2821
|
-
if (e.length !== 6) return
|
|
2822
|
-
const i = Math.round(
|
|
3076
|
+
function H(o, t) {
|
|
3077
|
+
const e = o.replace("#", "");
|
|
3078
|
+
if (e.length !== 6) return o;
|
|
3079
|
+
const i = Math.round(M(t, 0, 1) * 255);
|
|
2823
3080
|
return `#${e}${i.toString(16).padStart(2, "0")}`;
|
|
2824
3081
|
}
|
|
2825
|
-
function
|
|
2826
|
-
if (!
|
|
2827
|
-
const t =
|
|
2828
|
-
return typeof e == "number" && e >= 0 ?
|
|
3082
|
+
function K(o) {
|
|
3083
|
+
if (!o || typeof o != "object") return null;
|
|
3084
|
+
const t = o, e = t.background ?? t.bg;
|
|
3085
|
+
return typeof e == "number" && e >= 0 ? pe(e) : typeof t.background == "string" && t.background.startsWith("#") ? t.background : typeof t.bg == "string" && t.bg.startsWith("#") ? t.bg : null;
|
|
2829
3086
|
}
|
|
2830
|
-
function
|
|
2831
|
-
return `#${Number(
|
|
3087
|
+
function pe(o) {
|
|
3088
|
+
return `#${Number(o >>> 0).toString(16).padStart(6, "0").slice(-6)}`;
|
|
2832
3089
|
}
|
|
2833
|
-
function
|
|
2834
|
-
return
|
|
3090
|
+
function _(o, t, e, i) {
|
|
3091
|
+
return o.addEventListener(t, e, i), { dispose: () => o.removeEventListener(t, e, i) };
|
|
2835
3092
|
}
|
|
2836
|
-
function
|
|
2837
|
-
const t = typeof
|
|
3093
|
+
function $(o) {
|
|
3094
|
+
const t = typeof o == "string" ? o : "";
|
|
2838
3095
|
return t.startsWith("i") || t.startsWith("R");
|
|
2839
3096
|
}
|
|
2840
|
-
function
|
|
2841
|
-
const t = typeof
|
|
3097
|
+
function ge(o) {
|
|
3098
|
+
const t = typeof o == "string" ? o : "";
|
|
2842
3099
|
return t.length ? t[t.length - 1] : "";
|
|
2843
3100
|
}
|
|
2844
|
-
function
|
|
2845
|
-
const
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
3101
|
+
function x(o) {
|
|
3102
|
+
const t = typeof o == "string" ? o : "";
|
|
3103
|
+
return t === "c" || t.startsWith("c");
|
|
3104
|
+
}
|
|
3105
|
+
function ye(o, t, e, i, s, n) {
|
|
3106
|
+
const r = o[t] ?? "", a = o[i] ?? "", c = r.slice(0, Math.max(0, e)), h = a.slice(Math.max(0, s)), l = String(n ?? "").split(/\r?\n/);
|
|
3107
|
+
let u;
|
|
3108
|
+
if (l.length <= 1)
|
|
3109
|
+
u = [`${c}${l[0] ?? ""}${h}`];
|
|
2849
3110
|
else {
|
|
2850
|
-
const d = `${
|
|
2851
|
-
|
|
3111
|
+
const d = `${c}${l[0] ?? ""}`, m = `${l[l.length - 1] ?? ""}${h}`, p = l.slice(1, -1);
|
|
3112
|
+
u = [d, ...p, m];
|
|
2852
3113
|
}
|
|
2853
|
-
|
|
3114
|
+
o.splice(t, Math.max(0, i - t + 1), ...u);
|
|
2854
3115
|
}
|
|
2855
|
-
function
|
|
2856
|
-
if (!
|
|
2857
|
-
if (typeof
|
|
2858
|
-
if (!Array.isArray(
|
|
3116
|
+
function N(o) {
|
|
3117
|
+
if (!o) return "";
|
|
3118
|
+
if (typeof o == "string") return o;
|
|
3119
|
+
if (!Array.isArray(o)) return "";
|
|
2859
3120
|
let t = "";
|
|
2860
|
-
for (const e of
|
|
3121
|
+
for (const e of o) {
|
|
2861
3122
|
if (typeof e == "string") {
|
|
2862
3123
|
t += e;
|
|
2863
3124
|
continue;
|
|
2864
3125
|
}
|
|
2865
3126
|
if (Array.isArray(e)) {
|
|
2866
|
-
typeof e[1] == "string" ? t += e[1] : typeof e[0] == "string" ? t += e[0] : t +=
|
|
3127
|
+
typeof e[1] == "string" ? t += e[1] : typeof e[0] == "string" ? t += e[0] : t += N(e);
|
|
2867
3128
|
continue;
|
|
2868
3129
|
}
|
|
2869
3130
|
e && typeof e == "object" && typeof e.text == "string" && (t += e.text);
|
|
2870
3131
|
}
|
|
2871
3132
|
return t;
|
|
2872
3133
|
}
|
|
2873
|
-
function
|
|
2874
|
-
if (!Array.isArray(
|
|
3134
|
+
function be(o) {
|
|
3135
|
+
if (!Array.isArray(o)) return [];
|
|
2875
3136
|
const t = [];
|
|
2876
|
-
for (const e of
|
|
3137
|
+
for (const e of o) {
|
|
2877
3138
|
if (Array.isArray(e)) {
|
|
2878
3139
|
t.push({
|
|
2879
3140
|
word: String(e[0] ?? ""),
|
|
@@ -2890,12 +3151,12 @@ function me(r) {
|
|
|
2890
3151
|
}
|
|
2891
3152
|
return t.filter((e) => e.word.length > 0);
|
|
2892
3153
|
}
|
|
2893
|
-
const
|
|
3154
|
+
const Ce = new URL("./nvimWorker.js", import.meta.url), ve = new URL("./nvimWorkerAsyncify.js", import.meta.url);
|
|
2894
3155
|
export {
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
3156
|
+
le as MonacoNeovimClient,
|
|
3157
|
+
te as NeovimWasmSession,
|
|
3158
|
+
_e as createMonacoNeovim,
|
|
3159
|
+
Ce as defaultWorkerUrl,
|
|
3160
|
+
ve as defaultWorkerUrlAsyncify,
|
|
3161
|
+
X as isSharedArrayBufferAvailable
|
|
2901
3162
|
};
|