stream-monaco 0.0.15 → 0.0.17
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/README.md +42 -0
- package/README.zh-CN.md +33 -1
- package/dist/index.base-BaAqAXUs.d.ts +288 -0
- package/dist/index.base-D0jPJkA_.d.cts +289 -0
- package/dist/index.cjs +24 -2830
- package/dist/index.d.cts +4 -287
- package/dist/index.d.ts +4 -286
- package/dist/index.js +17 -2796
- package/dist/index.legacy.cjs +132 -0
- package/dist/index.legacy.d.cts +11 -0
- package/dist/index.legacy.d.ts +11 -0
- package/dist/index.legacy.js +124 -0
- package/dist/preloadMonacoWorkers.shared-C62vOlc9.js +2791 -0
- package/dist/preloadMonacoWorkers.shared-gUKedCzF.cjs +2878 -0
- package/legacy.cjs +1 -0
- package/legacy.d.cts +1 -0
- package/legacy.d.ts +1 -0
- package/legacy.js +1 -0
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -1,1999 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as _monaco from "monaco-editor";
|
|
3
|
-
import { computed } from "alien-signals";
|
|
4
|
-
import { shikiToMonaco } from "@shikijs/monaco";
|
|
5
|
-
import { createHighlighter } from "shiki";
|
|
1
|
+
import { RevealStrategy, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, editorWorkerPath, getOrCreateHighlighter, registerMonacoThemes, uniqueWorkerPaths, useMonaco, workerPathByLabel } from "./preloadMonacoWorkers.shared-C62vOlc9.js";
|
|
6
2
|
|
|
7
|
-
//#region src/
|
|
8
|
-
|
|
9
|
-
* Language detection definitions
|
|
10
|
-
*/
|
|
11
|
-
const languages = [
|
|
12
|
-
[
|
|
13
|
-
"bash",
|
|
14
|
-
[/#!(\/usr)?\/bin\/bash/g, 500],
|
|
15
|
-
[/\b(if|elif|then|fi|echo)\b|\$/g, 10]
|
|
16
|
-
],
|
|
17
|
-
[
|
|
18
|
-
"html",
|
|
19
|
-
[/<\/?[a-z-][^\n>]*>/g, 10],
|
|
20
|
-
[/^\s+<!DOCTYPE\s+html/g, 500]
|
|
21
|
-
],
|
|
22
|
-
["http", [/^(GET|HEAD|POST|PUT|DELETE|PATCH|HTTP)\b/g, 500]],
|
|
23
|
-
["js", [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require)\b/g, 10]],
|
|
24
|
-
["ts", [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require|implements|interface|namespace)\b/g, 10]],
|
|
25
|
-
["py", [/\b(def|print|class|and|or|lambda)\b/g, 10]],
|
|
26
|
-
["sql", [/\b(SELECT|INSERT|FROM)\b/g, 50]],
|
|
27
|
-
[
|
|
28
|
-
"pl",
|
|
29
|
-
[/#!(\/usr)?\/bin\/perl/g, 500],
|
|
30
|
-
[/\b(use|print)\b|\$/g, 10]
|
|
31
|
-
],
|
|
32
|
-
["lua", [/#!(\/usr)?\/bin\/lua/g, 500]],
|
|
33
|
-
["make", [/\b(ifneq|endif|if|elif|then|fi|echo|.PHONY|^[a-z]+ ?:$)\b|\$/gm, 10]],
|
|
34
|
-
["uri", [/https?:|mailto:|tel:|ftp:/g, 30]],
|
|
35
|
-
["css", [/^(@import|@page|@media|(\.|#)[a-z]+)/gm, 20]],
|
|
36
|
-
[
|
|
37
|
-
"diff",
|
|
38
|
-
[/^[+><-]/gm, 10],
|
|
39
|
-
[/^@@[-+,0-9 ]+@@/gm, 25]
|
|
40
|
-
],
|
|
41
|
-
[
|
|
42
|
-
"md",
|
|
43
|
-
[/^(>|\t\*|\t\d+.|#{1,6} |-\s+|\*\s+)/gm, 25],
|
|
44
|
-
[/\[.*\](.*)/g, 10]
|
|
45
|
-
],
|
|
46
|
-
["docker", [/^(FROM|ENTRYPOINT|RUN)/gm, 500]],
|
|
47
|
-
[
|
|
48
|
-
"xml",
|
|
49
|
-
[/<\/?[a-z-][^\n>]*>/g, 10],
|
|
50
|
-
[/^<\?xml/g, 500]
|
|
51
|
-
],
|
|
52
|
-
["c", [/#include\b|\bprintf\s+\(/g, 100]],
|
|
53
|
-
["rs", [/^\s+(use|fn|mut|match)\b/gm, 100]],
|
|
54
|
-
["go", [/\b(func|fmt|package)\b/g, 100]],
|
|
55
|
-
["java", [/^import\s+java/gm, 500]],
|
|
56
|
-
["asm", [/^(section|global main|extern|\t(call|mov|ret))/gm, 100]],
|
|
57
|
-
["css", [/^(@import|@page|@media|(\.|#)[a-z]+)/gm, 20]],
|
|
58
|
-
["json", [/\b(true|false|null|\{\})\b|"[^"]+":/g, 10]],
|
|
59
|
-
["yaml", [/^(\s+)?[a-z][a-z0-9]*:/gim, 10]],
|
|
60
|
-
[
|
|
61
|
-
"toml",
|
|
62
|
-
[/^\s*\[.*\]\s*$/gm, 100],
|
|
63
|
-
[/^\s*[\w-]+ *= */gm, 20]
|
|
64
|
-
],
|
|
65
|
-
[
|
|
66
|
-
"mermaid",
|
|
67
|
-
[/^(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|mindmap)/gm, 500],
|
|
68
|
-
[/\b(-->|--o|--x|=>|\[\]|[{}])\b/g, 10]
|
|
69
|
-
]
|
|
70
|
-
];
|
|
71
|
-
/**
|
|
72
|
-
* Try to find the language the given code belongs to
|
|
73
|
-
*
|
|
74
|
-
* @param {string} code The code to analyze
|
|
75
|
-
* @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
|
|
76
|
-
* @returns {CodeLanguage} The detected language of the code
|
|
77
|
-
*/
|
|
78
|
-
function detectLanguage(code, additionalLanguages) {
|
|
79
|
-
var _allLanguages$map$fil;
|
|
80
|
-
const allLanguages = additionalLanguages ? [...languages, ...additionalLanguages] : languages;
|
|
81
|
-
return ((_allLanguages$map$fil = allLanguages.map(([lang, ...features]) => [lang, features.reduce((acc, [match, score]) => acc + [...code.matchAll(match)].length * score, 0)]).filter(([, score]) => score > 20).sort((a, b) => b[1] - a[1])[0]) === null || _allLanguages$map$fil === void 0 ? void 0 : _allLanguages$map$fil[0]) || "plain";
|
|
82
|
-
}
|
|
83
|
-
function processedLanguage(language) {
|
|
84
|
-
if (/^(?:shellscript|bash|sh|shell|zsh)/i.test(language)) return "shell";
|
|
85
|
-
if (/^(?:powershell|ps1?)/i.test(language)) return "powershell";
|
|
86
|
-
return language.split(":")[0];
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 使用示例:
|
|
90
|
-
*
|
|
91
|
-
* // 基本用法
|
|
92
|
-
* const language1 = detectLanguage('console.log("hello")') // 'js'
|
|
93
|
-
*
|
|
94
|
-
* // 使用自定义语言检测规则
|
|
95
|
-
* const customLanguages: LanguageDefinition[] = [
|
|
96
|
-
* ['vue', [/<template>/g, 100], [/<script>/g, 50], [/<style>/g, 50]],
|
|
97
|
-
* ['kotlin', [/\b(fun|class|val|var)\b/g, 20]]
|
|
98
|
-
* ]
|
|
99
|
-
*
|
|
100
|
-
* const language2 = detectLanguage(`
|
|
101
|
-
* <template>
|
|
102
|
-
* <div>Hello Vue</div>
|
|
103
|
-
* </template>
|
|
104
|
-
* `, customLanguages) // 'vue'
|
|
105
|
-
*
|
|
106
|
-
* const language3 = detectLanguage(`
|
|
107
|
-
* fun main() {
|
|
108
|
-
* val name = "Kotlin"
|
|
109
|
-
* println("Hello $name")
|
|
110
|
-
* }
|
|
111
|
-
* `, customLanguages) // 'kotlin'
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/constant.ts
|
|
116
|
-
const defaultLanguages = [
|
|
117
|
-
"jsx",
|
|
118
|
-
"tsx",
|
|
119
|
-
"vue",
|
|
120
|
-
"csharp",
|
|
121
|
-
"python",
|
|
122
|
-
"java",
|
|
123
|
-
"c",
|
|
124
|
-
"cpp",
|
|
125
|
-
"rust",
|
|
126
|
-
"go",
|
|
127
|
-
"powershell",
|
|
128
|
-
"sql",
|
|
129
|
-
"json",
|
|
130
|
-
"html",
|
|
131
|
-
"javascript",
|
|
132
|
-
"typescript",
|
|
133
|
-
"css",
|
|
134
|
-
"markdown",
|
|
135
|
-
"xml",
|
|
136
|
-
"yaml",
|
|
137
|
-
"toml",
|
|
138
|
-
"dockerfile",
|
|
139
|
-
"kotlin",
|
|
140
|
-
"objective-c",
|
|
141
|
-
"objective-cpp",
|
|
142
|
-
"php",
|
|
143
|
-
"ruby",
|
|
144
|
-
"scala",
|
|
145
|
-
"svelte",
|
|
146
|
-
"swift",
|
|
147
|
-
"erlang",
|
|
148
|
-
"angular-html",
|
|
149
|
-
"angular-ts",
|
|
150
|
-
"dart",
|
|
151
|
-
"lua",
|
|
152
|
-
"mermaid",
|
|
153
|
-
"cmake",
|
|
154
|
-
"nginx"
|
|
155
|
-
];
|
|
156
|
-
const defaultThemes = ["vitesse-dark", "vitesse-light"];
|
|
157
|
-
const defaultScrollbar = {
|
|
158
|
-
verticalScrollbarSize: 8,
|
|
159
|
-
horizontalScrollbarSize: 8,
|
|
160
|
-
handleMouseWheel: true,
|
|
161
|
-
alwaysConsumeMouseWheel: false
|
|
162
|
-
};
|
|
163
|
-
const padding = 16;
|
|
164
|
-
const defaultRevealDebounceMs = 75;
|
|
165
|
-
const defaultRevealBatchOnIdleMs = 200;
|
|
166
|
-
const minimalEditMaxChars = 2e5;
|
|
167
|
-
const minimalEditMaxChangeRatio = .5;
|
|
168
|
-
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/minimalEdit.ts
|
|
171
|
-
/**
|
|
172
|
-
* Compute the minimal middle replacement between two UTF-16 strings.
|
|
173
|
-
* Returns null when prev === next (no edits required).
|
|
174
|
-
*/
|
|
175
|
-
function computeMinimalEdit(prev, next) {
|
|
176
|
-
if (prev === next) return null;
|
|
177
|
-
let start = 0;
|
|
178
|
-
const minLen = Math.min(prev.length, next.length);
|
|
179
|
-
while (start < minLen && prev.charCodeAt(start) === next.charCodeAt(start)) start++;
|
|
180
|
-
let endPrev = prev.length - 1;
|
|
181
|
-
let endNext = next.length - 1;
|
|
182
|
-
while (endPrev >= start && endNext >= start && prev.charCodeAt(endPrev) === next.charCodeAt(endNext)) {
|
|
183
|
-
endPrev--;
|
|
184
|
-
endNext--;
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
start,
|
|
188
|
-
endPrevIncl: endPrev,
|
|
189
|
-
endNextIncl: endNext,
|
|
190
|
-
replaceText: next.slice(start, endNext + 1)
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/monaco-shim.ts
|
|
196
|
-
var monaco_shim_exports = {};
|
|
197
|
-
__export(monaco_shim_exports, { default: () => monaco });
|
|
198
|
-
import * as import_monaco_editor from "monaco-editor";
|
|
199
|
-
__reExport(monaco_shim_exports, import_monaco_editor);
|
|
200
|
-
const monaco = _monaco;
|
|
201
|
-
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/utils/logger.ts
|
|
204
|
-
let seq = 0;
|
|
205
|
-
const DEBUG = (() => {
|
|
206
|
-
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) return Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
207
|
-
return false;
|
|
208
|
-
})();
|
|
209
|
-
function log(tag, ...args) {
|
|
210
|
-
if (!DEBUG) return;
|
|
211
|
-
seq += 1;
|
|
212
|
-
const id = `#${seq}`;
|
|
213
|
-
const ts = typeof performance !== "undefined" && performance.now ? performance.now().toFixed(1) : Date.now();
|
|
214
|
-
console.warn(`${id} [${tag}] @${ts}ms`, ...args);
|
|
215
|
-
}
|
|
216
|
-
function error(tag, ...args) {
|
|
217
|
-
if (!DEBUG) return;
|
|
218
|
-
console.error(`[${tag}]`, ...args);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/utils/height.ts
|
|
223
|
-
function createHeightManager(container, computeNext) {
|
|
224
|
-
let raf = null;
|
|
225
|
-
let debounceTimer = null;
|
|
226
|
-
let lastApplied = -1;
|
|
227
|
-
let suppressed = false;
|
|
228
|
-
const HYSTERESIS_PX = 12;
|
|
229
|
-
const DEBOUNCE_MS = 0;
|
|
230
|
-
function apply() {
|
|
231
|
-
const next = computeNext();
|
|
232
|
-
if (next == null) return;
|
|
233
|
-
log("heightManager", "computeNext ->", {
|
|
234
|
-
next,
|
|
235
|
-
lastApplied
|
|
236
|
-
});
|
|
237
|
-
if (!Number.isFinite(next) || next <= 0) {
|
|
238
|
-
log("heightManager", "invalid next height, ignoring", next);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (lastApplied !== -1 && Math.abs(next - lastApplied) <= HYSTERESIS_PX) return;
|
|
242
|
-
if (next === lastApplied) return;
|
|
243
|
-
suppressed = true;
|
|
244
|
-
container.style.height = `${next}px`;
|
|
245
|
-
lastApplied = next;
|
|
246
|
-
log("heightManager", "applied height ->", next);
|
|
247
|
-
queueMicrotask(() => {
|
|
248
|
-
suppressed = false;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function scheduleApply() {
|
|
252
|
-
if (debounceTimer != null) {
|
|
253
|
-
clearTimeout(debounceTimer);
|
|
254
|
-
debounceTimer = null;
|
|
255
|
-
}
|
|
256
|
-
if (DEBOUNCE_MS === 0) {
|
|
257
|
-
if (raf != null) return;
|
|
258
|
-
raf = requestAnimationFrame(() => {
|
|
259
|
-
raf = null;
|
|
260
|
-
apply();
|
|
261
|
-
});
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
debounceTimer = setTimeout(() => {
|
|
265
|
-
debounceTimer = null;
|
|
266
|
-
if (raf != null) return;
|
|
267
|
-
raf = requestAnimationFrame(() => {
|
|
268
|
-
raf = null;
|
|
269
|
-
apply();
|
|
270
|
-
});
|
|
271
|
-
}, DEBOUNCE_MS);
|
|
272
|
-
}
|
|
273
|
-
function update() {
|
|
274
|
-
scheduleApply();
|
|
275
|
-
}
|
|
276
|
-
function dispose() {
|
|
277
|
-
if (raf != null) {
|
|
278
|
-
cancelAnimationFrame(raf);
|
|
279
|
-
raf = null;
|
|
280
|
-
}
|
|
281
|
-
if (debounceTimer != null) {
|
|
282
|
-
clearTimeout(debounceTimer);
|
|
283
|
-
debounceTimer = null;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
function isSuppressed() {
|
|
287
|
-
return suppressed;
|
|
288
|
-
}
|
|
289
|
-
function getLastApplied() {
|
|
290
|
-
return lastApplied;
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
update,
|
|
294
|
-
dispose,
|
|
295
|
-
isSuppressed,
|
|
296
|
-
getLastApplied
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
//#endregion
|
|
301
|
-
//#region src/utils/raf.ts
|
|
302
|
-
/**
|
|
303
|
-
* Create a per-instance RAF scheduler that coalesces tasks by "kind" within
|
|
304
|
-
* the same instance. Instances are isolated so different editors won't
|
|
305
|
-
* cancel each other's scheduled work.
|
|
306
|
-
*/
|
|
307
|
-
function createRafScheduler(timeSource) {
|
|
308
|
-
const ids = {};
|
|
309
|
-
const ts = timeSource ?? {
|
|
310
|
-
requestAnimationFrame: (cb) => requestAnimationFrame(cb),
|
|
311
|
-
cancelAnimationFrame: (id) => cancelAnimationFrame(id)
|
|
312
|
-
};
|
|
313
|
-
function schedule(kind, cb) {
|
|
314
|
-
const existing = ids[kind];
|
|
315
|
-
if (existing != null) ts.cancelAnimationFrame(existing);
|
|
316
|
-
ids[kind] = ts.requestAnimationFrame((t) => {
|
|
317
|
-
ids[kind] = null;
|
|
318
|
-
cb(t);
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
function cancel(kind) {
|
|
322
|
-
const id = ids[kind];
|
|
323
|
-
if (id != null) {
|
|
324
|
-
ts.cancelAnimationFrame(id);
|
|
325
|
-
ids[kind] = null;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
schedule,
|
|
330
|
-
cancel
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
//#endregion
|
|
335
|
-
//#region src/utils/scroll.ts
|
|
336
|
-
function createScrollWatcherForEditor(ed, opts) {
|
|
337
|
-
var _ed$getScrollTop, _ed$onDidScrollChange;
|
|
338
|
-
const initial = ((_ed$getScrollTop = ed.getScrollTop) === null || _ed$getScrollTop === void 0 ? void 0 : _ed$getScrollTop.call(ed)) ?? 0;
|
|
339
|
-
opts.setLast(initial);
|
|
340
|
-
log("scrollWatcher", "initial scrollTop=", initial);
|
|
341
|
-
let suppressedExternally = false;
|
|
342
|
-
const THRESHOLD_PX = 6;
|
|
343
|
-
let domNode = null;
|
|
344
|
-
let interactionListener = null;
|
|
345
|
-
const listener = (e) => {
|
|
346
|
-
var _ed$getScrollTop2;
|
|
347
|
-
if (suppressedExternally) {
|
|
348
|
-
log("scrollWatcher", "suppressedExternally, ignoring event");
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
const currentTop = e && typeof e.scrollTop === "number" ? e.scrollTop : ((_ed$getScrollTop2 = ed.getScrollTop) === null || _ed$getScrollTop2 === void 0 ? void 0 : _ed$getScrollTop2.call(ed)) ?? 0;
|
|
352
|
-
const delta = currentTop - opts.getLast();
|
|
353
|
-
opts.setLast(currentTop);
|
|
354
|
-
if (Math.abs(delta) < THRESHOLD_PX) {
|
|
355
|
-
log("scrollWatcher", "small delta ignored", delta);
|
|
356
|
-
try {
|
|
357
|
-
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
358
|
-
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
359
|
-
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
360
|
-
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
361
|
-
const distance = scrollHeight - (currentTop + viewportH);
|
|
362
|
-
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
363
|
-
log("scrollWatcher", "small delta but at bottom, maybe resume", { distance });
|
|
364
|
-
opts.onMaybeResume();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
} catch {}
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
log("scrollWatcher", "delta=", delta, "currentTop=", currentTop);
|
|
371
|
-
if (delta < 0) {
|
|
372
|
-
log("scrollWatcher", "pause detected delta=", delta);
|
|
373
|
-
opts.onPause();
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
log("scrollWatcher", "maybe resume delta=", delta);
|
|
377
|
-
opts.onMaybeResume();
|
|
378
|
-
};
|
|
379
|
-
const disp = ((_ed$onDidScrollChange = ed.onDidScrollChange) === null || _ed$onDidScrollChange === void 0 ? void 0 : _ed$onDidScrollChange.call(ed, listener)) ?? null;
|
|
380
|
-
const api = {
|
|
381
|
-
dispose() {
|
|
382
|
-
try {
|
|
383
|
-
if (disp && typeof disp.dispose === "function") disp.dispose();
|
|
384
|
-
else if (typeof disp === "function") disp();
|
|
385
|
-
} catch {}
|
|
386
|
-
log("scrollWatcher", "dispose");
|
|
387
|
-
},
|
|
388
|
-
setSuppressed(v) {
|
|
389
|
-
const newVal = !!v;
|
|
390
|
-
if (newVal === suppressedExternally) return;
|
|
391
|
-
suppressedExternally = newVal;
|
|
392
|
-
log("scrollWatcher", "setSuppressed =>", suppressedExternally);
|
|
393
|
-
try {
|
|
394
|
-
if (!domNode && typeof ed.getDomNode === "function") domNode = ed.getDomNode();
|
|
395
|
-
if (suppressedExternally && domNode) {
|
|
396
|
-
if (!interactionListener) {
|
|
397
|
-
interactionListener = () => {
|
|
398
|
-
try {
|
|
399
|
-
var _ed$getScrollTop3;
|
|
400
|
-
log("scrollWatcher", "user interaction detected while suppressed, cancelling suppression");
|
|
401
|
-
opts.onPause();
|
|
402
|
-
suppressedExternally = false;
|
|
403
|
-
const cur = ((_ed$getScrollTop3 = ed.getScrollTop) === null || _ed$getScrollTop3 === void 0 ? void 0 : _ed$getScrollTop3.call(ed)) ?? 0;
|
|
404
|
-
opts.setLast(cur);
|
|
405
|
-
try {
|
|
406
|
-
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
407
|
-
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
408
|
-
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
409
|
-
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
410
|
-
const distance = scrollHeight - (cur + viewportH);
|
|
411
|
-
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
412
|
-
log("scrollWatcher", "interaction moved to bottom, maybe resume", { distance });
|
|
413
|
-
opts.onMaybeResume();
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
} catch {}
|
|
417
|
-
if (domNode && interactionListener) {
|
|
418
|
-
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
419
|
-
domNode.removeEventListener("pointerdown", interactionListener);
|
|
420
|
-
domNode.removeEventListener("touchstart", interactionListener);
|
|
421
|
-
}
|
|
422
|
-
interactionListener = null;
|
|
423
|
-
} catch {}
|
|
424
|
-
};
|
|
425
|
-
domNode.addEventListener("wheel", interactionListener, { passive: true });
|
|
426
|
-
domNode.addEventListener("pointerdown", interactionListener);
|
|
427
|
-
domNode.addEventListener("touchstart", interactionListener);
|
|
428
|
-
}
|
|
429
|
-
} else if (domNode && interactionListener) {
|
|
430
|
-
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
431
|
-
domNode.removeEventListener("pointerdown", interactionListener);
|
|
432
|
-
domNode.removeEventListener("touchstart", interactionListener);
|
|
433
|
-
interactionListener = null;
|
|
434
|
-
}
|
|
435
|
-
} catch {}
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
return api;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
//#endregion
|
|
442
|
-
//#region src/core/DiffEditorManager.ts
|
|
443
|
-
var DiffEditorManager = class {
|
|
444
|
-
diffEditorView = null;
|
|
445
|
-
originalModel = null;
|
|
446
|
-
modifiedModel = null;
|
|
447
|
-
lastContainer = null;
|
|
448
|
-
lastKnownOriginalCode = null;
|
|
449
|
-
lastKnownModifiedCode = null;
|
|
450
|
-
lastKnownModifiedLineCount = null;
|
|
451
|
-
pendingDiffUpdate = null;
|
|
452
|
-
shouldAutoScrollDiff = true;
|
|
453
|
-
diffScrollWatcher = null;
|
|
454
|
-
lastScrollTopDiff = 0;
|
|
455
|
-
_hasScrollBar = false;
|
|
456
|
-
cachedScrollHeightDiff = null;
|
|
457
|
-
cachedLineHeightDiff = null;
|
|
458
|
-
cachedComputedHeightDiff = null;
|
|
459
|
-
lastKnownModifiedDirty = false;
|
|
460
|
-
measureViewportDiff() {
|
|
461
|
-
var _me$getLayoutInfo, _me$getScrollTop, _me$getScrollHeight;
|
|
462
|
-
if (!this.diffEditorView) return null;
|
|
463
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
464
|
-
const li = ((_me$getLayoutInfo = me.getLayoutInfo) === null || _me$getLayoutInfo === void 0 ? void 0 : _me$getLayoutInfo.call(me)) ?? null;
|
|
465
|
-
const lineHeight = this.cachedLineHeightDiff ?? me.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
466
|
-
const scrollTop = ((_me$getScrollTop = me.getScrollTop) === null || _me$getScrollTop === void 0 ? void 0 : _me$getScrollTop.call(me)) ?? this.lastScrollTopDiff ?? 0;
|
|
467
|
-
const scrollHeight = ((_me$getScrollHeight = me.getScrollHeight) === null || _me$getScrollHeight === void 0 ? void 0 : _me$getScrollHeight.call(me)) ?? this.cachedScrollHeightDiff ?? (li === null || li === void 0 ? void 0 : li.height) ?? 0;
|
|
468
|
-
const computedHeight = this.cachedComputedHeightDiff ?? this.computedHeight();
|
|
469
|
-
this.cachedLineHeightDiff = lineHeight;
|
|
470
|
-
this.cachedScrollHeightDiff = scrollHeight;
|
|
471
|
-
this.cachedComputedHeightDiff = computedHeight;
|
|
472
|
-
this.lastScrollTopDiff = scrollTop;
|
|
473
|
-
return {
|
|
474
|
-
me,
|
|
475
|
-
li,
|
|
476
|
-
lineHeight,
|
|
477
|
-
scrollTop,
|
|
478
|
-
scrollHeight,
|
|
479
|
-
computedHeight
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
lastRevealLineDiff = null;
|
|
483
|
-
revealTicketDiff = 0;
|
|
484
|
-
revealDebounceIdDiff = null;
|
|
485
|
-
revealDebounceMs = defaultRevealDebounceMs;
|
|
486
|
-
revealIdleTimerIdDiff = null;
|
|
487
|
-
revealStrategyOption;
|
|
488
|
-
revealBatchOnIdleMsOption;
|
|
489
|
-
scrollWatcherSuppressionMs = 500;
|
|
490
|
-
diffScrollWatcherSuppressionTimer = null;
|
|
491
|
-
appendBufferOriginalDiff = [];
|
|
492
|
-
appendBufferModifiedDiff = [];
|
|
493
|
-
appendBufferDiffScheduled = false;
|
|
494
|
-
diffUpdateThrottleMs = 50;
|
|
495
|
-
lastAppendFlushTimeDiff = 0;
|
|
496
|
-
appendFlushThrottleTimerDiff = null;
|
|
497
|
-
rafScheduler = createRafScheduler();
|
|
498
|
-
diffHeightManager = null;
|
|
499
|
-
constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption, diffUpdateThrottleMsOption) {
|
|
500
|
-
this.options = options;
|
|
501
|
-
this.maxHeightValue = maxHeightValue;
|
|
502
|
-
this.maxHeightCSS = maxHeightCSS;
|
|
503
|
-
this.autoScrollOnUpdate = autoScrollOnUpdate;
|
|
504
|
-
this.autoScrollInitial = autoScrollInitial;
|
|
505
|
-
this.autoScrollThresholdPx = autoScrollThresholdPx;
|
|
506
|
-
this.autoScrollThresholdLines = autoScrollThresholdLines;
|
|
507
|
-
this.diffAutoScroll = diffAutoScroll;
|
|
508
|
-
this.revealDebounceMsOption = revealDebounceMsOption;
|
|
509
|
-
}
|
|
510
|
-
scheduleFlushAppendBufferDiff() {
|
|
511
|
-
if (this.appendBufferDiffScheduled) return;
|
|
512
|
-
this.appendBufferDiffScheduled = true;
|
|
513
|
-
const schedule = () => {
|
|
514
|
-
this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
|
|
515
|
-
};
|
|
516
|
-
const throttle = this.diffUpdateThrottleMs;
|
|
517
|
-
if (!throttle) {
|
|
518
|
-
schedule();
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const now = Date.now();
|
|
522
|
-
const since = now - this.lastAppendFlushTimeDiff;
|
|
523
|
-
if (since >= throttle) {
|
|
524
|
-
schedule();
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
if (this.appendFlushThrottleTimerDiff != null) return;
|
|
528
|
-
const wait = throttle - since;
|
|
529
|
-
this.appendFlushThrottleTimerDiff = setTimeout(() => {
|
|
530
|
-
this.appendFlushThrottleTimerDiff = null;
|
|
531
|
-
schedule();
|
|
532
|
-
}, wait);
|
|
533
|
-
}
|
|
534
|
-
flushOriginalAppendBufferSync() {
|
|
535
|
-
if (!this.originalModel) return;
|
|
536
|
-
if (this.appendBufferOriginalDiff.length === 0) return;
|
|
537
|
-
this.rafScheduler.cancel("appendDiff");
|
|
538
|
-
this.appendBufferDiffScheduled = false;
|
|
539
|
-
const text = this.appendBufferOriginalDiff.join("");
|
|
540
|
-
this.appendBufferOriginalDiff.length = 0;
|
|
541
|
-
if (!text) return;
|
|
542
|
-
this.appendToModel(this.originalModel, text);
|
|
543
|
-
}
|
|
544
|
-
computedHeight() {
|
|
545
|
-
var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
|
|
546
|
-
if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
|
|
547
|
-
const modifiedEditor = this.diffEditorView.getModifiedEditor();
|
|
548
|
-
const originalEditor = this.diffEditorView.getOriginalEditor();
|
|
549
|
-
const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
550
|
-
const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
|
|
551
|
-
const mCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
|
|
552
|
-
const lineCount = Math.max(oCount, mCount);
|
|
553
|
-
const fromLines = lineCount * lineHeight + padding;
|
|
554
|
-
const scrollH = Math.max(((_originalEditor$getSc = originalEditor.getScrollHeight) === null || _originalEditor$getSc === void 0 ? void 0 : _originalEditor$getSc.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc === void 0 ? void 0 : _modifiedEditor$getSc.call(modifiedEditor)) ?? 0);
|
|
555
|
-
const desired = Math.max(fromLines, scrollH);
|
|
556
|
-
return Math.min(desired, this.maxHeightValue);
|
|
557
|
-
}
|
|
558
|
-
isOverflowAutoDiff() {
|
|
559
|
-
return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
|
|
560
|
-
}
|
|
561
|
-
shouldPerformImmediateRevealDiff() {
|
|
562
|
-
return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
|
|
563
|
-
}
|
|
564
|
-
suppressScrollWatcherDiff(ms) {
|
|
565
|
-
if (!this.diffScrollWatcher || typeof this.diffScrollWatcher.setSuppressed !== "function") return;
|
|
566
|
-
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
567
|
-
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
568
|
-
this.diffScrollWatcherSuppressionTimer = null;
|
|
569
|
-
}
|
|
570
|
-
this.diffScrollWatcher.setSuppressed(true);
|
|
571
|
-
this.diffScrollWatcherSuppressionTimer = setTimeout(() => {
|
|
572
|
-
try {
|
|
573
|
-
this.diffScrollWatcher.setSuppressed(false);
|
|
574
|
-
} catch {}
|
|
575
|
-
this.diffScrollWatcherSuppressionTimer = null;
|
|
576
|
-
}, ms);
|
|
577
|
-
}
|
|
578
|
-
hasVerticalScrollbarModified() {
|
|
579
|
-
if (!this.diffEditorView) return false;
|
|
580
|
-
if (this._hasScrollBar) return true;
|
|
581
|
-
const m = this.measureViewportDiff();
|
|
582
|
-
if (!m) return false;
|
|
583
|
-
const epsilon = Math.max(2, Math.round(m.lineHeight / 8));
|
|
584
|
-
return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
|
|
585
|
-
}
|
|
586
|
-
userIsNearBottomDiff() {
|
|
587
|
-
if (!this.diffEditorView) return true;
|
|
588
|
-
const m = this.measureViewportDiff();
|
|
589
|
-
if (!m || !m.li) return true;
|
|
590
|
-
const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
|
|
591
|
-
const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
|
|
592
|
-
const distance = m.scrollHeight - (m.scrollTop + m.li.height);
|
|
593
|
-
return distance <= threshold;
|
|
594
|
-
}
|
|
595
|
-
maybeScrollDiffToBottom(targetLine, prevLineOverride) {
|
|
596
|
-
this.rafScheduler.schedule("maybe-scroll-diff", () => {
|
|
597
|
-
log("diff", "maybeScrollDiffToBottom called", {
|
|
598
|
-
targetLine,
|
|
599
|
-
prevLineOverride,
|
|
600
|
-
diffAutoScroll: this.diffAutoScroll,
|
|
601
|
-
autoScrollOnUpdate: this.autoScrollOnUpdate,
|
|
602
|
-
shouldAutoScrollDiff: this.shouldAutoScrollDiff
|
|
603
|
-
});
|
|
604
|
-
if (!this.diffEditorView) return;
|
|
605
|
-
const hasV = this.hasVerticalScrollbarModified();
|
|
606
|
-
log("diff", "hasVerticalScrollbarModified ->", hasV);
|
|
607
|
-
if (!(this.diffAutoScroll && this.autoScrollOnUpdate && this.shouldAutoScrollDiff && hasV)) return;
|
|
608
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
609
|
-
const model = me.getModel();
|
|
610
|
-
const currentLine = (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
611
|
-
const line = targetLine ?? currentLine;
|
|
612
|
-
const prevLine = typeof prevLineOverride === "number" ? prevLineOverride : this.lastKnownModifiedLineCount ?? -1;
|
|
613
|
-
log("diff", "scroll metrics", {
|
|
614
|
-
prevLine,
|
|
615
|
-
currentLine,
|
|
616
|
-
line,
|
|
617
|
-
lastRevealLineDiff: this.lastRevealLineDiff
|
|
618
|
-
});
|
|
619
|
-
if (prevLine !== -1 && prevLine === currentLine && line === currentLine) return;
|
|
620
|
-
if (this.lastRevealLineDiff !== null && this.lastRevealLineDiff === line) return;
|
|
621
|
-
const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
|
|
622
|
-
log("diff", "reveal timing", {
|
|
623
|
-
batchMs,
|
|
624
|
-
revealDebounceMs: this.revealDebounceMs,
|
|
625
|
-
revealDebounceMsOption: this.revealDebounceMsOption
|
|
626
|
-
});
|
|
627
|
-
if (typeof batchMs === "number" && batchMs > 0) {
|
|
628
|
-
if (hasV) {
|
|
629
|
-
const ticket$1 = ++this.revealTicketDiff;
|
|
630
|
-
log("diff", "has scrollbar -> immediate ticketed reveal", {
|
|
631
|
-
ticket: ticket$1,
|
|
632
|
-
line
|
|
633
|
-
});
|
|
634
|
-
this.performRevealDiffTicketed(line, ticket$1);
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
if (this.revealIdleTimerIdDiff != null) clearTimeout(this.revealIdleTimerIdDiff);
|
|
638
|
-
const ticket = ++this.revealTicketDiff;
|
|
639
|
-
log("diff", "scheduling idle reveal", {
|
|
640
|
-
ticket,
|
|
641
|
-
batchMs,
|
|
642
|
-
line
|
|
643
|
-
});
|
|
644
|
-
this.revealIdleTimerIdDiff = setTimeout(() => {
|
|
645
|
-
this.revealIdleTimerIdDiff = null;
|
|
646
|
-
this.performRevealDiffTicketed(line, ticket);
|
|
647
|
-
}, batchMs);
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
if (this.revealDebounceIdDiff != null) {
|
|
651
|
-
clearTimeout(this.revealDebounceIdDiff);
|
|
652
|
-
this.revealDebounceIdDiff = null;
|
|
653
|
-
}
|
|
654
|
-
const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
|
|
655
|
-
this.revealDebounceIdDiff = setTimeout(() => {
|
|
656
|
-
this.revealDebounceIdDiff = null;
|
|
657
|
-
const ticket = ++this.revealTicketDiff;
|
|
658
|
-
log("diff", "debounced reveal firing", {
|
|
659
|
-
ticket,
|
|
660
|
-
line
|
|
661
|
-
});
|
|
662
|
-
this.performRevealDiffTicketed(line, ticket);
|
|
663
|
-
}, ms);
|
|
664
|
-
this.lastKnownModifiedLineCount = currentLine;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
performRevealDiffTicketed(line, ticket) {
|
|
668
|
-
this.rafScheduler.schedule("revealDiff", () => {
|
|
669
|
-
var _editor;
|
|
670
|
-
if (this.diffScrollWatcher) {
|
|
671
|
-
log("diff", "performRevealDiffTicketed - suppressing watcher", {
|
|
672
|
-
ticket,
|
|
673
|
-
line,
|
|
674
|
-
ms: this.scrollWatcherSuppressionMs
|
|
675
|
-
});
|
|
676
|
-
this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs);
|
|
677
|
-
}
|
|
678
|
-
if (ticket !== this.revealTicketDiff) return;
|
|
679
|
-
log("diff", "performRevealDiffTicketed - performing reveal", {
|
|
680
|
-
ticket,
|
|
681
|
-
line
|
|
682
|
-
});
|
|
683
|
-
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
684
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
685
|
-
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
686
|
-
try {
|
|
687
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
688
|
-
if (strategy === "bottom") if (typeof smooth !== "undefined") me.revealLine(line, smooth);
|
|
689
|
-
else me.revealLine(line);
|
|
690
|
-
else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
|
|
691
|
-
else me.revealLineInCenter(line);
|
|
692
|
-
else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
|
|
693
|
-
else me.revealLineInCenterIfOutsideViewport(line);
|
|
694
|
-
} catch {
|
|
695
|
-
try {
|
|
696
|
-
this.diffEditorView.getModifiedEditor().revealLine(line);
|
|
697
|
-
} catch {}
|
|
698
|
-
}
|
|
699
|
-
this.lastRevealLineDiff = line;
|
|
700
|
-
log("diff", "performRevealDiffTicketed - revealed", {
|
|
701
|
-
line,
|
|
702
|
-
lastRevealLineDiff: this.lastRevealLineDiff
|
|
703
|
-
});
|
|
704
|
-
try {
|
|
705
|
-
var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2;
|
|
706
|
-
this.shouldAutoScrollDiff = true;
|
|
707
|
-
this.lastScrollTopDiff = ((_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 || (_this$diffEditorView$2 = (_this$diffEditorView$ = _this$diffEditorView.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$)) ?? this.lastScrollTopDiff;
|
|
708
|
-
} catch {}
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
performImmediateRevealDiff(line, ticket) {
|
|
712
|
-
var _editor2;
|
|
713
|
-
if (!this.diffEditorView) return;
|
|
714
|
-
if (ticket !== this.revealTicketDiff) return;
|
|
715
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
716
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
717
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
718
|
-
if (typeof immediate !== "undefined") me.revealLine(line, immediate);
|
|
719
|
-
else me.revealLine(line);
|
|
720
|
-
this.measureViewportDiff();
|
|
721
|
-
log("diff", "performImmediateRevealDiff", {
|
|
722
|
-
line,
|
|
723
|
-
ticket
|
|
724
|
-
});
|
|
725
|
-
try {
|
|
726
|
-
var _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
|
|
727
|
-
this.shouldAutoScrollDiff = true;
|
|
728
|
-
this.lastScrollTopDiff = ((_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 || (_this$diffEditorView4 = (_this$diffEditorView3 = _this$diffEditorView2.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView4 === void 0 ? void 0 : _this$diffEditorView4.call(_this$diffEditorView3)) ?? this.lastScrollTopDiff;
|
|
729
|
-
} catch {}
|
|
730
|
-
}
|
|
731
|
-
scheduleImmediateRevealAfterLayoutDiff(line) {
|
|
732
|
-
const ticket = ++this.revealTicketDiff;
|
|
733
|
-
this.rafScheduler.schedule("immediate-reveal-diff", async () => {
|
|
734
|
-
const target = this.diffEditorView && this.diffHeightManager ? Math.min(this.computedHeight(), this.maxHeightValue) : -1;
|
|
735
|
-
if (target !== -1 && this.diffHeightManager) {
|
|
736
|
-
if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
|
|
737
|
-
await this.waitForHeightAppliedDiff(target);
|
|
738
|
-
}
|
|
739
|
-
this.performImmediateRevealDiff(line, ticket);
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
waitForHeightAppliedDiff(target, timeoutMs = 500) {
|
|
743
|
-
return new Promise((resolve) => {
|
|
744
|
-
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
745
|
-
const check = () => {
|
|
746
|
-
const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
|
|
747
|
-
if (applied >= target - 1) {
|
|
748
|
-
resolve();
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
|
|
752
|
-
resolve();
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
requestAnimationFrame(check);
|
|
756
|
-
};
|
|
757
|
-
check();
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
|
|
761
|
-
var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
|
|
762
|
-
this.cleanup();
|
|
763
|
-
this.lastContainer = container;
|
|
764
|
-
container.style.overflow = "hidden";
|
|
765
|
-
container.style.maxHeight = this.maxHeightCSS;
|
|
766
|
-
const lang = processedLanguage(language) || language;
|
|
767
|
-
this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
|
|
768
|
-
this.modifiedModel = monaco_shim_exports.editor.createModel(modifiedCode, lang);
|
|
769
|
-
this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(container, {
|
|
770
|
-
automaticLayout: true,
|
|
771
|
-
scrollBeyondLastLine: false,
|
|
772
|
-
renderSideBySide: true,
|
|
773
|
-
originalEditable: false,
|
|
774
|
-
readOnly: this.options.readOnly ?? true,
|
|
775
|
-
minimap: { enabled: false },
|
|
776
|
-
theme: currentTheme,
|
|
777
|
-
contextmenu: false,
|
|
778
|
-
scrollbar: {
|
|
779
|
-
...defaultScrollbar,
|
|
780
|
-
...this.options.scrollbar || {}
|
|
781
|
-
},
|
|
782
|
-
...this.options
|
|
783
|
-
});
|
|
784
|
-
monaco_shim_exports.editor.setTheme(currentTheme);
|
|
785
|
-
this.diffEditorView.setModel({
|
|
786
|
-
original: this.originalModel,
|
|
787
|
-
modified: this.modifiedModel
|
|
788
|
-
});
|
|
789
|
-
this.lastKnownOriginalCode = originalCode;
|
|
790
|
-
this.lastKnownModifiedCode = modifiedCode;
|
|
791
|
-
this.diffUpdateThrottleMs = this.options.diffUpdateThrottleMs ?? 50;
|
|
792
|
-
this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
|
|
793
|
-
if (this.diffScrollWatcher) {
|
|
794
|
-
this.diffScrollWatcher.dispose();
|
|
795
|
-
this.diffScrollWatcher = null;
|
|
796
|
-
}
|
|
797
|
-
if (this.diffAutoScroll) {
|
|
798
|
-
const me$1 = this.diffEditorView.getModifiedEditor();
|
|
799
|
-
this.diffScrollWatcher = createScrollWatcherForEditor(me$1, {
|
|
800
|
-
onPause: () => {
|
|
801
|
-
this.shouldAutoScrollDiff = false;
|
|
802
|
-
},
|
|
803
|
-
onMaybeResume: () => {
|
|
804
|
-
this.rafScheduler.schedule("maybe-resume-diff", () => {
|
|
805
|
-
this.shouldAutoScrollDiff = this.userIsNearBottomDiff();
|
|
806
|
-
});
|
|
807
|
-
},
|
|
808
|
-
getLast: () => this.lastScrollTopDiff,
|
|
809
|
-
setLast: (v) => {
|
|
810
|
-
this.lastScrollTopDiff = v;
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
log("diff", "createDiffEditor", {
|
|
815
|
-
autoScrollInitial: this.autoScrollInitial,
|
|
816
|
-
diffAutoScroll: this.diffAutoScroll
|
|
817
|
-
});
|
|
818
|
-
const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
|
|
819
|
-
container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
|
|
820
|
-
if (this.diffHeightManager) {
|
|
821
|
-
this.diffHeightManager.dispose();
|
|
822
|
-
this.diffHeightManager = null;
|
|
823
|
-
}
|
|
824
|
-
this.diffHeightManager = createHeightManager(container, () => this.computedHeight());
|
|
825
|
-
this.diffHeightManager.update();
|
|
826
|
-
const initialComputed = this.computedHeight();
|
|
827
|
-
if (initialComputed >= this.maxHeightValue - 1) {
|
|
828
|
-
container.style.height = `${this.maxHeightValue}px`;
|
|
829
|
-
container.style.overflow = "auto";
|
|
830
|
-
}
|
|
831
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
832
|
-
this.cachedScrollHeightDiff = ((_me$getScrollHeight2 = me.getScrollHeight) === null || _me$getScrollHeight2 === void 0 ? void 0 : _me$getScrollHeight2.call(me)) ?? null;
|
|
833
|
-
this.cachedLineHeightDiff = ((_me$getOption = me.getOption) === null || _me$getOption === void 0 ? void 0 : _me$getOption.call(me, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
|
|
834
|
-
this.cachedComputedHeightDiff = this.computedHeight();
|
|
835
|
-
const oEditor = this.diffEditorView.getOriginalEditor();
|
|
836
|
-
const mEditor = this.diffEditorView.getModifiedEditor();
|
|
837
|
-
(_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
|
|
838
|
-
this._hasScrollBar = false;
|
|
839
|
-
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
840
|
-
var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag, _this$diffHeightManag2;
|
|
841
|
-
this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
|
|
842
|
-
this.cachedLineHeightDiff = ((_oEditor$getOption = oEditor.getOption) === null || _oEditor$getOption === void 0 ? void 0 : _oEditor$getOption.call(oEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
|
|
843
|
-
this.cachedComputedHeightDiff = this.computedHeight();
|
|
844
|
-
if ((_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 ? void 0 : _this$diffHeightManag.isSuppressed()) return;
|
|
845
|
-
(_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
|
|
846
|
-
const computed$2 = this.computedHeight();
|
|
847
|
-
if (this.lastContainer) {
|
|
848
|
-
const prevOverflow = this.lastContainer.style.overflow;
|
|
849
|
-
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
850
|
-
if (prevOverflow !== newOverflow) {
|
|
851
|
-
this.lastContainer.style.overflow = newOverflow;
|
|
852
|
-
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
853
|
-
var _this$modifiedModel;
|
|
854
|
-
this.maybeScrollDiffToBottom((_this$modifiedModel = this.modifiedModel) === null || _this$modifiedModel === void 0 ? void 0 : _this$modifiedModel.getLineCount());
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
(_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
|
|
861
|
-
this._hasScrollBar = false;
|
|
862
|
-
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
863
|
-
var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
|
|
864
|
-
this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
|
|
865
|
-
this.cachedLineHeightDiff = ((_mEditor$getOption = mEditor.getOption) === null || _mEditor$getOption === void 0 ? void 0 : _mEditor$getOption.call(mEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
|
|
866
|
-
this.cachedComputedHeightDiff = this.computedHeight();
|
|
867
|
-
if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
|
|
868
|
-
(_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
|
|
869
|
-
const computed$2 = this.computedHeight();
|
|
870
|
-
if (this.lastContainer) {
|
|
871
|
-
const prevOverflow = this.lastContainer.style.overflow;
|
|
872
|
-
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
873
|
-
if (prevOverflow !== newOverflow) {
|
|
874
|
-
this.lastContainer.style.overflow = newOverflow;
|
|
875
|
-
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
876
|
-
var _this$modifiedModel2;
|
|
877
|
-
this.maybeScrollDiffToBottom((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount());
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
mEditor.onDidChangeModelContent(() => {
|
|
884
|
-
this.lastKnownModifiedDirty = true;
|
|
885
|
-
this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
|
|
886
|
-
});
|
|
887
|
-
this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), this.lastKnownModifiedLineCount ?? void 0);
|
|
888
|
-
return this.diffEditorView;
|
|
889
|
-
}
|
|
890
|
-
updateDiff(originalCode, modifiedCode, codeLanguage) {
|
|
891
|
-
if (!this.diffEditorView || !this.originalModel || !this.modifiedModel) return;
|
|
892
|
-
const plang = codeLanguage ? processedLanguage(codeLanguage) : void 0;
|
|
893
|
-
if (plang && (this.originalModel.getLanguageId() !== plang || this.modifiedModel.getLanguageId() !== plang)) {
|
|
894
|
-
this.pendingDiffUpdate = {
|
|
895
|
-
original: originalCode,
|
|
896
|
-
modified: modifiedCode,
|
|
897
|
-
lang: codeLanguage
|
|
898
|
-
};
|
|
899
|
-
this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
|
|
900
|
-
return;
|
|
901
|
-
}
|
|
902
|
-
if (this.lastKnownOriginalCode == null) this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
903
|
-
if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = this.modifiedModel.getValue();
|
|
904
|
-
const prevO = this.lastKnownOriginalCode;
|
|
905
|
-
const prevM = this.lastKnownModifiedCode;
|
|
906
|
-
let didImmediate = false;
|
|
907
|
-
if (originalCode !== prevO && originalCode.startsWith(prevO)) {
|
|
908
|
-
this.appendOriginal(originalCode.slice(prevO.length));
|
|
909
|
-
this.lastKnownOriginalCode = originalCode;
|
|
910
|
-
didImmediate = true;
|
|
911
|
-
}
|
|
912
|
-
if (modifiedCode !== prevM && modifiedCode.startsWith(prevM)) {
|
|
913
|
-
this.appendModified(modifiedCode.slice(prevM.length));
|
|
914
|
-
this.lastKnownModifiedCode = modifiedCode;
|
|
915
|
-
didImmediate = true;
|
|
916
|
-
}
|
|
917
|
-
if (originalCode !== this.lastKnownOriginalCode || modifiedCode !== this.lastKnownModifiedCode) {
|
|
918
|
-
this.pendingDiffUpdate = {
|
|
919
|
-
original: originalCode,
|
|
920
|
-
modified: modifiedCode
|
|
921
|
-
};
|
|
922
|
-
this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
|
|
923
|
-
} else if (didImmediate) {}
|
|
924
|
-
}
|
|
925
|
-
updateOriginal(newCode, codeLanguage) {
|
|
926
|
-
if (!this.diffEditorView || !this.originalModel) return;
|
|
927
|
-
if (codeLanguage) {
|
|
928
|
-
const lang = processedLanguage(codeLanguage);
|
|
929
|
-
if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
|
|
930
|
-
}
|
|
931
|
-
const prev = this.lastKnownOriginalCode ?? this.originalModel.getValue();
|
|
932
|
-
if (prev === newCode) return;
|
|
933
|
-
if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
|
|
934
|
-
else {
|
|
935
|
-
this.flushOriginalAppendBufferSync();
|
|
936
|
-
this.applyMinimalEditToModel(this.originalModel, prev, newCode);
|
|
937
|
-
}
|
|
938
|
-
this.lastKnownOriginalCode = newCode;
|
|
939
|
-
}
|
|
940
|
-
updateModified(newCode, codeLanguage) {
|
|
941
|
-
if (!this.diffEditorView || !this.modifiedModel) return;
|
|
942
|
-
if (codeLanguage) {
|
|
943
|
-
const lang = processedLanguage(codeLanguage);
|
|
944
|
-
if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
|
|
945
|
-
}
|
|
946
|
-
const prev = this.lastKnownModifiedCode ?? this.modifiedModel.getValue();
|
|
947
|
-
if (prev === newCode) return;
|
|
948
|
-
if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendModified(newCode.slice(prev.length), codeLanguage);
|
|
949
|
-
else {
|
|
950
|
-
this.flushModifiedAppendBufferSync();
|
|
951
|
-
const prevAfterFlush = this.modifiedModel.getValue();
|
|
952
|
-
const prevLine = this.modifiedModel.getLineCount();
|
|
953
|
-
this.applyMinimalEditToModel(this.modifiedModel, prevAfterFlush, newCode);
|
|
954
|
-
const newLine = this.modifiedModel.getLineCount();
|
|
955
|
-
if (newLine !== prevLine) {
|
|
956
|
-
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
957
|
-
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
958
|
-
const computed$2 = this.computedHeight();
|
|
959
|
-
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
960
|
-
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
961
|
-
this.lastContainer.style.overflow = "auto";
|
|
962
|
-
}
|
|
963
|
-
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
964
|
-
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
965
|
-
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
966
|
-
var _editor3, _me2$getModel, _me2$getScrollTop;
|
|
967
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
968
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
969
|
-
const me2 = this.diffEditorView.getModifiedEditor();
|
|
970
|
-
const targetLine = ((_me2$getModel = me2.getModel()) === null || _me2$getModel === void 0 ? void 0 : _me2$getModel.getLineCount()) ?? newLine;
|
|
971
|
-
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
972
|
-
else me2.revealLine(targetLine);
|
|
973
|
-
this.lastRevealLineDiff = targetLine;
|
|
974
|
-
this.shouldAutoScrollDiff = true;
|
|
975
|
-
this.lastScrollTopDiff = ((_me2$getScrollTop = me2.getScrollTop) === null || _me2$getScrollTop === void 0 ? void 0 : _me2$getScrollTop.call(me2)) ?? this.lastScrollTopDiff;
|
|
976
|
-
} catch {}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
this.lastKnownModifiedCode = newCode;
|
|
980
|
-
}
|
|
981
|
-
appendOriginal(appendText, codeLanguage) {
|
|
982
|
-
if (!this.diffEditorView || !this.originalModel || !appendText) return;
|
|
983
|
-
if (codeLanguage) {
|
|
984
|
-
const lang = processedLanguage(codeLanguage);
|
|
985
|
-
if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
|
|
986
|
-
}
|
|
987
|
-
this.appendBufferOriginalDiff.push(appendText);
|
|
988
|
-
this.scheduleFlushAppendBufferDiff();
|
|
989
|
-
}
|
|
990
|
-
appendModified(appendText, codeLanguage) {
|
|
991
|
-
if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
|
|
992
|
-
if (codeLanguage) {
|
|
993
|
-
const lang = processedLanguage(codeLanguage);
|
|
994
|
-
if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
|
|
995
|
-
}
|
|
996
|
-
this.appendBufferModifiedDiff.push(appendText);
|
|
997
|
-
this.scheduleFlushAppendBufferDiff();
|
|
998
|
-
}
|
|
999
|
-
setLanguage(language, languages$1) {
|
|
1000
|
-
if (!languages$1.includes(language)) {
|
|
1001
|
-
console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
if (this.originalModel && this.originalModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.originalModel, language);
|
|
1005
|
-
if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
|
|
1006
|
-
}
|
|
1007
|
-
getDiffEditorView() {
|
|
1008
|
-
return this.diffEditorView;
|
|
1009
|
-
}
|
|
1010
|
-
getDiffModels() {
|
|
1011
|
-
return {
|
|
1012
|
-
original: this.originalModel,
|
|
1013
|
-
modified: this.modifiedModel
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
|
-
cleanup() {
|
|
1017
|
-
this.rafScheduler.cancel("diff");
|
|
1018
|
-
this.pendingDiffUpdate = null;
|
|
1019
|
-
this.rafScheduler.cancel("appendDiff");
|
|
1020
|
-
this.appendBufferDiffScheduled = false;
|
|
1021
|
-
this.appendBufferOriginalDiff.length = 0;
|
|
1022
|
-
this.appendBufferModifiedDiff.length = 0;
|
|
1023
|
-
if (this.appendFlushThrottleTimerDiff != null) {
|
|
1024
|
-
clearTimeout(this.appendFlushThrottleTimerDiff);
|
|
1025
|
-
this.appendFlushThrottleTimerDiff = null;
|
|
1026
|
-
}
|
|
1027
|
-
this.rafScheduler.cancel("content-size-change-diff");
|
|
1028
|
-
this.rafScheduler.cancel("sync-last-known-modified");
|
|
1029
|
-
if (this.diffScrollWatcher) {
|
|
1030
|
-
this.diffScrollWatcher.dispose();
|
|
1031
|
-
this.diffScrollWatcher = null;
|
|
1032
|
-
}
|
|
1033
|
-
if (this.diffHeightManager) {
|
|
1034
|
-
this.diffHeightManager.dispose();
|
|
1035
|
-
this.diffHeightManager = null;
|
|
1036
|
-
}
|
|
1037
|
-
if (this.diffEditorView) {
|
|
1038
|
-
this.diffEditorView.dispose();
|
|
1039
|
-
this.diffEditorView = null;
|
|
1040
|
-
}
|
|
1041
|
-
if (this.originalModel) {
|
|
1042
|
-
this.originalModel.dispose();
|
|
1043
|
-
this.originalModel = null;
|
|
1044
|
-
}
|
|
1045
|
-
if (this.modifiedModel) {
|
|
1046
|
-
this.modifiedModel.dispose();
|
|
1047
|
-
this.modifiedModel = null;
|
|
1048
|
-
}
|
|
1049
|
-
this.lastKnownOriginalCode = null;
|
|
1050
|
-
this.lastKnownModifiedCode = null;
|
|
1051
|
-
if (this.lastContainer) {
|
|
1052
|
-
this.lastContainer.innerHTML = "";
|
|
1053
|
-
this.lastContainer = null;
|
|
1054
|
-
}
|
|
1055
|
-
if (this.revealDebounceIdDiff != null) {
|
|
1056
|
-
clearTimeout(this.revealDebounceIdDiff);
|
|
1057
|
-
this.revealDebounceIdDiff = null;
|
|
1058
|
-
}
|
|
1059
|
-
if (this.revealIdleTimerIdDiff != null) {
|
|
1060
|
-
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1061
|
-
this.revealIdleTimerIdDiff = null;
|
|
1062
|
-
}
|
|
1063
|
-
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1064
|
-
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1065
|
-
this.diffScrollWatcherSuppressionTimer = null;
|
|
1066
|
-
}
|
|
1067
|
-
this.revealTicketDiff = 0;
|
|
1068
|
-
this.lastRevealLineDiff = null;
|
|
1069
|
-
}
|
|
1070
|
-
safeClean() {
|
|
1071
|
-
this.rafScheduler.cancel("diff");
|
|
1072
|
-
this.pendingDiffUpdate = null;
|
|
1073
|
-
this.rafScheduler.cancel("appendDiff");
|
|
1074
|
-
this.appendBufferDiffScheduled = false;
|
|
1075
|
-
this.appendBufferOriginalDiff.length = 0;
|
|
1076
|
-
this.appendBufferModifiedDiff.length = 0;
|
|
1077
|
-
if (this.appendFlushThrottleTimerDiff != null) {
|
|
1078
|
-
clearTimeout(this.appendFlushThrottleTimerDiff);
|
|
1079
|
-
this.appendFlushThrottleTimerDiff = null;
|
|
1080
|
-
}
|
|
1081
|
-
if (this.diffScrollWatcher) {
|
|
1082
|
-
this.diffScrollWatcher.dispose();
|
|
1083
|
-
this.diffScrollWatcher = null;
|
|
1084
|
-
}
|
|
1085
|
-
this._hasScrollBar = false;
|
|
1086
|
-
this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
|
|
1087
|
-
this.lastScrollTopDiff = 0;
|
|
1088
|
-
if (this.diffHeightManager) {
|
|
1089
|
-
this.diffHeightManager.dispose();
|
|
1090
|
-
this.diffHeightManager = null;
|
|
1091
|
-
}
|
|
1092
|
-
if (this.revealDebounceIdDiff != null) {
|
|
1093
|
-
clearTimeout(this.revealDebounceIdDiff);
|
|
1094
|
-
this.revealDebounceIdDiff = null;
|
|
1095
|
-
}
|
|
1096
|
-
if (this.revealIdleTimerIdDiff != null) {
|
|
1097
|
-
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1098
|
-
this.revealIdleTimerIdDiff = null;
|
|
1099
|
-
}
|
|
1100
|
-
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1101
|
-
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1102
|
-
this.diffScrollWatcherSuppressionTimer = null;
|
|
1103
|
-
}
|
|
1104
|
-
this.revealTicketDiff = 0;
|
|
1105
|
-
this.lastRevealLineDiff = null;
|
|
1106
|
-
this.rafScheduler.cancel("content-size-change-diff");
|
|
1107
|
-
this.rafScheduler.cancel("sync-last-known-modified");
|
|
1108
|
-
}
|
|
1109
|
-
syncLastKnownModified() {
|
|
1110
|
-
if (!this.diffEditorView || !this.lastKnownModifiedDirty) return;
|
|
1111
|
-
try {
|
|
1112
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
1113
|
-
const model = me.getModel();
|
|
1114
|
-
if (model) {
|
|
1115
|
-
this.lastKnownModifiedCode = model.getValue();
|
|
1116
|
-
this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1117
|
-
}
|
|
1118
|
-
} finally {
|
|
1119
|
-
this.lastKnownModifiedDirty = false;
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
flushPendingDiffUpdate() {
|
|
1123
|
-
if (!this.pendingDiffUpdate || !this.diffEditorView) return;
|
|
1124
|
-
const o = this.originalModel;
|
|
1125
|
-
const m = this.modifiedModel;
|
|
1126
|
-
if (!o || !m) {
|
|
1127
|
-
this.pendingDiffUpdate = null;
|
|
1128
|
-
return;
|
|
1129
|
-
}
|
|
1130
|
-
const { original, modified, lang } = this.pendingDiffUpdate;
|
|
1131
|
-
this.pendingDiffUpdate = null;
|
|
1132
|
-
this.flushOriginalAppendBufferSync();
|
|
1133
|
-
this.flushModifiedAppendBufferSync();
|
|
1134
|
-
if (lang) {
|
|
1135
|
-
const plang = processedLanguage(lang);
|
|
1136
|
-
if (plang) {
|
|
1137
|
-
if (o.getLanguageId() !== plang) {
|
|
1138
|
-
monaco_shim_exports.editor.setModelLanguage(o, plang);
|
|
1139
|
-
monaco_shim_exports.editor.setModelLanguage(m, plang);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
if (this.lastKnownOriginalCode == null) this.lastKnownOriginalCode = o.getValue();
|
|
1144
|
-
if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = m.getValue();
|
|
1145
|
-
const prevO = this.lastKnownOriginalCode;
|
|
1146
|
-
if (prevO !== original) {
|
|
1147
|
-
if (original.startsWith(prevO) && prevO.length < original.length) this.appendToModel(o, original.slice(prevO.length));
|
|
1148
|
-
else this.applyMinimalEditToModel(o, prevO, original);
|
|
1149
|
-
this.lastKnownOriginalCode = original;
|
|
1150
|
-
}
|
|
1151
|
-
const prevM = m.getValue();
|
|
1152
|
-
const prevMLineCount = m.getLineCount();
|
|
1153
|
-
if (prevM !== modified) {
|
|
1154
|
-
if (modified.startsWith(prevM) && prevM.length < modified.length) this.appendToModel(m, modified.slice(prevM.length));
|
|
1155
|
-
else this.applyMinimalEditToModel(m, prevM, modified);
|
|
1156
|
-
this.lastKnownModifiedCode = modified;
|
|
1157
|
-
const newMLineCount = m.getLineCount();
|
|
1158
|
-
if (newMLineCount !== prevMLineCount) {
|
|
1159
|
-
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1160
|
-
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1161
|
-
const computed$2 = this.computedHeight();
|
|
1162
|
-
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1163
|
-
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1164
|
-
this.lastContainer.style.overflow = "auto";
|
|
1165
|
-
}
|
|
1166
|
-
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newMLineCount);
|
|
1167
|
-
else this.maybeScrollDiffToBottom(newMLineCount, prevMLineCount);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
flushModifiedAppendBufferSync() {
|
|
1172
|
-
if (!this.modifiedModel) return;
|
|
1173
|
-
if (this.appendBufferModifiedDiff.length === 0) return;
|
|
1174
|
-
this.rafScheduler.cancel("appendDiff");
|
|
1175
|
-
this.appendBufferDiffScheduled = false;
|
|
1176
|
-
const text = this.appendBufferModifiedDiff.join("");
|
|
1177
|
-
this.appendBufferModifiedDiff.length = 0;
|
|
1178
|
-
if (!text) return;
|
|
1179
|
-
this.appendToModel(this.modifiedModel, text);
|
|
1180
|
-
}
|
|
1181
|
-
async flushAppendBufferDiff() {
|
|
1182
|
-
if (!this.diffEditorView) return;
|
|
1183
|
-
if (this.appendBufferOriginalDiff.length === 0 && this.appendBufferModifiedDiff.length === 0) return;
|
|
1184
|
-
this.lastAppendFlushTimeDiff = Date.now();
|
|
1185
|
-
this.appendBufferDiffScheduled = false;
|
|
1186
|
-
if (this.originalModel && this.appendBufferOriginalDiff.length > 0) {
|
|
1187
|
-
const oText = this.appendBufferOriginalDiff.join("");
|
|
1188
|
-
this.appendBufferOriginalDiff.length = 0;
|
|
1189
|
-
if (oText) this.appendToModel(this.originalModel, oText);
|
|
1190
|
-
}
|
|
1191
|
-
const me = this.diffEditorView.getModifiedEditor();
|
|
1192
|
-
const model = me.getModel();
|
|
1193
|
-
if (!model) {
|
|
1194
|
-
this.appendBufferModifiedDiff.length = 0;
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
let parts = this.appendBufferModifiedDiff.splice(0);
|
|
1198
|
-
const prevLineInit = model.getLineCount();
|
|
1199
|
-
const totalText = parts.join("");
|
|
1200
|
-
const totalChars = totalText.length;
|
|
1201
|
-
if (parts.length === 1 && totalChars > 5e3) {
|
|
1202
|
-
const lines = totalText.split(/\r?\n/);
|
|
1203
|
-
const chunkSize = 200;
|
|
1204
|
-
const chunks = [];
|
|
1205
|
-
for (let i = 0; i < lines.length; i += chunkSize) chunks.push(`${lines.slice(i, i + chunkSize).join("\n")}\n`);
|
|
1206
|
-
if (chunks.length > 1) parts = chunks;
|
|
1207
|
-
}
|
|
1208
|
-
const applyChunked = parts.length > 1 && (totalChars > 2e3 || model.getLineCount && model.getLineCount() + 0 - prevLineInit > 50);
|
|
1209
|
-
log("diff", "flushAppendBufferDiff start", {
|
|
1210
|
-
partsCount: parts.length,
|
|
1211
|
-
totalChars,
|
|
1212
|
-
applyChunked
|
|
1213
|
-
});
|
|
1214
|
-
let prevLine = prevLineInit;
|
|
1215
|
-
const watcherApi = this.diffScrollWatcher;
|
|
1216
|
-
let suppressedByFlush = false;
|
|
1217
|
-
if (watcherApi && typeof watcherApi.setSuppressed === "function") try {
|
|
1218
|
-
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1219
|
-
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1220
|
-
this.diffScrollWatcherSuppressionTimer = null;
|
|
1221
|
-
}
|
|
1222
|
-
watcherApi.setSuppressed(true);
|
|
1223
|
-
suppressedByFlush = true;
|
|
1224
|
-
} catch {}
|
|
1225
|
-
if (applyChunked) {
|
|
1226
|
-
log("diff", "flushAppendBufferDiff applying chunked", { partsLen: parts.length });
|
|
1227
|
-
let idx = 0;
|
|
1228
|
-
for (const part of parts) {
|
|
1229
|
-
if (!part) continue;
|
|
1230
|
-
idx += 1;
|
|
1231
|
-
log("diff", "flushAppendBufferDiff chunk", {
|
|
1232
|
-
idx,
|
|
1233
|
-
partLen: part.length,
|
|
1234
|
-
prevLine
|
|
1235
|
-
});
|
|
1236
|
-
const lastColumn$1 = model.getLineMaxColumn(prevLine);
|
|
1237
|
-
const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
|
|
1238
|
-
model.applyEdits([{
|
|
1239
|
-
range: range$1,
|
|
1240
|
-
text: part,
|
|
1241
|
-
forceMoveMarkers: true
|
|
1242
|
-
}]);
|
|
1243
|
-
this.lastKnownModifiedCode = model.getValue();
|
|
1244
|
-
const newLine$1 = model.getLineCount();
|
|
1245
|
-
this.lastKnownModifiedLineCount = newLine$1;
|
|
1246
|
-
await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
|
|
1247
|
-
const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
|
|
1248
|
-
log("diff", "flushAppendBufferDiff chunk metrics", {
|
|
1249
|
-
idx,
|
|
1250
|
-
newLine: newLine$1,
|
|
1251
|
-
prevLine,
|
|
1252
|
-
shouldImmediate: shouldImmediate$1
|
|
1253
|
-
});
|
|
1254
|
-
if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1255
|
-
const computed$3 = this.computedHeight();
|
|
1256
|
-
if (computed$3 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1257
|
-
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1258
|
-
this.lastContainer.style.overflow = "auto";
|
|
1259
|
-
}
|
|
1260
|
-
if (shouldImmediate$1) this.scheduleImmediateRevealAfterLayoutDiff(newLine$1);
|
|
1261
|
-
else this.maybeScrollDiffToBottom(newLine$1, prevLine);
|
|
1262
|
-
prevLine = newLine$1;
|
|
1263
|
-
log("diff", "flushAppendBufferDiff chunk applied", {
|
|
1264
|
-
idx,
|
|
1265
|
-
newLine: newLine$1
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
const text = totalText;
|
|
1272
|
-
this.appendBufferModifiedDiff.length = 0;
|
|
1273
|
-
prevLine = model.getLineCount();
|
|
1274
|
-
const lastColumn = model.getLineMaxColumn(prevLine);
|
|
1275
|
-
const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
|
|
1276
|
-
model.applyEdits([{
|
|
1277
|
-
range,
|
|
1278
|
-
text,
|
|
1279
|
-
forceMoveMarkers: true
|
|
1280
|
-
}]);
|
|
1281
|
-
this.lastKnownModifiedCode = model.getValue();
|
|
1282
|
-
const newLine = model.getLineCount();
|
|
1283
|
-
this.lastKnownModifiedLineCount = newLine;
|
|
1284
|
-
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1285
|
-
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1286
|
-
const computed$2 = this.computedHeight();
|
|
1287
|
-
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1288
|
-
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
1289
|
-
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
1290
|
-
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
1291
|
-
var _editor4, _me2$getModel2, _me2$getScrollTop2;
|
|
1292
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor4 = monaco_shim_exports.editor) === null || _editor4 === void 0 ? void 0 : _editor4.ScrollType);
|
|
1293
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1294
|
-
const me2 = this.diffEditorView.getModifiedEditor();
|
|
1295
|
-
const targetLine = ((_me2$getModel2 = me2.getModel()) === null || _me2$getModel2 === void 0 ? void 0 : _me2$getModel2.getLineCount()) ?? newLine;
|
|
1296
|
-
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
1297
|
-
else me2.revealLine(targetLine);
|
|
1298
|
-
this.lastRevealLineDiff = targetLine;
|
|
1299
|
-
this.shouldAutoScrollDiff = true;
|
|
1300
|
-
this.lastScrollTopDiff = ((_me2$getScrollTop2 = me2.getScrollTop) === null || _me2$getScrollTop2 === void 0 ? void 0 : _me2$getScrollTop2.call(me2)) ?? this.lastScrollTopDiff;
|
|
1301
|
-
} catch {}
|
|
1302
|
-
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
1303
|
-
try {
|
|
1304
|
-
var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7;
|
|
1305
|
-
this.shouldAutoScrollDiff = true;
|
|
1306
|
-
this.lastScrollTopDiff = ((_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || (_this$diffEditorView7 = (_this$diffEditorView6 = _this$diffEditorView5.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.call(_this$diffEditorView6)) ?? this.lastScrollTopDiff;
|
|
1307
|
-
} catch {}
|
|
1308
|
-
}
|
|
1309
|
-
applyMinimalEditToModel(model, prev, next) {
|
|
1310
|
-
const maxChars = minimalEditMaxChars;
|
|
1311
|
-
const ratio = minimalEditMaxChangeRatio;
|
|
1312
|
-
const maxLen = Math.max(prev.length, next.length);
|
|
1313
|
-
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1314
|
-
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1315
|
-
model.setValue(next);
|
|
1316
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
const res = computeMinimalEdit(prev, next);
|
|
1320
|
-
if (!res) return;
|
|
1321
|
-
const { start, endPrevIncl, replaceText } = res;
|
|
1322
|
-
const rangeStart = model.getPositionAt(start);
|
|
1323
|
-
const rangeEnd = model.getPositionAt(endPrevIncl + 1);
|
|
1324
|
-
const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
|
|
1325
|
-
model.applyEdits([{
|
|
1326
|
-
range,
|
|
1327
|
-
text: replaceText,
|
|
1328
|
-
forceMoveMarkers: true
|
|
1329
|
-
}]);
|
|
1330
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1331
|
-
}
|
|
1332
|
-
appendToModel(model, appendText) {
|
|
1333
|
-
if (!appendText) return;
|
|
1334
|
-
const lastLine = model.getLineCount();
|
|
1335
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
1336
|
-
const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
1337
|
-
model.applyEdits([{
|
|
1338
|
-
range,
|
|
1339
|
-
text: appendText,
|
|
1340
|
-
forceMoveMarkers: true
|
|
1341
|
-
}]);
|
|
1342
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
|
|
1346
|
-
//#endregion
|
|
1347
|
-
//#region src/core/EditorManager.ts
|
|
1348
|
-
var EditorManager = class {
|
|
1349
|
-
editorView = null;
|
|
1350
|
-
lastContainer = null;
|
|
1351
|
-
lastKnownCode = null;
|
|
1352
|
-
pendingUpdate = null;
|
|
1353
|
-
_hasScrollBar = false;
|
|
1354
|
-
shouldAutoScroll = true;
|
|
1355
|
-
scrollWatcher = null;
|
|
1356
|
-
scrollWatcherSuppressionTimer = null;
|
|
1357
|
-
lastScrollTop = 0;
|
|
1358
|
-
cachedScrollHeight = null;
|
|
1359
|
-
cachedLineHeight = null;
|
|
1360
|
-
cachedComputedHeight = null;
|
|
1361
|
-
cachedLineCount = null;
|
|
1362
|
-
lastKnownCodeDirty = false;
|
|
1363
|
-
debug = false;
|
|
1364
|
-
measureViewport() {
|
|
1365
|
-
var _this$editorView$getL, _this$editorView, _this$editorView$getS, _this$editorView2, _this$editorView$getS2, _this$editorView3;
|
|
1366
|
-
if (!this.editorView) return null;
|
|
1367
|
-
const li = ((_this$editorView$getL = (_this$editorView = this.editorView).getLayoutInfo) === null || _this$editorView$getL === void 0 ? void 0 : _this$editorView$getL.call(_this$editorView)) ?? null;
|
|
1368
|
-
const lineHeight = this.cachedLineHeight ?? this.editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
1369
|
-
const scrollTop = ((_this$editorView$getS = (_this$editorView2 = this.editorView).getScrollTop) === null || _this$editorView$getS === void 0 ? void 0 : _this$editorView$getS.call(_this$editorView2)) ?? this.lastScrollTop ?? 0;
|
|
1370
|
-
const scrollHeight = ((_this$editorView$getS2 = (_this$editorView3 = this.editorView).getScrollHeight) === null || _this$editorView$getS2 === void 0 ? void 0 : _this$editorView$getS2.call(_this$editorView3)) ?? this.cachedScrollHeight ?? (li === null || li === void 0 ? void 0 : li.height) ?? 0;
|
|
1371
|
-
const computedHeight = this.cachedComputedHeight ?? this.computedHeight(this.editorView);
|
|
1372
|
-
this.cachedLineHeight = lineHeight;
|
|
1373
|
-
this.cachedScrollHeight = scrollHeight;
|
|
1374
|
-
this.cachedComputedHeight = computedHeight;
|
|
1375
|
-
this.lastScrollTop = scrollTop;
|
|
1376
|
-
return {
|
|
1377
|
-
li,
|
|
1378
|
-
lineHeight,
|
|
1379
|
-
scrollTop,
|
|
1380
|
-
scrollHeight,
|
|
1381
|
-
computedHeight
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
|
-
appendBuffer = [];
|
|
1385
|
-
appendBufferScheduled = false;
|
|
1386
|
-
rafScheduler = createRafScheduler();
|
|
1387
|
-
editorHeightManager = null;
|
|
1388
|
-
revealDebounceId = null;
|
|
1389
|
-
revealDebounceMs = defaultRevealDebounceMs;
|
|
1390
|
-
revealIdleTimerId = null;
|
|
1391
|
-
revealTicket = 0;
|
|
1392
|
-
revealStrategyOption;
|
|
1393
|
-
revealBatchOnIdleMsOption;
|
|
1394
|
-
scrollWatcherSuppressionMs = 500;
|
|
1395
|
-
constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, revealDebounceMsOption) {
|
|
1396
|
-
this.options = options;
|
|
1397
|
-
this.maxHeightValue = maxHeightValue;
|
|
1398
|
-
this.maxHeightCSS = maxHeightCSS;
|
|
1399
|
-
this.autoScrollOnUpdate = autoScrollOnUpdate;
|
|
1400
|
-
this.autoScrollInitial = autoScrollInitial;
|
|
1401
|
-
this.autoScrollThresholdPx = autoScrollThresholdPx;
|
|
1402
|
-
this.autoScrollThresholdLines = autoScrollThresholdLines;
|
|
1403
|
-
this.revealDebounceMsOption = revealDebounceMsOption;
|
|
1404
|
-
}
|
|
1405
|
-
initDebugFlag() {
|
|
1406
|
-
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) {
|
|
1407
|
-
this.debug = Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
1408
|
-
return;
|
|
1409
|
-
}
|
|
1410
|
-
if (this.options && this.options.debug !== void 0) {
|
|
1411
|
-
this.debug = Boolean(this.options.debug);
|
|
1412
|
-
return;
|
|
1413
|
-
}
|
|
1414
|
-
this.debug = false;
|
|
1415
|
-
}
|
|
1416
|
-
dlog(...args) {
|
|
1417
|
-
if (!this.debug) return;
|
|
1418
|
-
log("EditorManager", ...args);
|
|
1419
|
-
}
|
|
1420
|
-
hasVerticalScrollbar() {
|
|
1421
|
-
if (!this.editorView) return false;
|
|
1422
|
-
if (this._hasScrollBar) return true;
|
|
1423
|
-
const m = this.measureViewport();
|
|
1424
|
-
if (!m) return false;
|
|
1425
|
-
return this._hasScrollBar = m.scrollHeight > m.computedHeight + padding / 2;
|
|
1426
|
-
}
|
|
1427
|
-
userIsNearBottom() {
|
|
1428
|
-
if (!this.editorView) return true;
|
|
1429
|
-
const m = this.measureViewport();
|
|
1430
|
-
if (!m || !m.li) return true;
|
|
1431
|
-
const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
|
|
1432
|
-
const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
|
|
1433
|
-
const distance = m.scrollHeight - (m.scrollTop + m.li.height);
|
|
1434
|
-
return distance <= threshold;
|
|
1435
|
-
}
|
|
1436
|
-
computedHeight(editorView) {
|
|
1437
|
-
var _editorView$getModel;
|
|
1438
|
-
const lineCount = this.cachedLineCount ?? ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getLineCount()) ?? 1;
|
|
1439
|
-
const lineHeight = editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
1440
|
-
const height = Math.min(lineCount * lineHeight + padding, this.maxHeightValue);
|
|
1441
|
-
log("EditorManager.computedHeight", {
|
|
1442
|
-
lineCount,
|
|
1443
|
-
lineHeight,
|
|
1444
|
-
computed: height,
|
|
1445
|
-
maxHeightValue: this.maxHeightValue
|
|
1446
|
-
});
|
|
1447
|
-
return height;
|
|
1448
|
-
}
|
|
1449
|
-
maybeScrollToBottom(targetLine) {
|
|
1450
|
-
this.rafScheduler.schedule("maybe-scroll", () => {
|
|
1451
|
-
const hasVS = this.hasVerticalScrollbar();
|
|
1452
|
-
this.dlog("maybeScrollToBottom called", {
|
|
1453
|
-
autoScrollOnUpdate: this.autoScrollOnUpdate,
|
|
1454
|
-
shouldAutoScroll: this.shouldAutoScroll,
|
|
1455
|
-
hasVerticalScrollbar: hasVS,
|
|
1456
|
-
targetLine
|
|
1457
|
-
});
|
|
1458
|
-
if (!(this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar())) {
|
|
1459
|
-
this.dlog("maybeScrollToBottom skipped (auto-scroll conditions not met)");
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
const model = this.editorView.getModel();
|
|
1463
|
-
const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
1464
|
-
const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
|
|
1465
|
-
if (typeof batchMs === "number" && batchMs > 0) {
|
|
1466
|
-
if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
|
|
1467
|
-
const ticket = ++this.revealTicket;
|
|
1468
|
-
this.dlog("scheduled idle reveal ticket=", ticket, "line=", line, "batchMs=", batchMs);
|
|
1469
|
-
this.revealIdleTimerId = setTimeout(() => {
|
|
1470
|
-
this.revealIdleTimerId = null;
|
|
1471
|
-
this.dlog("idle reveal timer firing, ticket=", ticket, "line=", line);
|
|
1472
|
-
this.performReveal(line, ticket);
|
|
1473
|
-
}, batchMs);
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
if (this.revealDebounceId != null) {
|
|
1477
|
-
clearTimeout(this.revealDebounceId);
|
|
1478
|
-
this.revealDebounceId = null;
|
|
1479
|
-
}
|
|
1480
|
-
const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
|
|
1481
|
-
this.revealDebounceId = setTimeout(() => {
|
|
1482
|
-
this.revealDebounceId = null;
|
|
1483
|
-
const ticket = ++this.revealTicket;
|
|
1484
|
-
this.dlog("scheduled debounce reveal ticket=", ticket, "line=", line, "ms=", ms);
|
|
1485
|
-
this.performReveal(line, ticket);
|
|
1486
|
-
}, ms);
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
performReveal(line, ticket) {
|
|
1490
|
-
this.rafScheduler.schedule("reveal", () => {
|
|
1491
|
-
var _editor;
|
|
1492
|
-
if (ticket !== this.revealTicket) {
|
|
1493
|
-
this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
1494
|
-
return;
|
|
1495
|
-
}
|
|
1496
|
-
this.dlog("performReveal executing, ticket=", ticket, "line=", line);
|
|
1497
|
-
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
1498
|
-
this.dlog("performReveal strategy=", strategy);
|
|
1499
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
1500
|
-
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
1501
|
-
try {
|
|
1502
|
-
if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
|
|
1503
|
-
else this.editorView.revealLine(line);
|
|
1504
|
-
else if (strategy === "center") if (typeof smooth !== "undefined") this.editorView.revealLineInCenter(line, smooth);
|
|
1505
|
-
else this.editorView.revealLineInCenter(line);
|
|
1506
|
-
else if (typeof smooth !== "undefined") this.editorView.revealLineInCenterIfOutsideViewport(line, smooth);
|
|
1507
|
-
else this.editorView.revealLineInCenterIfOutsideViewport(line);
|
|
1508
|
-
} catch {
|
|
1509
|
-
try {
|
|
1510
|
-
this.editorView.revealLine(line);
|
|
1511
|
-
} catch {}
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
performImmediateReveal(line, ticket) {
|
|
1516
|
-
this.dlog("performImmediateReveal line=", line, "ticket=", ticket);
|
|
1517
|
-
try {
|
|
1518
|
-
var _editor2;
|
|
1519
|
-
if (!this.editorView) return;
|
|
1520
|
-
if (ticket !== this.revealTicket) {
|
|
1521
|
-
this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
1525
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1526
|
-
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
1527
|
-
else this.editorView.revealLine(line);
|
|
1528
|
-
} catch {}
|
|
1529
|
-
try {
|
|
1530
|
-
this.measureViewport();
|
|
1531
|
-
} catch {}
|
|
1532
|
-
}
|
|
1533
|
-
forceReveal(line) {
|
|
1534
|
-
try {
|
|
1535
|
-
var _editor3;
|
|
1536
|
-
if (!this.editorView) return;
|
|
1537
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
1538
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1539
|
-
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
1540
|
-
else this.editorView.revealLine(line);
|
|
1541
|
-
} catch {}
|
|
1542
|
-
try {
|
|
1543
|
-
this.measureViewport();
|
|
1544
|
-
} catch {}
|
|
1545
|
-
try {
|
|
1546
|
-
var _this$editorView4, _this$editorView4$get;
|
|
1547
|
-
this.shouldAutoScroll = true;
|
|
1548
|
-
this.lastScrollTop = ((_this$editorView4 = this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4$get = _this$editorView4.getScrollTop) === null || _this$editorView4$get === void 0 ? void 0 : _this$editorView4$get.call(_this$editorView4)) ?? this.lastScrollTop;
|
|
1549
|
-
} catch {}
|
|
1550
|
-
}
|
|
1551
|
-
isOverflowAuto() {
|
|
1552
|
-
try {
|
|
1553
|
-
return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
|
|
1554
|
-
} catch {
|
|
1555
|
-
return false;
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
shouldPerformImmediateReveal() {
|
|
1559
|
-
return this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar() && this.isOverflowAuto();
|
|
1560
|
-
}
|
|
1561
|
-
async createEditor(container, code, language, currentTheme) {
|
|
1562
|
-
var _this$editorView$getS3, _this$editorView5, _this$editorView$getO, _this$editorView6, _this$editorView$getM, _this$editorView$onDi, _this$editorView7;
|
|
1563
|
-
this.cleanup();
|
|
1564
|
-
this.lastContainer = container;
|
|
1565
|
-
this.initDebugFlag();
|
|
1566
|
-
this.dlog("createEditor container, maxHeight", this.maxHeightValue);
|
|
1567
|
-
container.style.overflow = "hidden";
|
|
1568
|
-
container.style.maxHeight = this.maxHeightCSS;
|
|
1569
|
-
this.editorView = monaco_shim_exports.editor.create(container, {
|
|
1570
|
-
value: code,
|
|
1571
|
-
language: processedLanguage(language) || language,
|
|
1572
|
-
theme: currentTheme,
|
|
1573
|
-
scrollBeyondLastLine: false,
|
|
1574
|
-
minimap: { enabled: false },
|
|
1575
|
-
automaticLayout: true,
|
|
1576
|
-
readOnly: this.options.readOnly ?? true,
|
|
1577
|
-
contextmenu: false,
|
|
1578
|
-
scrollbar: {
|
|
1579
|
-
...defaultScrollbar,
|
|
1580
|
-
...this.options.scrollbar || {}
|
|
1581
|
-
},
|
|
1582
|
-
...this.options
|
|
1583
|
-
});
|
|
1584
|
-
monaco_shim_exports.editor.setTheme(currentTheme);
|
|
1585
|
-
this.lastKnownCode = this.editorView.getValue();
|
|
1586
|
-
if (this.editorHeightManager) {
|
|
1587
|
-
try {
|
|
1588
|
-
this.editorHeightManager.dispose();
|
|
1589
|
-
} catch {}
|
|
1590
|
-
this.editorHeightManager = null;
|
|
1591
|
-
}
|
|
1592
|
-
if (this.revealDebounceId != null) {
|
|
1593
|
-
clearTimeout(this.revealDebounceId);
|
|
1594
|
-
this.revealDebounceId = null;
|
|
1595
|
-
}
|
|
1596
|
-
if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
|
|
1597
|
-
this.revealIdleTimerId = null;
|
|
1598
|
-
const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
|
|
1599
|
-
container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
|
|
1600
|
-
this.editorHeightManager = createHeightManager(container, () => {
|
|
1601
|
-
const computed$2 = this.computedHeight(this.editorView);
|
|
1602
|
-
const clamped = Math.min(computed$2, this.maxHeightValue);
|
|
1603
|
-
return Math.max(clamped, MIN_VISIBLE_HEIGHT);
|
|
1604
|
-
});
|
|
1605
|
-
this.editorHeightManager.update();
|
|
1606
|
-
const initialComputed = this.computedHeight(this.editorView);
|
|
1607
|
-
if (initialComputed >= this.maxHeightValue - 1) {
|
|
1608
|
-
container.style.height = `${this.maxHeightValue}px`;
|
|
1609
|
-
container.style.overflow = "auto";
|
|
1610
|
-
this.dlog("applied immediate maxHeight on createEditor", this.maxHeightValue);
|
|
1611
|
-
}
|
|
1612
|
-
this.cachedScrollHeight = ((_this$editorView$getS3 = (_this$editorView5 = this.editorView).getScrollHeight) === null || _this$editorView$getS3 === void 0 ? void 0 : _this$editorView$getS3.call(_this$editorView5)) ?? null;
|
|
1613
|
-
this.cachedLineHeight = ((_this$editorView$getO = (_this$editorView6 = this.editorView).getOption) === null || _this$editorView$getO === void 0 ? void 0 : _this$editorView$getO.call(_this$editorView6, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
|
|
1614
|
-
this.cachedComputedHeight = this.computedHeight(this.editorView);
|
|
1615
|
-
this.cachedLineCount = ((_this$editorView$getM = this.editorView.getModel()) === null || _this$editorView$getM === void 0 ? void 0 : _this$editorView$getM.getLineCount()) ?? null;
|
|
1616
|
-
(_this$editorView$onDi = (_this$editorView7 = this.editorView).onDidContentSizeChange) === null || _this$editorView$onDi === void 0 || _this$editorView$onDi.call(_this$editorView7, () => {
|
|
1617
|
-
this._hasScrollBar = false;
|
|
1618
|
-
this.rafScheduler.schedule("content-size-change", () => {
|
|
1619
|
-
try {
|
|
1620
|
-
var _this$editorView8, _this$editorHeightMan, _this$editorHeightMan2;
|
|
1621
|
-
this.dlog("content-size-change frame");
|
|
1622
|
-
const m = this.measureViewport();
|
|
1623
|
-
this.dlog("content-size-change measure", m);
|
|
1624
|
-
this.cachedLineCount = ((_this$editorView8 = this.editorView) === null || _this$editorView8 === void 0 || (_this$editorView8 = _this$editorView8.getModel()) === null || _this$editorView8 === void 0 ? void 0 : _this$editorView8.getLineCount()) ?? this.cachedLineCount;
|
|
1625
|
-
if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
|
|
1626
|
-
this.dlog("content-size-change skipped height update (suppressed)");
|
|
1627
|
-
return;
|
|
1628
|
-
}
|
|
1629
|
-
this.dlog("content-size-change calling heightManager.update");
|
|
1630
|
-
(_this$editorHeightMan2 = this.editorHeightManager) === null || _this$editorHeightMan2 === void 0 || _this$editorHeightMan2.update();
|
|
1631
|
-
const computed$2 = this.computedHeight(this.editorView);
|
|
1632
|
-
if (this.lastContainer) {
|
|
1633
|
-
const prevOverflow = this.lastContainer.style.overflow;
|
|
1634
|
-
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
1635
|
-
if (prevOverflow !== newOverflow) {
|
|
1636
|
-
this.lastContainer.style.overflow = newOverflow;
|
|
1637
|
-
if (newOverflow === "auto" && this.shouldAutoScroll) this.maybeScrollToBottom();
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
} catch (err) {
|
|
1641
|
-
error("EditorManager", "content-size-change error", err);
|
|
1642
|
-
}
|
|
1643
|
-
});
|
|
1644
|
-
});
|
|
1645
|
-
this.editorView.onDidChangeModelContent(() => {
|
|
1646
|
-
this.lastKnownCodeDirty = true;
|
|
1647
|
-
this.rafScheduler.schedule("sync-last-known", () => this.syncLastKnownCode());
|
|
1648
|
-
});
|
|
1649
|
-
this.shouldAutoScroll = !!this.autoScrollInitial;
|
|
1650
|
-
if (this.scrollWatcher) {
|
|
1651
|
-
this.scrollWatcher.dispose();
|
|
1652
|
-
this.scrollWatcher = null;
|
|
1653
|
-
}
|
|
1654
|
-
this.scrollWatcher = createScrollWatcherForEditor(this.editorView, {
|
|
1655
|
-
onPause: () => {
|
|
1656
|
-
this.shouldAutoScroll = false;
|
|
1657
|
-
},
|
|
1658
|
-
onMaybeResume: () => {
|
|
1659
|
-
this.rafScheduler.schedule("maybe-resume", () => {
|
|
1660
|
-
this.shouldAutoScroll = this.userIsNearBottom();
|
|
1661
|
-
});
|
|
1662
|
-
},
|
|
1663
|
-
getLast: () => this.lastScrollTop,
|
|
1664
|
-
setLast: (v) => {
|
|
1665
|
-
this.lastScrollTop = v;
|
|
1666
|
-
}
|
|
1667
|
-
});
|
|
1668
|
-
this.maybeScrollToBottom();
|
|
1669
|
-
return this.editorView;
|
|
1670
|
-
}
|
|
1671
|
-
syncLastKnownCode() {
|
|
1672
|
-
if (!this.editorView || !this.lastKnownCodeDirty) return;
|
|
1673
|
-
const model = this.editorView.getModel();
|
|
1674
|
-
if (model) {
|
|
1675
|
-
this.lastKnownCode = model.getValue();
|
|
1676
|
-
this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
|
|
1677
|
-
}
|
|
1678
|
-
this.lastKnownCodeDirty = false;
|
|
1679
|
-
}
|
|
1680
|
-
suppressScrollWatcher(ms) {
|
|
1681
|
-
if (!this.scrollWatcher || typeof this.scrollWatcher.setSuppressed !== "function") return;
|
|
1682
|
-
this.dlog("suppressScrollWatcher", ms);
|
|
1683
|
-
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1684
|
-
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1685
|
-
this.scrollWatcherSuppressionTimer = null;
|
|
1686
|
-
}
|
|
1687
|
-
this.scrollWatcher.setSuppressed(true);
|
|
1688
|
-
this.scrollWatcherSuppressionTimer = setTimeout(() => {
|
|
1689
|
-
if (this.scrollWatcher && typeof this.scrollWatcher.setSuppressed === "function") {
|
|
1690
|
-
this.scrollWatcher.setSuppressed(false);
|
|
1691
|
-
this.dlog("suppressScrollWatcher cleared");
|
|
1692
|
-
}
|
|
1693
|
-
this.scrollWatcherSuppressionTimer = null;
|
|
1694
|
-
}, ms);
|
|
1695
|
-
}
|
|
1696
|
-
scheduleImmediateRevealAfterLayout(line) {
|
|
1697
|
-
const ticket = ++this.revealTicket;
|
|
1698
|
-
this.dlog("scheduleImmediateRevealAfterLayout ticket=", ticket, "line=", line);
|
|
1699
|
-
this.rafScheduler.schedule("immediate-reveal", async () => {
|
|
1700
|
-
try {
|
|
1701
|
-
const target = this.editorView && this.editorHeightManager ? Math.min(this.computedHeight(this.editorView), this.maxHeightValue) : -1;
|
|
1702
|
-
if (target !== -1 && this.editorHeightManager) await this.waitForHeightApplied(target, 500);
|
|
1703
|
-
else await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r())));
|
|
1704
|
-
this.dlog("running delayed immediate reveal", "ticket=", ticket, "line=", line);
|
|
1705
|
-
this.performImmediateReveal(line, ticket);
|
|
1706
|
-
} catch (err) {
|
|
1707
|
-
error("EditorManager", "scheduleImmediateRevealAfterLayout error", err);
|
|
1708
|
-
}
|
|
1709
|
-
});
|
|
1710
|
-
}
|
|
1711
|
-
waitForHeightApplied(target, timeoutMs = 500) {
|
|
1712
|
-
return new Promise((resolve) => {
|
|
1713
|
-
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1714
|
-
const check = () => {
|
|
1715
|
-
try {
|
|
1716
|
-
var _this$editorHeightMan3, _this$editorHeightMan4;
|
|
1717
|
-
const last = ((_this$editorHeightMan3 = this.editorHeightManager) === null || _this$editorHeightMan3 === void 0 || (_this$editorHeightMan4 = _this$editorHeightMan3.getLastApplied) === null || _this$editorHeightMan4 === void 0 ? void 0 : _this$editorHeightMan4.call(_this$editorHeightMan3)) ?? -1;
|
|
1718
|
-
if (last !== -1 && Math.abs(last - target) <= 12) {
|
|
1719
|
-
this.dlog("waitForHeightApplied satisfied", last, "target=", target);
|
|
1720
|
-
resolve();
|
|
1721
|
-
return;
|
|
1722
|
-
}
|
|
1723
|
-
const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1724
|
-
if (now - start > timeoutMs) {
|
|
1725
|
-
log("EditorManager", "waitForHeightApplied timeout", last, "target=", target);
|
|
1726
|
-
resolve();
|
|
1727
|
-
return;
|
|
1728
|
-
}
|
|
1729
|
-
} catch {}
|
|
1730
|
-
requestAnimationFrame(check);
|
|
1731
|
-
};
|
|
1732
|
-
check();
|
|
1733
|
-
});
|
|
1734
|
-
}
|
|
1735
|
-
updateCode(newCode, codeLanguage) {
|
|
1736
|
-
this.pendingUpdate = {
|
|
1737
|
-
code: newCode,
|
|
1738
|
-
lang: codeLanguage
|
|
1739
|
-
};
|
|
1740
|
-
this.rafScheduler.schedule("update", () => this.flushPendingUpdate());
|
|
1741
|
-
}
|
|
1742
|
-
flushPendingUpdate() {
|
|
1743
|
-
if (!this.pendingUpdate || !this.editorView) return;
|
|
1744
|
-
const model = this.editorView.getModel();
|
|
1745
|
-
if (!model) return;
|
|
1746
|
-
const { code: newCode, lang: codeLanguage } = this.pendingUpdate;
|
|
1747
|
-
this.pendingUpdate = null;
|
|
1748
|
-
const processedCodeLanguage = processedLanguage(codeLanguage);
|
|
1749
|
-
const languageId = model.getLanguageId();
|
|
1750
|
-
if (languageId !== processedCodeLanguage) {
|
|
1751
|
-
if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
|
|
1752
|
-
const prevLineCount$1 = model.getLineCount();
|
|
1753
|
-
model.setValue(newCode);
|
|
1754
|
-
this.lastKnownCode = newCode;
|
|
1755
|
-
const newLineCount$1 = model.getLineCount();
|
|
1756
|
-
this.cachedLineCount = newLineCount$1;
|
|
1757
|
-
if (newLineCount$1 !== prevLineCount$1) {
|
|
1758
|
-
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1759
|
-
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1760
|
-
const computed$2 = this.computedHeight(this.editorView);
|
|
1761
|
-
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1762
|
-
this.forceReveal(newLineCount$1);
|
|
1763
|
-
}
|
|
1764
|
-
return;
|
|
1765
|
-
}
|
|
1766
|
-
const buffered = this.appendBuffer.length > 0 ? this.appendBuffer.join("") : "";
|
|
1767
|
-
const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() + buffered : this.lastKnownCode ?? this.editorView.getValue();
|
|
1768
|
-
if (prevCode === newCode) return;
|
|
1769
|
-
if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
|
|
1770
|
-
const suffix = newCode.slice(prevCode.length);
|
|
1771
|
-
if (suffix) this.appendCode(suffix, codeLanguage);
|
|
1772
|
-
this.lastKnownCode = newCode;
|
|
1773
|
-
return;
|
|
1774
|
-
}
|
|
1775
|
-
const prevLineCount = model.getLineCount();
|
|
1776
|
-
this.applyMinimalEdit(prevCode, newCode);
|
|
1777
|
-
this.lastKnownCode = newCode;
|
|
1778
|
-
const newLineCount = model.getLineCount();
|
|
1779
|
-
this.cachedLineCount = newLineCount;
|
|
1780
|
-
if (newLineCount !== prevLineCount) {
|
|
1781
|
-
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1782
|
-
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1783
|
-
if (shouldImmediate) this.scheduleImmediateRevealAfterLayout(newLineCount);
|
|
1784
|
-
else this.maybeScrollToBottom(newLineCount);
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
appendCode(appendText, codeLanguage) {
|
|
1788
|
-
if (!this.editorView) return;
|
|
1789
|
-
const model = this.editorView.getModel();
|
|
1790
|
-
if (!model) return;
|
|
1791
|
-
const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
|
|
1792
|
-
if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
|
|
1793
|
-
if (appendText) {
|
|
1794
|
-
this.appendBuffer.push(appendText);
|
|
1795
|
-
if (!this.appendBufferScheduled) {
|
|
1796
|
-
this.appendBufferScheduled = true;
|
|
1797
|
-
this.rafScheduler.schedule("append", () => this.flushAppendBuffer());
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
applyMinimalEdit(prev, next) {
|
|
1802
|
-
if (!this.editorView) return;
|
|
1803
|
-
const model = this.editorView.getModel();
|
|
1804
|
-
if (!model) return;
|
|
1805
|
-
const maxChars = minimalEditMaxChars;
|
|
1806
|
-
const ratio = minimalEditMaxChangeRatio;
|
|
1807
|
-
const maxLen = Math.max(prev.length, next.length);
|
|
1808
|
-
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1809
|
-
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1810
|
-
const prevLineCount = model.getLineCount();
|
|
1811
|
-
model.setValue(next);
|
|
1812
|
-
this.lastKnownCode = next;
|
|
1813
|
-
const newLineCount = model.getLineCount();
|
|
1814
|
-
this.cachedLineCount = newLineCount;
|
|
1815
|
-
if (newLineCount !== prevLineCount) this.maybeScrollToBottom(newLineCount);
|
|
1816
|
-
return;
|
|
1817
|
-
}
|
|
1818
|
-
const res = computeMinimalEdit(prev, next);
|
|
1819
|
-
if (!res) return;
|
|
1820
|
-
const { start, endPrevIncl, replaceText } = res;
|
|
1821
|
-
const rangeStart = model.getPositionAt(start);
|
|
1822
|
-
const rangeEnd = model.getPositionAt(endPrevIncl + 1);
|
|
1823
|
-
const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
|
|
1824
|
-
const isReadOnly = this.editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
1825
|
-
const edit = [{
|
|
1826
|
-
range,
|
|
1827
|
-
text: replaceText,
|
|
1828
|
-
forceMoveMarkers: true
|
|
1829
|
-
}];
|
|
1830
|
-
if (isReadOnly) model.applyEdits(edit);
|
|
1831
|
-
else this.editorView.executeEdits("minimal-replace", edit);
|
|
1832
|
-
}
|
|
1833
|
-
flushAppendBuffer() {
|
|
1834
|
-
if (!this.editorView) return;
|
|
1835
|
-
if (this.appendBuffer.length === 0) return;
|
|
1836
|
-
this.appendBufferScheduled = false;
|
|
1837
|
-
const model = this.editorView.getModel();
|
|
1838
|
-
if (!model) {
|
|
1839
|
-
this.appendBuffer.length = 0;
|
|
1840
|
-
return;
|
|
1841
|
-
}
|
|
1842
|
-
const text = this.appendBuffer.join("");
|
|
1843
|
-
this.appendBuffer.length = 0;
|
|
1844
|
-
const lastLine = model.getLineCount();
|
|
1845
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
1846
|
-
const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
1847
|
-
const isReadOnly = this.editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
1848
|
-
if (isReadOnly) model.applyEdits([{
|
|
1849
|
-
range,
|
|
1850
|
-
text,
|
|
1851
|
-
forceMoveMarkers: true
|
|
1852
|
-
}]);
|
|
1853
|
-
else this.editorView.executeEdits("append", [{
|
|
1854
|
-
range,
|
|
1855
|
-
text,
|
|
1856
|
-
forceMoveMarkers: true
|
|
1857
|
-
}]);
|
|
1858
|
-
try {
|
|
1859
|
-
this.lastKnownCode = model.getValue();
|
|
1860
|
-
} catch {}
|
|
1861
|
-
const newLineCount = model.getLineCount();
|
|
1862
|
-
if (lastLine !== newLineCount) {
|
|
1863
|
-
this.cachedLineCount = newLineCount;
|
|
1864
|
-
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1865
|
-
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1866
|
-
const computed$2 = this.computedHeight(this.editorView);
|
|
1867
|
-
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1868
|
-
if (shouldImmediate) try {
|
|
1869
|
-
this.forceReveal(newLineCount);
|
|
1870
|
-
} catch {}
|
|
1871
|
-
else this.maybeScrollToBottom(newLineCount);
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
setLanguage(language, languages$1) {
|
|
1875
|
-
if (languages$1.includes(language)) {
|
|
1876
|
-
if (this.editorView) {
|
|
1877
|
-
const model = this.editorView.getModel();
|
|
1878
|
-
if (model && model.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(model, language);
|
|
1879
|
-
}
|
|
1880
|
-
} else console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
|
|
1881
|
-
}
|
|
1882
|
-
getEditorView() {
|
|
1883
|
-
return this.editorView;
|
|
1884
|
-
}
|
|
1885
|
-
cleanup() {
|
|
1886
|
-
this.rafScheduler.cancel("update");
|
|
1887
|
-
this.rafScheduler.cancel("sync-last-known");
|
|
1888
|
-
this.rafScheduler.cancel("content-size-change");
|
|
1889
|
-
this.rafScheduler.cancel("maybe-scroll");
|
|
1890
|
-
this.rafScheduler.cancel("reveal");
|
|
1891
|
-
this.rafScheduler.cancel("immediate-reveal");
|
|
1892
|
-
this.rafScheduler.cancel("maybe-resume");
|
|
1893
|
-
this.pendingUpdate = null;
|
|
1894
|
-
this.rafScheduler.cancel("append");
|
|
1895
|
-
this.appendBufferScheduled = false;
|
|
1896
|
-
this.appendBuffer.length = 0;
|
|
1897
|
-
if (this.revealDebounceId != null) {
|
|
1898
|
-
clearTimeout(this.revealDebounceId);
|
|
1899
|
-
this.revealDebounceId = null;
|
|
1900
|
-
}
|
|
1901
|
-
if (this.revealIdleTimerId != null) {
|
|
1902
|
-
clearTimeout(this.revealIdleTimerId);
|
|
1903
|
-
this.revealIdleTimerId = null;
|
|
1904
|
-
}
|
|
1905
|
-
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1906
|
-
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1907
|
-
this.scrollWatcherSuppressionTimer = null;
|
|
1908
|
-
}
|
|
1909
|
-
if (this.editorView) {
|
|
1910
|
-
this.editorView.dispose();
|
|
1911
|
-
this.editorView = null;
|
|
1912
|
-
}
|
|
1913
|
-
this.lastKnownCode = null;
|
|
1914
|
-
if (this.lastContainer) {
|
|
1915
|
-
this.lastContainer.style.minHeight = "";
|
|
1916
|
-
this.lastContainer.innerHTML = "";
|
|
1917
|
-
this.lastContainer = null;
|
|
1918
|
-
}
|
|
1919
|
-
if (this.scrollWatcher) {
|
|
1920
|
-
this.scrollWatcher.dispose();
|
|
1921
|
-
this.scrollWatcher = null;
|
|
1922
|
-
}
|
|
1923
|
-
if (this.editorHeightManager) {
|
|
1924
|
-
this.editorHeightManager.dispose();
|
|
1925
|
-
this.editorHeightManager = null;
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
safeClean() {
|
|
1929
|
-
this.rafScheduler.cancel("update");
|
|
1930
|
-
this.pendingUpdate = null;
|
|
1931
|
-
this.rafScheduler.cancel("sync-last-known");
|
|
1932
|
-
if (this.scrollWatcher) {
|
|
1933
|
-
try {
|
|
1934
|
-
this.scrollWatcher.dispose();
|
|
1935
|
-
} catch {}
|
|
1936
|
-
this.scrollWatcher = null;
|
|
1937
|
-
}
|
|
1938
|
-
if (this.revealDebounceId != null) {
|
|
1939
|
-
clearTimeout(this.revealDebounceId);
|
|
1940
|
-
this.revealDebounceId = null;
|
|
1941
|
-
}
|
|
1942
|
-
if (this.revealIdleTimerId != null) {
|
|
1943
|
-
clearTimeout(this.revealIdleTimerId);
|
|
1944
|
-
this.revealIdleTimerId = null;
|
|
1945
|
-
}
|
|
1946
|
-
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1947
|
-
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1948
|
-
this.scrollWatcherSuppressionTimer = null;
|
|
1949
|
-
}
|
|
1950
|
-
this.rafScheduler.cancel("maybe-scroll");
|
|
1951
|
-
this.rafScheduler.cancel("reveal");
|
|
1952
|
-
this.rafScheduler.cancel("immediate-reveal");
|
|
1953
|
-
this.rafScheduler.cancel("maybe-resume");
|
|
1954
|
-
this._hasScrollBar = false;
|
|
1955
|
-
this.shouldAutoScroll = !!this.autoScrollInitial;
|
|
1956
|
-
this.lastScrollTop = 0;
|
|
1957
|
-
if (this.editorHeightManager) {
|
|
1958
|
-
this.editorHeightManager.dispose();
|
|
1959
|
-
this.editorHeightManager = null;
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
};
|
|
1963
|
-
|
|
1964
|
-
//#endregion
|
|
1965
|
-
//#region src/preloadMonacoWorkers.ts
|
|
1966
|
-
async function preloadMonacoWorkers() {
|
|
3
|
+
//#region src/ensureMonacoWorkers.ts
|
|
4
|
+
function ensureMonacoWorkers() {
|
|
1967
5
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
1968
|
-
const workerUrlJson = new URL("monaco-editor/esm/vs/language/json/json.worker.js", import.meta.url);
|
|
1969
|
-
const workerUrlCss = new URL("monaco-editor/esm/vs/language/css/css.worker.js", import.meta.url);
|
|
1970
|
-
const workerUrlHtml = new URL("monaco-editor/esm/vs/language/html/html.worker.js", import.meta.url);
|
|
1971
|
-
const workerUrlTs = new URL("monaco-editor/esm/vs/language/typescript/ts.worker.js", import.meta.url);
|
|
1972
|
-
const workerUrlEditor = new URL("monaco-editor/esm/vs/editor/editor.worker.js", import.meta.url);
|
|
1973
|
-
const unique = Array.from(new Set([
|
|
1974
|
-
String(workerUrlJson),
|
|
1975
|
-
String(workerUrlCss),
|
|
1976
|
-
String(workerUrlHtml),
|
|
1977
|
-
String(workerUrlTs),
|
|
1978
|
-
String(workerUrlEditor)
|
|
1979
|
-
]));
|
|
1980
|
-
const workerUrlByLabel = {
|
|
1981
|
-
json: workerUrlJson,
|
|
1982
|
-
css: workerUrlCss,
|
|
1983
|
-
scss: workerUrlCss,
|
|
1984
|
-
less: workerUrlCss,
|
|
1985
|
-
html: workerUrlHtml,
|
|
1986
|
-
handlebars: workerUrlHtml,
|
|
1987
|
-
razor: workerUrlHtml,
|
|
1988
|
-
typescript: workerUrlTs,
|
|
1989
|
-
javascript: workerUrlTs
|
|
1990
|
-
};
|
|
1991
6
|
try {
|
|
7
|
+
const existing = self.MonacoEnvironment;
|
|
8
|
+
if ((existing === null || existing === void 0 ? void 0 : existing.getWorker) || (existing === null || existing === void 0 ? void 0 : existing.getWorkerUrl)) return;
|
|
9
|
+
const workerUrlByLabel = Object.fromEntries(Object.entries(workerPathByLabel).map(([label, path]) => [label, new URL(path, import.meta.url)]));
|
|
10
|
+
const workerUrlEditor = new URL(editorWorkerPath, import.meta.url);
|
|
1992
11
|
self.MonacoEnvironment = { getWorker(_, label) {
|
|
1993
12
|
const url = workerUrlByLabel[label] ?? workerUrlEditor;
|
|
1994
13
|
return new Worker(url, { type: "module" });
|
|
1995
14
|
} };
|
|
1996
15
|
} catch {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/preloadMonacoWorkers.ts
|
|
20
|
+
async function preloadMonacoWorkers() {
|
|
21
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
22
|
+
const unique = uniqueWorkerPaths.map((p) => String(new URL(p, import.meta.url)));
|
|
23
|
+
ensureMonacoWorkers();
|
|
1997
24
|
try {
|
|
1998
25
|
await Promise.all(unique.map((u) => fetch(u, {
|
|
1999
26
|
method: "GET",
|
|
@@ -2002,815 +29,9 @@ async function preloadMonacoWorkers() {
|
|
|
2002
29
|
} catch {}
|
|
2003
30
|
}
|
|
2004
31
|
|
|
2005
|
-
//#endregion
|
|
2006
|
-
//#region src/reactivity.ts
|
|
2007
|
-
function computed$1(getter) {
|
|
2008
|
-
const c = computed(() => getter());
|
|
2009
|
-
return Object.defineProperty({}, "value", {
|
|
2010
|
-
get() {
|
|
2011
|
-
return c();
|
|
2012
|
-
},
|
|
2013
|
-
set(_) {},
|
|
2014
|
-
enumerable: true,
|
|
2015
|
-
configurable: false
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
//#endregion
|
|
2020
|
-
//#region src/utils/arraysEqual.ts
|
|
2021
|
-
function arraysEqual(a, b) {
|
|
2022
|
-
if (a === b) return true;
|
|
2023
|
-
if (!a || !b) return false;
|
|
2024
|
-
if (a.length !== b.length) return false;
|
|
2025
|
-
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
2026
|
-
return true;
|
|
2027
|
-
}
|
|
2028
|
-
|
|
2029
|
-
//#endregion
|
|
2030
|
-
//#region src/utils/registerMonacoThemes.ts
|
|
2031
|
-
let languagesRegistered = false;
|
|
2032
|
-
let currentLanguages = [];
|
|
2033
|
-
let themeRegisterPromise = null;
|
|
2034
|
-
let registrationQueue = Promise.resolve();
|
|
2035
|
-
function enqueueRegistration(task) {
|
|
2036
|
-
const next = registrationQueue.then(task, task);
|
|
2037
|
-
registrationQueue = next.then(() => void 0, () => void 0);
|
|
2038
|
-
return next;
|
|
2039
|
-
}
|
|
2040
|
-
function setThemeRegisterPromise(p) {
|
|
2041
|
-
return themeRegisterPromise = p;
|
|
2042
|
-
}
|
|
2043
|
-
const highlighterCache = /* @__PURE__ */ new Map();
|
|
2044
|
-
let monacoHighlighterPromise = null;
|
|
2045
|
-
let lastPatchedHighlighter = null;
|
|
2046
|
-
const monacoThemeByKey = /* @__PURE__ */ new Map();
|
|
2047
|
-
const monacoLanguageSet = /* @__PURE__ */ new Set();
|
|
2048
|
-
function themeKey(t) {
|
|
2049
|
-
return typeof t === "string" ? t : t.name ?? JSON.stringify(t);
|
|
2050
|
-
}
|
|
2051
|
-
async function ensureMonacoHighlighter(themes, languages$1) {
|
|
2052
|
-
for (const t of themes) monacoThemeByKey.set(themeKey(t), t);
|
|
2053
|
-
for (const l of languages$1) monacoLanguageSet.add(l);
|
|
2054
|
-
if (!monacoHighlighterPromise) {
|
|
2055
|
-
const initialThemes = Array.from(monacoThemeByKey.values());
|
|
2056
|
-
const initialLangs = Array.from(monacoLanguageSet.values());
|
|
2057
|
-
monacoHighlighterPromise = createHighlighter({
|
|
2058
|
-
themes: initialThemes,
|
|
2059
|
-
langs: initialLangs
|
|
2060
|
-
}).then((h$1) => h$1);
|
|
2061
|
-
}
|
|
2062
|
-
const h = await monacoHighlighterPromise;
|
|
2063
|
-
const wantsThemes = Array.from(monacoThemeByKey.values());
|
|
2064
|
-
const wantsLangs = Array.from(monacoLanguageSet.values());
|
|
2065
|
-
const canLoadTheme = typeof h.loadTheme === "function";
|
|
2066
|
-
const canLoadLanguage = typeof h.loadLanguage === "function";
|
|
2067
|
-
if (canLoadTheme || canLoadLanguage) {
|
|
2068
|
-
if (canLoadTheme) for (const t of themes) {
|
|
2069
|
-
const k = themeKey(t);
|
|
2070
|
-
if (!h.__streamMonacoLoadedThemes) h.__streamMonacoLoadedThemes = /* @__PURE__ */ new Set();
|
|
2071
|
-
const loaded = h.__streamMonacoLoadedThemes;
|
|
2072
|
-
if (loaded.has(k)) continue;
|
|
2073
|
-
await h.loadTheme(t);
|
|
2074
|
-
loaded.add(k);
|
|
2075
|
-
}
|
|
2076
|
-
if (canLoadLanguage) for (const l of languages$1) {
|
|
2077
|
-
if (!h.__streamMonacoLoadedLangs) h.__streamMonacoLoadedLangs = /* @__PURE__ */ new Set();
|
|
2078
|
-
const loaded = h.__streamMonacoLoadedLangs;
|
|
2079
|
-
if (loaded.has(l)) continue;
|
|
2080
|
-
await h.loadLanguage(l);
|
|
2081
|
-
loaded.add(l);
|
|
2082
|
-
}
|
|
2083
|
-
return h;
|
|
2084
|
-
}
|
|
2085
|
-
const p = createHighlighter({
|
|
2086
|
-
themes: wantsThemes,
|
|
2087
|
-
langs: wantsLangs
|
|
2088
|
-
}).then((hh) => hh);
|
|
2089
|
-
monacoHighlighterPromise = p;
|
|
2090
|
-
return p;
|
|
2091
|
-
}
|
|
2092
|
-
/**
|
|
2093
|
-
* Clear all cached shiki highlighters.
|
|
2094
|
-
*
|
|
2095
|
-
* Useful for long-running apps that dynamically create many theme combinations,
|
|
2096
|
-
* or in tests to ensure a clean state. Call this when you know the highlighters
|
|
2097
|
-
* are no longer needed (for example on app shutdown) to free memory.
|
|
2098
|
-
*/
|
|
2099
|
-
function clearHighlighterCache() {
|
|
2100
|
-
highlighterCache.clear();
|
|
2101
|
-
}
|
|
2102
|
-
function serializeThemes(themes) {
|
|
2103
|
-
return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
|
|
2104
|
-
}
|
|
2105
|
-
async function getOrCreateHighlighter(themes, languages$1) {
|
|
2106
|
-
const key = serializeThemes(themes);
|
|
2107
|
-
const requestedSet = new Set(languages$1);
|
|
2108
|
-
let existing = highlighterCache.get(key);
|
|
2109
|
-
if (existing) {
|
|
2110
|
-
let allIncluded = true;
|
|
2111
|
-
for (const l of requestedSet) if (!existing.languages.has(l)) {
|
|
2112
|
-
allIncluded = false;
|
|
2113
|
-
break;
|
|
2114
|
-
}
|
|
2115
|
-
if (allIncluded) return existing.promise;
|
|
2116
|
-
const prev = existing;
|
|
2117
|
-
const current = highlighterCache.get(key);
|
|
2118
|
-
if (current && current !== prev) {
|
|
2119
|
-
let allIncludedCurrent = true;
|
|
2120
|
-
for (const l of requestedSet) if (!current.languages.has(l)) {
|
|
2121
|
-
allIncludedCurrent = false;
|
|
2122
|
-
break;
|
|
2123
|
-
}
|
|
2124
|
-
if (allIncludedCurrent) return current.promise;
|
|
2125
|
-
existing = current;
|
|
2126
|
-
}
|
|
2127
|
-
const union = new Set([...existing.languages, ...requestedSet]);
|
|
2128
|
-
const langsArray = Array.from(union);
|
|
2129
|
-
const p$1 = createHighlighter({
|
|
2130
|
-
themes,
|
|
2131
|
-
langs: langsArray
|
|
2132
|
-
});
|
|
2133
|
-
const newEntry = {
|
|
2134
|
-
promise: p$1,
|
|
2135
|
-
languages: union
|
|
2136
|
-
};
|
|
2137
|
-
highlighterCache.set(key, newEntry);
|
|
2138
|
-
p$1.catch(() => {
|
|
2139
|
-
if (highlighterCache.get(key) === newEntry && prev) highlighterCache.set(key, prev);
|
|
2140
|
-
});
|
|
2141
|
-
return p$1;
|
|
2142
|
-
}
|
|
2143
|
-
const p = createHighlighter({
|
|
2144
|
-
themes,
|
|
2145
|
-
langs: Array.from(requestedSet)
|
|
2146
|
-
});
|
|
2147
|
-
const entry = {
|
|
2148
|
-
promise: p,
|
|
2149
|
-
languages: requestedSet
|
|
2150
|
-
};
|
|
2151
|
-
highlighterCache.set(key, entry);
|
|
2152
|
-
p.catch(() => {
|
|
2153
|
-
if (highlighterCache.get(key) === entry) highlighterCache.delete(key);
|
|
2154
|
-
});
|
|
2155
|
-
return p;
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Update the theme used by the shiki highlighter for a given themes+languages
|
|
2159
|
-
* combination. Useful when Monaco themes are already registered (so switching
|
|
2160
|
-
* Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
|
|
2161
|
-
* standalone renderer to use the new theme without recreating everything.
|
|
2162
|
-
*/
|
|
2163
|
-
async function registerMonacoThemes(themes, languages$1) {
|
|
2164
|
-
return enqueueRegistration(async () => {
|
|
2165
|
-
registerMonacoLanguages(languages$1);
|
|
2166
|
-
const p = (async () => {
|
|
2167
|
-
const highlighter = await ensureMonacoHighlighter(themes, languages$1);
|
|
2168
|
-
if (lastPatchedHighlighter !== highlighter) {
|
|
2169
|
-
shikiToMonaco(highlighter, monaco_shim_exports);
|
|
2170
|
-
lastPatchedHighlighter = highlighter;
|
|
2171
|
-
}
|
|
2172
|
-
currentLanguages = languages$1.slice();
|
|
2173
|
-
return highlighter;
|
|
2174
|
-
})();
|
|
2175
|
-
setThemeRegisterPromise(p);
|
|
2176
|
-
try {
|
|
2177
|
-
const res = await p;
|
|
2178
|
-
return res;
|
|
2179
|
-
} catch (e) {
|
|
2180
|
-
setThemeRegisterPromise(null);
|
|
2181
|
-
throw e;
|
|
2182
|
-
}
|
|
2183
|
-
});
|
|
2184
|
-
}
|
|
2185
|
-
function registerMonacoLanguages(languages$1) {
|
|
2186
|
-
if (languagesRegistered && arraysEqual(languages$1, currentLanguages)) return;
|
|
2187
|
-
const existing = new Set(monaco_shim_exports.languages.getLanguages().map((l) => l.id));
|
|
2188
|
-
for (const lang of languages$1) if (!existing.has(lang)) try {
|
|
2189
|
-
monaco_shim_exports.languages.register({ id: lang });
|
|
2190
|
-
} catch {}
|
|
2191
|
-
languagesRegistered = true;
|
|
2192
|
-
currentLanguages = languages$1;
|
|
2193
|
-
}
|
|
2194
|
-
|
|
2195
|
-
//#endregion
|
|
2196
|
-
//#region src/type.ts
|
|
2197
|
-
let RevealStrategy = /* @__PURE__ */ function(RevealStrategy$1) {
|
|
2198
|
-
RevealStrategy$1["Bottom"] = "bottom";
|
|
2199
|
-
RevealStrategy$1["CenterIfOutside"] = "centerIfOutside";
|
|
2200
|
-
RevealStrategy$1["Center"] = "center";
|
|
2201
|
-
return RevealStrategy$1;
|
|
2202
|
-
}({});
|
|
2203
|
-
|
|
2204
32
|
//#endregion
|
|
2205
33
|
//#region src/index.ts
|
|
2206
|
-
|
|
2207
|
-
let globalThemeRequestSeq = 0;
|
|
2208
|
-
let globalAppliedThemeName = null;
|
|
2209
|
-
/**
|
|
2210
|
-
* useMonaco 组合式函数
|
|
2211
|
-
*
|
|
2212
|
-
* 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
|
|
2213
|
-
* 支持主题自动切换、语言高亮、代码更新等功能。
|
|
2214
|
-
*
|
|
2215
|
-
* @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
|
|
2216
|
-
* @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
|
|
2217
|
-
* @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
|
|
2218
|
-
* @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
|
|
2219
|
-
* @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
|
|
2220
|
-
* @param {string} [monacoOptions.theme] - 初始主题名称
|
|
2221
|
-
* @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
|
|
2222
|
-
* @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
|
|
2223
|
-
*
|
|
2224
|
-
* @returns {{
|
|
2225
|
-
* createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
|
|
2226
|
-
* createDiffEditor: (
|
|
2227
|
-
* container: HTMLElement,
|
|
2228
|
-
* originalCode: string,
|
|
2229
|
-
* modifiedCode: string,
|
|
2230
|
-
* language: string,
|
|
2231
|
-
* ) => Promise<monaco.editor.IStandaloneDiffEditor>,
|
|
2232
|
-
* cleanupEditor: () => void,
|
|
2233
|
-
* updateCode: (newCode: string, codeLanguage: string) => void,
|
|
2234
|
-
* appendCode: (appendText: string, codeLanguage?: string) => void,
|
|
2235
|
-
* updateDiff: (
|
|
2236
|
-
* originalCode: string,
|
|
2237
|
-
* modifiedCode: string,
|
|
2238
|
-
* codeLanguage?: string,
|
|
2239
|
-
* ) => void,
|
|
2240
|
-
* updateOriginal: (newCode: string, codeLanguage?: string) => void,
|
|
2241
|
-
* updateModified: (newCode: string, codeLanguage?: string) => void,
|
|
2242
|
-
* appendOriginal: (appendText: string, codeLanguage?: string) => void,
|
|
2243
|
-
* appendModified: (appendText: string, codeLanguage?: string) => void,
|
|
2244
|
-
* setTheme: (theme: MonacoTheme) => Promise<void>,
|
|
2245
|
-
* setLanguage: (language: MonacoLanguage) => void,
|
|
2246
|
-
* getCurrentTheme: () => string,
|
|
2247
|
-
* getEditor: () => typeof monaco.editor,
|
|
2248
|
-
* getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
|
|
2249
|
-
* getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
|
|
2250
|
-
* getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
|
|
2251
|
-
* getCode: () => string | { original: string, modified: string } | null,
|
|
2252
|
-
* }} 返回对象包含以下方法和属性:
|
|
2253
|
-
*
|
|
2254
|
-
* @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
|
|
2255
|
-
* @property {Function} cleanupEditor - 销毁编辑器并清理容器
|
|
2256
|
-
* @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
|
|
2257
|
-
* @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
|
|
2258
|
-
* @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
|
|
2259
|
-
* @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
|
|
2260
|
-
* @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
|
|
2261
|
-
* @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
|
|
2262
|
-
* @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
|
|
2263
|
-
* @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
|
|
2264
|
-
* @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
|
|
2265
|
-
* @property {Function} setLanguage - 切换编辑器语言
|
|
2266
|
-
* @property {Function} getCurrentTheme - 获取当前主题名称
|
|
2267
|
-
* @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
|
|
2268
|
-
* @property {Function} getEditorView - 获取当前编辑器实例
|
|
2269
|
-
* @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
|
|
2270
|
-
* @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
|
|
2271
|
-
* @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
|
|
2272
|
-
*
|
|
2273
|
-
* @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
|
|
2274
|
-
*
|
|
2275
|
-
* @example
|
|
2276
|
-
* ```typescript
|
|
2277
|
-
* import { useMonaco } from 'stream-monaco'
|
|
2278
|
-
*
|
|
2279
|
-
* const { createEditor, updateCode, setTheme } = useMonaco({
|
|
2280
|
-
* themes: ['vitesse-dark', 'vitesse-light'],
|
|
2281
|
-
* languages: ['javascript', 'typescript'],
|
|
2282
|
-
* readOnly: false
|
|
2283
|
-
* })
|
|
2284
|
-
*
|
|
2285
|
-
* // 创建编辑器
|
|
2286
|
-
* const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
|
|
2287
|
-
*
|
|
2288
|
-
* // 更新代码
|
|
2289
|
-
* updateCode('console.log("world")', 'javascript')
|
|
2290
|
-
*
|
|
2291
|
-
* // 切换主题
|
|
2292
|
-
* setTheme('vitesse-light')
|
|
2293
|
-
* ```
|
|
2294
|
-
*/
|
|
2295
|
-
function useMonaco(monacoOptions = {}) {
|
|
2296
|
-
var _monacoOptions$themes;
|
|
2297
|
-
const disposals = [];
|
|
2298
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.forEach((d) => d.dispose());
|
|
2299
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
|
|
2300
|
-
let editorView = null;
|
|
2301
|
-
let editorMgr = null;
|
|
2302
|
-
let diffEditorView = null;
|
|
2303
|
-
let diffMgr = null;
|
|
2304
|
-
let originalModel = null;
|
|
2305
|
-
let modifiedModel = null;
|
|
2306
|
-
let _hasScrollBar = false;
|
|
2307
|
-
const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
|
|
2308
|
-
if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
|
|
2309
|
-
const languages$1 = monacoOptions.languages ?? defaultLanguages;
|
|
2310
|
-
const MAX_HEIGHT = monacoOptions.MAX_HEIGHT ?? 500;
|
|
2311
|
-
const autoScrollOnUpdate = monacoOptions.autoScrollOnUpdate ?? true;
|
|
2312
|
-
const autoScrollInitial = monacoOptions.autoScrollInitial ?? true;
|
|
2313
|
-
const autoScrollThresholdPx = monacoOptions.autoScrollThresholdPx ?? 32;
|
|
2314
|
-
const autoScrollThresholdLines = monacoOptions.autoScrollThresholdLines ?? 2;
|
|
2315
|
-
const diffAutoScroll = monacoOptions.diffAutoScroll ?? true;
|
|
2316
|
-
const getMaxHeightValue = () => {
|
|
2317
|
-
if (typeof MAX_HEIGHT === "number") return MAX_HEIGHT;
|
|
2318
|
-
const match = MAX_HEIGHT.match(/^(\d+(?:\.\d+)?)/);
|
|
2319
|
-
return match ? Number.parseFloat(match[1]) : 500;
|
|
2320
|
-
};
|
|
2321
|
-
const getMaxHeightCSS = () => {
|
|
2322
|
-
if (typeof MAX_HEIGHT === "number") return `${MAX_HEIGHT}px`;
|
|
2323
|
-
return MAX_HEIGHT;
|
|
2324
|
-
};
|
|
2325
|
-
const maxHeightValue = getMaxHeightValue();
|
|
2326
|
-
const maxHeightCSS = getMaxHeightCSS();
|
|
2327
|
-
let lastContainer = null;
|
|
2328
|
-
let lastKnownCode = null;
|
|
2329
|
-
const minimalEditMaxCharsLocal = monacoOptions.minimalEditMaxChars ?? minimalEditMaxChars;
|
|
2330
|
-
const minimalEditMaxChangeRatioLocal = monacoOptions.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
|
|
2331
|
-
let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
|
|
2332
|
-
let lastFlushTime = 0;
|
|
2333
|
-
let updateThrottleTimer = null;
|
|
2334
|
-
let pendingUpdate = null;
|
|
2335
|
-
let shouldAutoScroll = true;
|
|
2336
|
-
const cachedComputedHeight = null;
|
|
2337
|
-
const appendBuffer = [];
|
|
2338
|
-
let appendBufferScheduled = false;
|
|
2339
|
-
const currentTheme = computed$1(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
|
|
2340
|
-
let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
|
|
2341
|
-
let themeWatcher = null;
|
|
2342
|
-
const rafScheduler = createRafScheduler();
|
|
2343
|
-
async function tryLoadAndSetShikiTheme(highlighter, themeName) {
|
|
2344
|
-
if (!highlighter || typeof highlighter.setTheme !== "function") return;
|
|
2345
|
-
try {
|
|
2346
|
-
await highlighter.setTheme(themeName);
|
|
2347
|
-
} catch (err) {
|
|
2348
|
-
const message = (err === null || err === void 0 ? void 0 : err.message) ? String(err.message) : String(err);
|
|
2349
|
-
const lower = message.toLowerCase();
|
|
2350
|
-
const looksLikeMissingThemeError = lower.includes("theme") && lower.includes("not found");
|
|
2351
|
-
if (typeof highlighter.loadTheme === "function" && looksLikeMissingThemeError) {
|
|
2352
|
-
await highlighter.loadTheme(themeName);
|
|
2353
|
-
await highlighter.setTheme(themeName);
|
|
2354
|
-
return;
|
|
2355
|
-
}
|
|
2356
|
-
throw err;
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
async function setThemeInternal(theme, force = false) {
|
|
2360
|
-
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
2361
|
-
globalThemeRequestSeq += 1;
|
|
2362
|
-
const token = globalThemeRequestSeq;
|
|
2363
|
-
requestedThemeName = themeName;
|
|
2364
|
-
globalRequestedThemeName = themeName;
|
|
2365
|
-
if (!force && themeName === globalAppliedThemeName) return;
|
|
2366
|
-
if (token !== globalThemeRequestSeq) return;
|
|
2367
|
-
await registerMonacoThemes(themes, languages$1).catch(() => void 0);
|
|
2368
|
-
if (token !== globalThemeRequestSeq) return;
|
|
2369
|
-
const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
|
|
2370
|
-
if (!availableNames.includes(themeName)) try {
|
|
2371
|
-
const extended = availableNames.concat(themeName);
|
|
2372
|
-
const maybeHighlighter = await registerMonacoThemes(extended, languages$1);
|
|
2373
|
-
await tryLoadAndSetShikiTheme(maybeHighlighter, themeName).catch(() => void 0);
|
|
2374
|
-
} catch {
|
|
2375
|
-
console.warn(`Theme "${themeName}" is not registered and automatic registration failed. Available themes: ${availableNames.join(", ")}`);
|
|
2376
|
-
return;
|
|
2377
|
-
}
|
|
2378
|
-
if (token !== globalThemeRequestSeq) return;
|
|
2379
|
-
try {
|
|
2380
|
-
monaco_shim_exports.editor.setTheme(themeName);
|
|
2381
|
-
globalAppliedThemeName = themeName;
|
|
2382
|
-
} catch {
|
|
2383
|
-
try {
|
|
2384
|
-
const maybeHighlighter = await registerMonacoThemes(themes, languages$1);
|
|
2385
|
-
if (token !== globalThemeRequestSeq) return;
|
|
2386
|
-
monaco_shim_exports.editor.setTheme(themeName);
|
|
2387
|
-
globalAppliedThemeName = themeName;
|
|
2388
|
-
await tryLoadAndSetShikiTheme(maybeHighlighter, themeName).catch(() => void 0);
|
|
2389
|
-
} catch (err2) {
|
|
2390
|
-
console.warn(`Failed to set theme "${themeName}":`, err2);
|
|
2391
|
-
return;
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
if (token !== globalThemeRequestSeq) return;
|
|
2395
|
-
try {
|
|
2396
|
-
if (typeof monacoOptions.onThemeChange === "function") await monacoOptions.onThemeChange(themeName);
|
|
2397
|
-
} catch (err) {
|
|
2398
|
-
console.warn("onThemeChange callback threw an error:", err);
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
async function ensureThemeRegistered(themeName) {
|
|
2402
|
-
const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
|
|
2403
|
-
const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
|
|
2404
|
-
await registerMonacoThemes(list, languages$1);
|
|
2405
|
-
}
|
|
2406
|
-
function hasVerticalScrollbar() {
|
|
2407
|
-
if (!editorView) return false;
|
|
2408
|
-
if (_hasScrollBar) return true;
|
|
2409
|
-
const ch = cachedComputedHeight ?? computedHeight(editorView);
|
|
2410
|
-
return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
|
|
2411
|
-
}
|
|
2412
|
-
let revealDebounceId = null;
|
|
2413
|
-
const revealDebounceMs = 75;
|
|
2414
|
-
function maybeScrollToBottom(targetLine) {
|
|
2415
|
-
if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
|
|
2416
|
-
const model = editorView.getModel();
|
|
2417
|
-
const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
2418
|
-
if (revealDebounceId != null) {
|
|
2419
|
-
clearTimeout(revealDebounceId);
|
|
2420
|
-
revealDebounceId = null;
|
|
2421
|
-
}
|
|
2422
|
-
revealDebounceId = setTimeout(() => {
|
|
2423
|
-
revealDebounceId = null;
|
|
2424
|
-
rafScheduler.schedule("reveal", () => {
|
|
2425
|
-
try {
|
|
2426
|
-
var _editor;
|
|
2427
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
2428
|
-
if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
|
|
2429
|
-
else editorView.revealLineInCenterIfOutsideViewport(line);
|
|
2430
|
-
} catch {}
|
|
2431
|
-
});
|
|
2432
|
-
}, revealDebounceMs);
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
async function createEditor(container, code, language) {
|
|
2436
|
-
cleanupEditor();
|
|
2437
|
-
lastContainer = container;
|
|
2438
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) {
|
|
2439
|
-
disposals.forEach((d) => d.dispose());
|
|
2440
|
-
disposals.length = 0;
|
|
2441
|
-
}
|
|
2442
|
-
if (monacoOptions.onBeforeCreate) {
|
|
2443
|
-
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2444
|
-
if (ds) disposals.push(...ds);
|
|
2445
|
-
}
|
|
2446
|
-
const initialThemeName = requestedThemeName ?? monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
|
|
2447
|
-
await ensureThemeRegistered(initialThemeName);
|
|
2448
|
-
editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs);
|
|
2449
|
-
editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
|
|
2450
|
-
if (pendingUpdate && editorMgr) {
|
|
2451
|
-
const { code: queuedCode, lang: queuedLang } = pendingUpdate;
|
|
2452
|
-
pendingUpdate = null;
|
|
2453
|
-
editorMgr.updateCode(queuedCode, queuedLang);
|
|
2454
|
-
}
|
|
2455
|
-
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
2456
|
-
if (editorView) lastKnownCode = editorView.getValue();
|
|
2457
|
-
return editorView;
|
|
2458
|
-
}
|
|
2459
|
-
function computedHeight(editorView$1) {
|
|
2460
|
-
var _getModel;
|
|
2461
|
-
const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
|
|
2462
|
-
const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
2463
|
-
const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
|
|
2464
|
-
return height;
|
|
2465
|
-
}
|
|
2466
|
-
async function createDiffEditor(container, originalCode, modifiedCode, language) {
|
|
2467
|
-
cleanupEditor();
|
|
2468
|
-
lastContainer = container;
|
|
2469
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) {
|
|
2470
|
-
disposals.forEach((d) => d.dispose());
|
|
2471
|
-
disposals.length = 0;
|
|
2472
|
-
}
|
|
2473
|
-
if (monacoOptions.onBeforeCreate) {
|
|
2474
|
-
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2475
|
-
if (ds) disposals.push(...ds);
|
|
2476
|
-
}
|
|
2477
|
-
const initialThemeName = requestedThemeName ?? monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
|
|
2478
|
-
await ensureThemeRegistered(initialThemeName);
|
|
2479
|
-
try {
|
|
2480
|
-
monaco_shim_exports.editor.setTheme(initialThemeName);
|
|
2481
|
-
} catch {}
|
|
2482
|
-
diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
|
|
2483
|
-
diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
|
|
2484
|
-
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
2485
|
-
const models = diffMgr.getDiffModels();
|
|
2486
|
-
originalModel = models.original;
|
|
2487
|
-
modifiedModel = models.modified;
|
|
2488
|
-
return diffEditorView;
|
|
2489
|
-
}
|
|
2490
|
-
function cleanupEditor() {
|
|
2491
|
-
if (editorMgr) {
|
|
2492
|
-
editorMgr.cleanup();
|
|
2493
|
-
editorMgr = null;
|
|
2494
|
-
}
|
|
2495
|
-
if (diffMgr) {
|
|
2496
|
-
diffMgr.cleanup();
|
|
2497
|
-
diffMgr = null;
|
|
2498
|
-
}
|
|
2499
|
-
rafScheduler.cancel("update");
|
|
2500
|
-
pendingUpdate = null;
|
|
2501
|
-
rafScheduler.cancel("append");
|
|
2502
|
-
appendBufferScheduled = false;
|
|
2503
|
-
appendBuffer.length = 0;
|
|
2504
|
-
if (!editorMgr && editorView) {
|
|
2505
|
-
editorView.dispose();
|
|
2506
|
-
editorView = null;
|
|
2507
|
-
}
|
|
2508
|
-
lastKnownCode = null;
|
|
2509
|
-
if (lastContainer) {
|
|
2510
|
-
lastContainer.innerHTML = "";
|
|
2511
|
-
lastContainer = null;
|
|
2512
|
-
}
|
|
2513
|
-
if (themeWatcher) {
|
|
2514
|
-
themeWatcher();
|
|
2515
|
-
themeWatcher = null;
|
|
2516
|
-
}
|
|
2517
|
-
if (updateThrottleTimer != null) {
|
|
2518
|
-
clearTimeout(updateThrottleTimer);
|
|
2519
|
-
updateThrottleTimer = null;
|
|
2520
|
-
}
|
|
2521
|
-
diffEditorView = null;
|
|
2522
|
-
originalModel = null;
|
|
2523
|
-
modifiedModel = null;
|
|
2524
|
-
}
|
|
2525
|
-
function appendCode(appendText, codeLanguage) {
|
|
2526
|
-
if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
|
|
2527
|
-
else {
|
|
2528
|
-
if (!editorView) return;
|
|
2529
|
-
const model = editorView.getModel();
|
|
2530
|
-
if (!model) return;
|
|
2531
|
-
const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
|
|
2532
|
-
if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
|
|
2533
|
-
if (appendText && lastKnownCode != null) lastKnownCode = lastKnownCode + appendText;
|
|
2534
|
-
if (appendText) {
|
|
2535
|
-
appendBuffer.push(appendText);
|
|
2536
|
-
if (!appendBufferScheduled) {
|
|
2537
|
-
appendBufferScheduled = true;
|
|
2538
|
-
rafScheduler.schedule("append", flushAppendBuffer);
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
function applyMinimalEdit(prev, next) {
|
|
2544
|
-
if (!editorView) return;
|
|
2545
|
-
const model = editorView.getModel();
|
|
2546
|
-
if (!model) return;
|
|
2547
|
-
try {
|
|
2548
|
-
const maxChars = minimalEditMaxCharsLocal;
|
|
2549
|
-
const ratio = minimalEditMaxChangeRatioLocal;
|
|
2550
|
-
const maxLen = Math.max(prev.length, next.length);
|
|
2551
|
-
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
2552
|
-
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
2553
|
-
const prevLineCount = model.getLineCount();
|
|
2554
|
-
model.setValue(next);
|
|
2555
|
-
lastKnownCode = next;
|
|
2556
|
-
const newLineCount = model.getLineCount();
|
|
2557
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
2558
|
-
return;
|
|
2559
|
-
}
|
|
2560
|
-
} catch {}
|
|
2561
|
-
const res = computeMinimalEdit(prev, next);
|
|
2562
|
-
if (!res) return;
|
|
2563
|
-
const { start, endPrevIncl, replaceText } = res;
|
|
2564
|
-
const rangeStart = model.getPositionAt(start);
|
|
2565
|
-
const rangeEnd = model.getPositionAt(endPrevIncl + 1);
|
|
2566
|
-
const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
|
|
2567
|
-
const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
2568
|
-
const edit = [{
|
|
2569
|
-
range,
|
|
2570
|
-
text: replaceText,
|
|
2571
|
-
forceMoveMarkers: true
|
|
2572
|
-
}];
|
|
2573
|
-
if (isReadOnly) model.applyEdits(edit);
|
|
2574
|
-
else editorView.executeEdits("minimal-replace", edit);
|
|
2575
|
-
}
|
|
2576
|
-
function flushPendingUpdate() {
|
|
2577
|
-
if (!pendingUpdate) return;
|
|
2578
|
-
lastFlushTime = Date.now();
|
|
2579
|
-
if (!editorView) return;
|
|
2580
|
-
const model = editorView.getModel();
|
|
2581
|
-
if (!model) return;
|
|
2582
|
-
const { code: newCode, lang: codeLanguage } = pendingUpdate;
|
|
2583
|
-
pendingUpdate = null;
|
|
2584
|
-
const processedCodeLanguage = processedLanguage(codeLanguage);
|
|
2585
|
-
let prevCode = null;
|
|
2586
|
-
if (appendBuffer.length > 0) try {
|
|
2587
|
-
prevCode = model.getValue();
|
|
2588
|
-
lastKnownCode = prevCode;
|
|
2589
|
-
} catch {
|
|
2590
|
-
prevCode = "";
|
|
2591
|
-
}
|
|
2592
|
-
else {
|
|
2593
|
-
prevCode = lastKnownCode;
|
|
2594
|
-
if (prevCode == null) try {
|
|
2595
|
-
prevCode = model.getValue();
|
|
2596
|
-
lastKnownCode = prevCode;
|
|
2597
|
-
} catch {
|
|
2598
|
-
prevCode = "";
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
if (prevCode === newCode) return;
|
|
2602
|
-
const languageId = model.getLanguageId();
|
|
2603
|
-
if (languageId !== processedCodeLanguage) {
|
|
2604
|
-
if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
|
|
2605
|
-
const prevLineCount = model.getLineCount();
|
|
2606
|
-
model.setValue(newCode);
|
|
2607
|
-
lastKnownCode = newCode;
|
|
2608
|
-
const newLineCount = model.getLineCount();
|
|
2609
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
2610
|
-
return;
|
|
2611
|
-
}
|
|
2612
|
-
if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
|
|
2613
|
-
const suffix = newCode.slice(prevCode.length);
|
|
2614
|
-
if (suffix) appendCode(suffix, codeLanguage);
|
|
2615
|
-
lastKnownCode = newCode;
|
|
2616
|
-
return;
|
|
2617
|
-
}
|
|
2618
|
-
try {
|
|
2619
|
-
const maxChars = minimalEditMaxCharsLocal;
|
|
2620
|
-
const ratio = minimalEditMaxChangeRatioLocal;
|
|
2621
|
-
const maxLen = Math.max(prevCode.length, newCode.length);
|
|
2622
|
-
const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
|
|
2623
|
-
if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
|
|
2624
|
-
const prevLineCount = model.getLineCount();
|
|
2625
|
-
model.setValue(newCode);
|
|
2626
|
-
lastKnownCode = newCode;
|
|
2627
|
-
const newLineCount = model.getLineCount();
|
|
2628
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
2629
|
-
return;
|
|
2630
|
-
}
|
|
2631
|
-
} catch {}
|
|
2632
|
-
try {
|
|
2633
|
-
applyMinimalEdit(prevCode, newCode);
|
|
2634
|
-
lastKnownCode = newCode;
|
|
2635
|
-
const newLineCount = model.getLineCount();
|
|
2636
|
-
const prevLineCount = (prevCode ? prevCode.split("\n").length : 0) || model.getLineCount();
|
|
2637
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
2638
|
-
} catch {
|
|
2639
|
-
try {
|
|
2640
|
-
const prevLineCount = model.getLineCount();
|
|
2641
|
-
model.setValue(newCode);
|
|
2642
|
-
lastKnownCode = newCode;
|
|
2643
|
-
const newLineCount = model.getLineCount();
|
|
2644
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
2645
|
-
} catch {}
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
function flushAppendBuffer() {
|
|
2649
|
-
if (!editorView) return;
|
|
2650
|
-
if (appendBuffer.length === 0) return;
|
|
2651
|
-
appendBufferScheduled = false;
|
|
2652
|
-
const model = editorView.getModel();
|
|
2653
|
-
if (!model) {
|
|
2654
|
-
appendBuffer.length = 0;
|
|
2655
|
-
return;
|
|
2656
|
-
}
|
|
2657
|
-
const text = appendBuffer.join("");
|
|
2658
|
-
appendBuffer.length = 0;
|
|
2659
|
-
try {
|
|
2660
|
-
const lastLine = model.getLineCount();
|
|
2661
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
2662
|
-
const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
2663
|
-
const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
2664
|
-
if (isReadOnly) model.applyEdits([{
|
|
2665
|
-
range,
|
|
2666
|
-
text,
|
|
2667
|
-
forceMoveMarkers: true
|
|
2668
|
-
}]);
|
|
2669
|
-
else editorView.executeEdits("append", [{
|
|
2670
|
-
range,
|
|
2671
|
-
text,
|
|
2672
|
-
forceMoveMarkers: true
|
|
2673
|
-
}]);
|
|
2674
|
-
if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
|
|
2675
|
-
try {
|
|
2676
|
-
if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
|
|
2677
|
-
} catch {}
|
|
2678
|
-
} catch {}
|
|
2679
|
-
}
|
|
2680
|
-
function updateCode(newCode, codeLanguage) {
|
|
2681
|
-
if (editorMgr) editorMgr.updateCode(newCode, codeLanguage);
|
|
2682
|
-
else {
|
|
2683
|
-
pendingUpdate = {
|
|
2684
|
-
code: newCode,
|
|
2685
|
-
lang: codeLanguage
|
|
2686
|
-
};
|
|
2687
|
-
rafScheduler.schedule("update", () => {
|
|
2688
|
-
if (!updateThrottleMs) {
|
|
2689
|
-
flushPendingUpdate();
|
|
2690
|
-
return;
|
|
2691
|
-
}
|
|
2692
|
-
const now = Date.now();
|
|
2693
|
-
const since = now - lastFlushTime;
|
|
2694
|
-
if (since >= updateThrottleMs) {
|
|
2695
|
-
flushPendingUpdate();
|
|
2696
|
-
return;
|
|
2697
|
-
}
|
|
2698
|
-
if (updateThrottleTimer != null) return;
|
|
2699
|
-
const wait = updateThrottleMs - since;
|
|
2700
|
-
updateThrottleTimer = setTimeout(() => {
|
|
2701
|
-
updateThrottleTimer = null;
|
|
2702
|
-
rafScheduler.schedule("update", () => flushPendingUpdate());
|
|
2703
|
-
}, wait);
|
|
2704
|
-
});
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
function setUpdateThrottleMs(ms) {
|
|
2708
|
-
updateThrottleMs = ms;
|
|
2709
|
-
}
|
|
2710
|
-
function getUpdateThrottleMs() {
|
|
2711
|
-
return updateThrottleMs;
|
|
2712
|
-
}
|
|
2713
|
-
function updateDiff(originalCode, modifiedCode, codeLanguage) {
|
|
2714
|
-
if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
|
|
2715
|
-
}
|
|
2716
|
-
function updateOriginal(newCode, codeLanguage) {
|
|
2717
|
-
if (diffMgr) diffMgr.updateOriginal(newCode, codeLanguage);
|
|
2718
|
-
}
|
|
2719
|
-
function updateModified(newCode, codeLanguage) {
|
|
2720
|
-
if (diffMgr) diffMgr.updateModified(newCode, codeLanguage);
|
|
2721
|
-
}
|
|
2722
|
-
function appendOriginal(appendText, codeLanguage) {
|
|
2723
|
-
if (diffMgr) diffMgr.appendOriginal(appendText, codeLanguage);
|
|
2724
|
-
}
|
|
2725
|
-
function appendModified(appendText, codeLanguage) {
|
|
2726
|
-
if (diffMgr) diffMgr.appendModified(appendText, codeLanguage);
|
|
2727
|
-
}
|
|
2728
|
-
return {
|
|
2729
|
-
createEditor,
|
|
2730
|
-
createDiffEditor,
|
|
2731
|
-
cleanupEditor,
|
|
2732
|
-
safeClean() {
|
|
2733
|
-
rafScheduler.cancel("update");
|
|
2734
|
-
pendingUpdate = null;
|
|
2735
|
-
if (editorMgr) try {
|
|
2736
|
-
editorMgr.safeClean();
|
|
2737
|
-
} catch {}
|
|
2738
|
-
if (diffMgr) try {
|
|
2739
|
-
diffMgr.safeClean();
|
|
2740
|
-
} catch {}
|
|
2741
|
-
_hasScrollBar = false;
|
|
2742
|
-
shouldAutoScroll = !!autoScrollInitial;
|
|
2743
|
-
},
|
|
2744
|
-
updateCode,
|
|
2745
|
-
appendCode,
|
|
2746
|
-
updateDiff,
|
|
2747
|
-
updateOriginal,
|
|
2748
|
-
updateModified,
|
|
2749
|
-
appendOriginal,
|
|
2750
|
-
appendModified,
|
|
2751
|
-
setTheme: setThemeInternal,
|
|
2752
|
-
setLanguage(language) {
|
|
2753
|
-
if (editorMgr) {
|
|
2754
|
-
editorMgr.setLanguage(language, languages$1);
|
|
2755
|
-
return;
|
|
2756
|
-
}
|
|
2757
|
-
if (diffMgr) {
|
|
2758
|
-
diffMgr.setLanguage(language, languages$1);
|
|
2759
|
-
return;
|
|
2760
|
-
}
|
|
2761
|
-
if (languages$1.includes(language)) {
|
|
2762
|
-
if (editorView) {
|
|
2763
|
-
const model = editorView.getModel();
|
|
2764
|
-
if (model && model.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(model, language);
|
|
2765
|
-
}
|
|
2766
|
-
if (originalModel && originalModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(originalModel, language);
|
|
2767
|
-
if (modifiedModel && modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(modifiedModel, language);
|
|
2768
|
-
} else console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
|
|
2769
|
-
},
|
|
2770
|
-
getCurrentTheme() {
|
|
2771
|
-
return globalAppliedThemeName ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
|
|
2772
|
-
},
|
|
2773
|
-
getEditor() {
|
|
2774
|
-
return monaco_shim_exports.editor;
|
|
2775
|
-
},
|
|
2776
|
-
getEditorView() {
|
|
2777
|
-
return editorView;
|
|
2778
|
-
},
|
|
2779
|
-
getDiffEditorView() {
|
|
2780
|
-
return diffEditorView;
|
|
2781
|
-
},
|
|
2782
|
-
getDiffModels() {
|
|
2783
|
-
return {
|
|
2784
|
-
original: originalModel,
|
|
2785
|
-
modified: modifiedModel
|
|
2786
|
-
};
|
|
2787
|
-
},
|
|
2788
|
-
getMonacoInstance() {
|
|
2789
|
-
return monaco_shim_exports;
|
|
2790
|
-
},
|
|
2791
|
-
setUpdateThrottleMs,
|
|
2792
|
-
getUpdateThrottleMs,
|
|
2793
|
-
getCode() {
|
|
2794
|
-
if (editorView) try {
|
|
2795
|
-
var _editorView$getModel;
|
|
2796
|
-
return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
|
|
2797
|
-
} catch {
|
|
2798
|
-
return null;
|
|
2799
|
-
}
|
|
2800
|
-
if (diffEditorView || originalModel && modifiedModel) try {
|
|
2801
|
-
const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
|
|
2802
|
-
const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
|
|
2803
|
-
return {
|
|
2804
|
-
original,
|
|
2805
|
-
modified
|
|
2806
|
-
};
|
|
2807
|
-
} catch {
|
|
2808
|
-
return null;
|
|
2809
|
-
}
|
|
2810
|
-
return null;
|
|
2811
|
-
}
|
|
2812
|
-
};
|
|
2813
|
-
}
|
|
34
|
+
ensureMonacoWorkers();
|
|
2814
35
|
|
|
2815
36
|
//#endregion
|
|
2816
|
-
export { RevealStrategy, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
|
|
37
|
+
export { RevealStrategy, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, ensureMonacoWorkers, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
|