stream-monaco 0.0.2 → 0.0.4
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 +114 -0
- package/README.zh-CN.md +75 -0
- package/dist/index.cjs +822 -118
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +822 -118
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __export, __reExport } from "./chunk-CHLpw0oG.js";
|
|
2
2
|
import * as _monaco from "monaco-editor";
|
|
3
|
+
import nodeProcess from "node:process";
|
|
3
4
|
import { computed, effect, signal } from "alien-signals";
|
|
4
5
|
import { shikiToMonaco } from "@shikijs/monaco";
|
|
5
6
|
import { createHighlighter } from "shiki";
|
|
@@ -199,34 +200,107 @@ import * as import_monaco_editor from "monaco-editor";
|
|
|
199
200
|
__reExport(monaco_shim_exports, import_monaco_editor);
|
|
200
201
|
const monaco = _monaco;
|
|
201
202
|
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/utils/logger.ts
|
|
205
|
+
let seq = 0;
|
|
206
|
+
const DEBUG = (() => {
|
|
207
|
+
try {
|
|
208
|
+
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) return Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
209
|
+
try {
|
|
210
|
+
const proc = nodeProcess;
|
|
211
|
+
if (proc && proc.env && proc.env.NODE_ENV === "production") return false;
|
|
212
|
+
} catch {}
|
|
213
|
+
} catch {}
|
|
214
|
+
return true;
|
|
215
|
+
})();
|
|
216
|
+
function log(tag, ...args) {
|
|
217
|
+
if (!DEBUG) return;
|
|
218
|
+
try {
|
|
219
|
+
seq += 1;
|
|
220
|
+
const id = `#${seq}`;
|
|
221
|
+
const ts = typeof performance !== "undefined" && performance.now ? performance.now().toFixed(1) : Date.now();
|
|
222
|
+
console.warn(`${id} [${tag}] @${ts}ms`, ...args);
|
|
223
|
+
} catch (err) {
|
|
224
|
+
try {
|
|
225
|
+
console.warn("[logger] fallback", tag, ...args, err);
|
|
226
|
+
} catch {}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function error(tag, ...args) {
|
|
230
|
+
if (!DEBUG) return;
|
|
231
|
+
try {
|
|
232
|
+
console.error(`[${tag}]`, ...args);
|
|
233
|
+
} catch (err) {
|
|
234
|
+
try {
|
|
235
|
+
console.error("[logger] fallback error", tag, ...args, err);
|
|
236
|
+
} catch {}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
202
240
|
//#endregion
|
|
203
241
|
//#region src/utils/height.ts
|
|
204
242
|
function createHeightManager(container, computeNext) {
|
|
205
243
|
let raf = null;
|
|
244
|
+
let debounceTimer = null;
|
|
206
245
|
let lastApplied = -1;
|
|
207
246
|
let suppressed = false;
|
|
247
|
+
const HYSTERESIS_PX = 12;
|
|
248
|
+
const DEBOUNCE_MS = 0;
|
|
208
249
|
function apply() {
|
|
209
250
|
const next = computeNext();
|
|
251
|
+
if (next == null) return;
|
|
252
|
+
log("heightManager", "computeNext ->", {
|
|
253
|
+
next,
|
|
254
|
+
lastApplied
|
|
255
|
+
});
|
|
256
|
+
if (!Number.isFinite(next) || next <= 0) {
|
|
257
|
+
log("heightManager", "invalid next height, ignoring", next);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (lastApplied !== -1 && Math.abs(next - lastApplied) <= HYSTERESIS_PX) return;
|
|
210
261
|
if (next === lastApplied) return;
|
|
211
262
|
suppressed = true;
|
|
212
263
|
container.style.height = `${next}px`;
|
|
213
264
|
lastApplied = next;
|
|
265
|
+
log("heightManager", "applied height ->", next);
|
|
214
266
|
queueMicrotask(() => {
|
|
215
267
|
suppressed = false;
|
|
216
268
|
});
|
|
217
269
|
}
|
|
270
|
+
function scheduleApply() {
|
|
271
|
+
if (debounceTimer != null) {
|
|
272
|
+
clearTimeout(debounceTimer);
|
|
273
|
+
debounceTimer = null;
|
|
274
|
+
}
|
|
275
|
+
if (DEBOUNCE_MS === 0) {
|
|
276
|
+
if (raf != null) return;
|
|
277
|
+
raf = requestAnimationFrame(() => {
|
|
278
|
+
raf = null;
|
|
279
|
+
apply();
|
|
280
|
+
});
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
debounceTimer = setTimeout(() => {
|
|
284
|
+
debounceTimer = null;
|
|
285
|
+
if (raf != null) return;
|
|
286
|
+
raf = requestAnimationFrame(() => {
|
|
287
|
+
raf = null;
|
|
288
|
+
apply();
|
|
289
|
+
});
|
|
290
|
+
}, DEBOUNCE_MS);
|
|
291
|
+
}
|
|
218
292
|
function update() {
|
|
219
|
-
|
|
220
|
-
raf = requestAnimationFrame(() => {
|
|
221
|
-
raf = null;
|
|
222
|
-
apply();
|
|
223
|
-
});
|
|
293
|
+
scheduleApply();
|
|
224
294
|
}
|
|
225
295
|
function dispose() {
|
|
226
296
|
if (raf != null) {
|
|
227
297
|
cancelAnimationFrame(raf);
|
|
228
298
|
raf = null;
|
|
229
299
|
}
|
|
300
|
+
if (debounceTimer != null) {
|
|
301
|
+
clearTimeout(debounceTimer);
|
|
302
|
+
debounceTimer = null;
|
|
303
|
+
}
|
|
230
304
|
}
|
|
231
305
|
function isSuppressed() {
|
|
232
306
|
return suppressed;
|
|
@@ -282,18 +356,105 @@ function createScrollWatcherForEditor(ed, opts) {
|
|
|
282
356
|
var _ed$getScrollTop, _ed$onDidScrollChange;
|
|
283
357
|
const initial = ((_ed$getScrollTop = ed.getScrollTop) === null || _ed$getScrollTop === void 0 ? void 0 : _ed$getScrollTop.call(ed)) ?? 0;
|
|
284
358
|
opts.setLast(initial);
|
|
285
|
-
|
|
359
|
+
log("scrollWatcher", "initial scrollTop=", initial);
|
|
360
|
+
let suppressedExternally = false;
|
|
361
|
+
const THRESHOLD_PX = 6;
|
|
362
|
+
let domNode = null;
|
|
363
|
+
let interactionListener = null;
|
|
364
|
+
const listener = (e) => {
|
|
286
365
|
var _ed$getScrollTop2;
|
|
366
|
+
if (suppressedExternally) {
|
|
367
|
+
log("scrollWatcher", "suppressedExternally, ignoring event");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
287
370
|
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;
|
|
288
371
|
const delta = currentTop - opts.getLast();
|
|
289
372
|
opts.setLast(currentTop);
|
|
373
|
+
if (Math.abs(delta) < THRESHOLD_PX) {
|
|
374
|
+
log("scrollWatcher", "small delta ignored", delta);
|
|
375
|
+
try {
|
|
376
|
+
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
377
|
+
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
378
|
+
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
379
|
+
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
380
|
+
const distance = scrollHeight - (currentTop + viewportH);
|
|
381
|
+
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
382
|
+
log("scrollWatcher", "small delta but at bottom, maybe resume", { distance });
|
|
383
|
+
opts.onMaybeResume();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} catch {}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
log("scrollWatcher", "delta=", delta, "currentTop=", currentTop);
|
|
290
390
|
if (delta < 0) {
|
|
391
|
+
log("scrollWatcher", "pause detected delta=", delta);
|
|
291
392
|
opts.onPause();
|
|
292
393
|
return;
|
|
293
394
|
}
|
|
395
|
+
log("scrollWatcher", "maybe resume delta=", delta);
|
|
294
396
|
opts.onMaybeResume();
|
|
295
|
-
}
|
|
296
|
-
|
|
397
|
+
};
|
|
398
|
+
const disp = ((_ed$onDidScrollChange = ed.onDidScrollChange) === null || _ed$onDidScrollChange === void 0 ? void 0 : _ed$onDidScrollChange.call(ed, listener)) ?? null;
|
|
399
|
+
const api = {
|
|
400
|
+
dispose() {
|
|
401
|
+
try {
|
|
402
|
+
if (disp && typeof disp.dispose === "function") disp.dispose();
|
|
403
|
+
else if (typeof disp === "function") disp();
|
|
404
|
+
} catch {}
|
|
405
|
+
log("scrollWatcher", "dispose");
|
|
406
|
+
},
|
|
407
|
+
setSuppressed(v) {
|
|
408
|
+
const newVal = !!v;
|
|
409
|
+
if (newVal === suppressedExternally) return;
|
|
410
|
+
suppressedExternally = newVal;
|
|
411
|
+
log("scrollWatcher", "setSuppressed =>", suppressedExternally);
|
|
412
|
+
try {
|
|
413
|
+
if (!domNode && typeof ed.getDomNode === "function") domNode = ed.getDomNode();
|
|
414
|
+
if (suppressedExternally && domNode) {
|
|
415
|
+
if (!interactionListener) {
|
|
416
|
+
interactionListener = () => {
|
|
417
|
+
try {
|
|
418
|
+
var _ed$getScrollTop3;
|
|
419
|
+
log("scrollWatcher", "user interaction detected while suppressed, cancelling suppression");
|
|
420
|
+
opts.onPause();
|
|
421
|
+
suppressedExternally = false;
|
|
422
|
+
const cur = ((_ed$getScrollTop3 = ed.getScrollTop) === null || _ed$getScrollTop3 === void 0 ? void 0 : _ed$getScrollTop3.call(ed)) ?? 0;
|
|
423
|
+
opts.setLast(cur);
|
|
424
|
+
try {
|
|
425
|
+
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
426
|
+
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
427
|
+
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
428
|
+
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
429
|
+
const distance = scrollHeight - (cur + viewportH);
|
|
430
|
+
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
431
|
+
log("scrollWatcher", "interaction moved to bottom, maybe resume", { distance });
|
|
432
|
+
opts.onMaybeResume();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
} catch {}
|
|
436
|
+
if (domNode && interactionListener) {
|
|
437
|
+
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
438
|
+
domNode.removeEventListener("pointerdown", interactionListener);
|
|
439
|
+
domNode.removeEventListener("touchstart", interactionListener);
|
|
440
|
+
}
|
|
441
|
+
interactionListener = null;
|
|
442
|
+
} catch {}
|
|
443
|
+
};
|
|
444
|
+
domNode.addEventListener("wheel", interactionListener, { passive: true });
|
|
445
|
+
domNode.addEventListener("pointerdown", interactionListener);
|
|
446
|
+
domNode.addEventListener("touchstart", interactionListener);
|
|
447
|
+
}
|
|
448
|
+
} else if (domNode && interactionListener) {
|
|
449
|
+
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
450
|
+
domNode.removeEventListener("pointerdown", interactionListener);
|
|
451
|
+
domNode.removeEventListener("touchstart", interactionListener);
|
|
452
|
+
interactionListener = null;
|
|
453
|
+
}
|
|
454
|
+
} catch {}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
return api;
|
|
297
458
|
}
|
|
298
459
|
|
|
299
460
|
//#endregion
|
|
@@ -338,11 +499,14 @@ var DiffEditorManager = class {
|
|
|
338
499
|
};
|
|
339
500
|
}
|
|
340
501
|
lastRevealLineDiff = null;
|
|
502
|
+
revealTicketDiff = 0;
|
|
341
503
|
revealDebounceIdDiff = null;
|
|
342
504
|
revealDebounceMs = defaultRevealDebounceMs;
|
|
343
505
|
revealIdleTimerIdDiff = null;
|
|
344
506
|
revealStrategyOption;
|
|
345
507
|
revealBatchOnIdleMsOption;
|
|
508
|
+
scrollWatcherSuppressionMs = 500;
|
|
509
|
+
diffScrollWatcherSuppressionTimer = null;
|
|
346
510
|
appendBufferDiff = [];
|
|
347
511
|
appendBufferDiffScheduled = false;
|
|
348
512
|
rafScheduler = createRafScheduler();
|
|
@@ -372,6 +536,26 @@ var DiffEditorManager = class {
|
|
|
372
536
|
const desired = Math.max(fromLines, scrollH);
|
|
373
537
|
return Math.min(desired, this.maxHeightValue);
|
|
374
538
|
}
|
|
539
|
+
isOverflowAutoDiff() {
|
|
540
|
+
return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
|
|
541
|
+
}
|
|
542
|
+
shouldPerformImmediateRevealDiff() {
|
|
543
|
+
return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
|
|
544
|
+
}
|
|
545
|
+
suppressScrollWatcherDiff(ms) {
|
|
546
|
+
if (!this.diffScrollWatcher || typeof this.diffScrollWatcher.setSuppressed !== "function") return;
|
|
547
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
548
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
549
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
550
|
+
}
|
|
551
|
+
this.diffScrollWatcher.setSuppressed(true);
|
|
552
|
+
this.diffScrollWatcherSuppressionTimer = setTimeout(() => {
|
|
553
|
+
try {
|
|
554
|
+
this.diffScrollWatcher.setSuppressed(false);
|
|
555
|
+
} catch {}
|
|
556
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
557
|
+
}, ms);
|
|
558
|
+
}
|
|
375
559
|
hasVerticalScrollbarModified() {
|
|
376
560
|
if (!this.diffEditorView) return false;
|
|
377
561
|
if (this._hasScrollBar) return true;
|
|
@@ -391,21 +575,56 @@ var DiffEditorManager = class {
|
|
|
391
575
|
}
|
|
392
576
|
maybeScrollDiffToBottom(targetLine, prevLineOverride) {
|
|
393
577
|
this.rafScheduler.schedule("maybe-scroll-diff", () => {
|
|
578
|
+
log("diff", "maybeScrollDiffToBottom called", {
|
|
579
|
+
targetLine,
|
|
580
|
+
prevLineOverride,
|
|
581
|
+
diffAutoScroll: this.diffAutoScroll,
|
|
582
|
+
autoScrollOnUpdate: this.autoScrollOnUpdate,
|
|
583
|
+
shouldAutoScrollDiff: this.shouldAutoScrollDiff
|
|
584
|
+
});
|
|
394
585
|
if (!this.diffEditorView) return;
|
|
395
|
-
|
|
586
|
+
const hasV = this.hasVerticalScrollbarModified();
|
|
587
|
+
log("diff", "hasVerticalScrollbarModified ->", hasV);
|
|
588
|
+
if (!(this.diffAutoScroll && this.autoScrollOnUpdate && this.shouldAutoScrollDiff && hasV)) return;
|
|
396
589
|
const me = this.diffEditorView.getModifiedEditor();
|
|
397
590
|
const model = me.getModel();
|
|
398
591
|
const currentLine = (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
399
592
|
const line = targetLine ?? currentLine;
|
|
400
593
|
const prevLine = typeof prevLineOverride === "number" ? prevLineOverride : this.lastKnownModifiedLineCount ?? -1;
|
|
594
|
+
log("diff", "scroll metrics", {
|
|
595
|
+
prevLine,
|
|
596
|
+
currentLine,
|
|
597
|
+
line,
|
|
598
|
+
lastRevealLineDiff: this.lastRevealLineDiff
|
|
599
|
+
});
|
|
401
600
|
if (prevLine !== -1 && prevLine === currentLine && line === currentLine) return;
|
|
402
601
|
if (this.lastRevealLineDiff !== null && this.lastRevealLineDiff === line) return;
|
|
403
602
|
const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
|
|
603
|
+
log("diff", "reveal timing", {
|
|
604
|
+
batchMs,
|
|
605
|
+
revealDebounceMs: this.revealDebounceMs,
|
|
606
|
+
revealDebounceMsOption: this.revealDebounceMsOption
|
|
607
|
+
});
|
|
404
608
|
if (typeof batchMs === "number" && batchMs > 0) {
|
|
609
|
+
if (hasV) {
|
|
610
|
+
const ticket$1 = ++this.revealTicketDiff;
|
|
611
|
+
log("diff", "has scrollbar -> immediate ticketed reveal", {
|
|
612
|
+
ticket: ticket$1,
|
|
613
|
+
line
|
|
614
|
+
});
|
|
615
|
+
this.performRevealDiffTicketed(line, ticket$1);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
405
618
|
if (this.revealIdleTimerIdDiff != null) clearTimeout(this.revealIdleTimerIdDiff);
|
|
619
|
+
const ticket = ++this.revealTicketDiff;
|
|
620
|
+
log("diff", "scheduling idle reveal", {
|
|
621
|
+
ticket,
|
|
622
|
+
batchMs,
|
|
623
|
+
line
|
|
624
|
+
});
|
|
406
625
|
this.revealIdleTimerIdDiff = setTimeout(() => {
|
|
407
626
|
this.revealIdleTimerIdDiff = null;
|
|
408
|
-
this.
|
|
627
|
+
this.performRevealDiffTicketed(line, ticket);
|
|
409
628
|
}, batchMs);
|
|
410
629
|
return;
|
|
411
630
|
}
|
|
@@ -416,14 +635,32 @@ var DiffEditorManager = class {
|
|
|
416
635
|
const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
|
|
417
636
|
this.revealDebounceIdDiff = setTimeout(() => {
|
|
418
637
|
this.revealDebounceIdDiff = null;
|
|
419
|
-
this.
|
|
638
|
+
const ticket = ++this.revealTicketDiff;
|
|
639
|
+
log("diff", "debounced reveal firing", {
|
|
640
|
+
ticket,
|
|
641
|
+
line
|
|
642
|
+
});
|
|
643
|
+
this.performRevealDiffTicketed(line, ticket);
|
|
420
644
|
}, ms);
|
|
421
645
|
this.lastKnownModifiedLineCount = currentLine;
|
|
422
646
|
});
|
|
423
647
|
}
|
|
424
|
-
|
|
648
|
+
performRevealDiffTicketed(line, ticket) {
|
|
425
649
|
this.rafScheduler.schedule("revealDiff", () => {
|
|
426
650
|
var _editor;
|
|
651
|
+
if (this.diffScrollWatcher) {
|
|
652
|
+
log("diff", "performRevealDiffTicketed - suppressing watcher", {
|
|
653
|
+
ticket,
|
|
654
|
+
line,
|
|
655
|
+
ms: this.scrollWatcherSuppressionMs
|
|
656
|
+
});
|
|
657
|
+
this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs);
|
|
658
|
+
}
|
|
659
|
+
if (ticket !== this.revealTicketDiff) return;
|
|
660
|
+
log("diff", "performRevealDiffTicketed - performing reveal", {
|
|
661
|
+
ticket,
|
|
662
|
+
line
|
|
663
|
+
});
|
|
427
664
|
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
428
665
|
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
429
666
|
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
@@ -441,13 +678,71 @@ var DiffEditorManager = class {
|
|
|
441
678
|
} catch {}
|
|
442
679
|
}
|
|
443
680
|
this.lastRevealLineDiff = line;
|
|
681
|
+
log("diff", "performRevealDiffTicketed - revealed", {
|
|
682
|
+
line,
|
|
683
|
+
lastRevealLineDiff: this.lastRevealLineDiff
|
|
684
|
+
});
|
|
685
|
+
try {
|
|
686
|
+
var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2;
|
|
687
|
+
this.shouldAutoScrollDiff = true;
|
|
688
|
+
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;
|
|
689
|
+
} catch {}
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
performImmediateRevealDiff(line, ticket) {
|
|
693
|
+
var _editor2;
|
|
694
|
+
if (!this.diffEditorView) return;
|
|
695
|
+
if (ticket !== this.revealTicketDiff) return;
|
|
696
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
697
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
698
|
+
const me = this.diffEditorView.getModifiedEditor();
|
|
699
|
+
if (typeof immediate !== "undefined") me.revealLine(line, immediate);
|
|
700
|
+
else me.revealLine(line);
|
|
701
|
+
this.measureViewportDiff();
|
|
702
|
+
log("diff", "performImmediateRevealDiff", {
|
|
703
|
+
line,
|
|
704
|
+
ticket
|
|
705
|
+
});
|
|
706
|
+
try {
|
|
707
|
+
var _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
|
|
708
|
+
this.shouldAutoScrollDiff = true;
|
|
709
|
+
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;
|
|
710
|
+
} catch {}
|
|
711
|
+
}
|
|
712
|
+
scheduleImmediateRevealAfterLayoutDiff(line) {
|
|
713
|
+
const ticket = ++this.revealTicketDiff;
|
|
714
|
+
this.rafScheduler.schedule("immediate-reveal-diff", async () => {
|
|
715
|
+
const target = this.diffEditorView && this.diffHeightManager ? Math.min(this.computedHeight(), this.maxHeightValue) : -1;
|
|
716
|
+
if (target !== -1 && this.diffHeightManager) {
|
|
717
|
+
if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
|
|
718
|
+
await this.waitForHeightAppliedDiff(target);
|
|
719
|
+
}
|
|
720
|
+
this.performImmediateRevealDiff(line, ticket);
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
waitForHeightAppliedDiff(target, timeoutMs = 500) {
|
|
724
|
+
return new Promise((resolve) => {
|
|
725
|
+
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
726
|
+
const check = () => {
|
|
727
|
+
const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
|
|
728
|
+
if (applied >= target - 1) {
|
|
729
|
+
resolve();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
|
|
733
|
+
resolve();
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
requestAnimationFrame(check);
|
|
737
|
+
};
|
|
738
|
+
check();
|
|
444
739
|
});
|
|
445
740
|
}
|
|
446
741
|
async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
|
|
447
742
|
var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
|
|
448
743
|
this.cleanup();
|
|
449
744
|
this.lastContainer = container;
|
|
450
|
-
container.style.overflow = "
|
|
745
|
+
container.style.overflow = "hidden";
|
|
451
746
|
container.style.maxHeight = this.maxHeightCSS;
|
|
452
747
|
const lang = processedLanguage(language) || language;
|
|
453
748
|
this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
|
|
@@ -496,13 +791,23 @@ var DiffEditorManager = class {
|
|
|
496
791
|
}
|
|
497
792
|
});
|
|
498
793
|
}
|
|
499
|
-
|
|
794
|
+
log("diff", "createDiffEditor", {
|
|
795
|
+
autoScrollInitial: this.autoScrollInitial,
|
|
796
|
+
diffAutoScroll: this.diffAutoScroll
|
|
797
|
+
});
|
|
798
|
+
const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
|
|
799
|
+
container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
|
|
500
800
|
if (this.diffHeightManager) {
|
|
501
801
|
this.diffHeightManager.dispose();
|
|
502
802
|
this.diffHeightManager = null;
|
|
503
803
|
}
|
|
504
804
|
this.diffHeightManager = createHeightManager(container, () => this.computedHeight());
|
|
505
805
|
this.diffHeightManager.update();
|
|
806
|
+
const initialComputed = this.computedHeight();
|
|
807
|
+
if (initialComputed >= this.maxHeightValue - 1) {
|
|
808
|
+
container.style.height = `${this.maxHeightValue}px`;
|
|
809
|
+
container.style.overflow = "auto";
|
|
810
|
+
}
|
|
506
811
|
const me = this.diffEditorView.getModifiedEditor();
|
|
507
812
|
this.cachedScrollHeightDiff = ((_me$getScrollHeight2 = me.getScrollHeight) === null || _me$getScrollHeight2 === void 0 ? void 0 : _me$getScrollHeight2.call(me)) ?? null;
|
|
508
813
|
this.cachedLineHeightDiff = ((_me$getOption = me.getOption) === null || _me$getOption === void 0 ? void 0 : _me$getOption.call(me, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
|
|
@@ -512,33 +817,54 @@ var DiffEditorManager = class {
|
|
|
512
817
|
(_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
|
|
513
818
|
this._hasScrollBar = false;
|
|
514
819
|
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
820
|
+
var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag, _this$diffHeightManag2;
|
|
821
|
+
this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
|
|
822
|
+
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;
|
|
823
|
+
this.cachedComputedHeightDiff = this.computedHeight();
|
|
824
|
+
if ((_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 ? void 0 : _this$diffHeightManag.isSuppressed()) return;
|
|
825
|
+
(_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
|
|
826
|
+
const computed$2 = this.computedHeight();
|
|
827
|
+
if (this.lastContainer) {
|
|
828
|
+
const prevOverflow = this.lastContainer.style.overflow;
|
|
829
|
+
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
830
|
+
if (prevOverflow !== newOverflow) {
|
|
831
|
+
this.lastContainer.style.overflow = newOverflow;
|
|
832
|
+
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
833
|
+
var _this$modifiedModel;
|
|
834
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel = this.modifiedModel) === null || _this$modifiedModel === void 0 ? void 0 : _this$modifiedModel.getLineCount());
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
523
838
|
});
|
|
524
839
|
});
|
|
525
840
|
(_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
|
|
526
841
|
this._hasScrollBar = false;
|
|
527
842
|
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
843
|
+
var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
|
|
844
|
+
this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
|
|
845
|
+
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;
|
|
846
|
+
this.cachedComputedHeightDiff = this.computedHeight();
|
|
847
|
+
if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
|
|
848
|
+
(_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
|
|
849
|
+
const computed$2 = this.computedHeight();
|
|
850
|
+
if (this.lastContainer) {
|
|
851
|
+
const prevOverflow = this.lastContainer.style.overflow;
|
|
852
|
+
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
853
|
+
if (prevOverflow !== newOverflow) {
|
|
854
|
+
this.lastContainer.style.overflow = newOverflow;
|
|
855
|
+
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
856
|
+
var _this$modifiedModel2;
|
|
857
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount());
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
536
861
|
});
|
|
537
862
|
});
|
|
538
863
|
mEditor.onDidChangeModelContent(() => {
|
|
539
864
|
this.lastKnownModifiedDirty = true;
|
|
540
865
|
this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
|
|
541
866
|
});
|
|
867
|
+
this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), this.lastKnownModifiedLineCount ?? void 0);
|
|
542
868
|
return this.diffEditorView;
|
|
543
869
|
}
|
|
544
870
|
updateDiff(originalCode, modifiedCode, codeLanguage) {
|
|
@@ -598,11 +924,37 @@ var DiffEditorManager = class {
|
|
|
598
924
|
}
|
|
599
925
|
const prev = this.lastKnownModifiedCode ?? this.modifiedModel.getValue();
|
|
600
926
|
if (prev === newCode) return;
|
|
927
|
+
const prevLine = this.modifiedModel.getLineCount();
|
|
601
928
|
if (newCode.startsWith(prev) && prev.length < newCode.length) {
|
|
602
|
-
const prevLine = this.modifiedModel.getLineCount();
|
|
603
929
|
this.appendToModel(this.modifiedModel, newCode.slice(prev.length));
|
|
604
930
|
this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), prevLine);
|
|
605
|
-
} else
|
|
931
|
+
} else {
|
|
932
|
+
this.applyMinimalEditToModel(this.modifiedModel, prev, newCode);
|
|
933
|
+
const newLine = this.modifiedModel.getLineCount();
|
|
934
|
+
if (newLine !== prevLine) {
|
|
935
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
936
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
937
|
+
const computed$2 = this.computedHeight();
|
|
938
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
939
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
940
|
+
this.lastContainer.style.overflow = "auto";
|
|
941
|
+
}
|
|
942
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
943
|
+
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
944
|
+
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
945
|
+
var _editor3, _me2$getModel, _me2$getScrollTop;
|
|
946
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
947
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
948
|
+
const me2 = this.diffEditorView.getModifiedEditor();
|
|
949
|
+
const targetLine = ((_me2$getModel = me2.getModel()) === null || _me2$getModel === void 0 ? void 0 : _me2$getModel.getLineCount()) ?? newLine;
|
|
950
|
+
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
951
|
+
else me2.revealLine(targetLine);
|
|
952
|
+
this.lastRevealLineDiff = targetLine;
|
|
953
|
+
this.shouldAutoScrollDiff = true;
|
|
954
|
+
this.lastScrollTopDiff = ((_me2$getScrollTop = me2.getScrollTop) === null || _me2$getScrollTop === void 0 ? void 0 : _me2$getScrollTop.call(me2)) ?? this.lastScrollTopDiff;
|
|
955
|
+
} catch {}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
606
958
|
this.lastKnownModifiedCode = newCode;
|
|
607
959
|
}
|
|
608
960
|
appendOriginal(appendText, codeLanguage) {
|
|
@@ -612,9 +964,7 @@ var DiffEditorManager = class {
|
|
|
612
964
|
if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
|
|
613
965
|
}
|
|
614
966
|
this.appendToModel(this.originalModel, appendText);
|
|
615
|
-
|
|
616
|
-
this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
617
|
-
} catch {}
|
|
967
|
+
this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
618
968
|
}
|
|
619
969
|
appendModified(appendText, codeLanguage) {
|
|
620
970
|
if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
|
|
@@ -683,6 +1033,15 @@ var DiffEditorManager = class {
|
|
|
683
1033
|
clearTimeout(this.revealDebounceIdDiff);
|
|
684
1034
|
this.revealDebounceIdDiff = null;
|
|
685
1035
|
}
|
|
1036
|
+
if (this.revealIdleTimerIdDiff != null) {
|
|
1037
|
+
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1038
|
+
this.revealIdleTimerIdDiff = null;
|
|
1039
|
+
}
|
|
1040
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1041
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1042
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1043
|
+
}
|
|
1044
|
+
this.revealTicketDiff = 0;
|
|
686
1045
|
this.lastRevealLineDiff = null;
|
|
687
1046
|
}
|
|
688
1047
|
safeClean() {
|
|
@@ -703,6 +1062,15 @@ var DiffEditorManager = class {
|
|
|
703
1062
|
clearTimeout(this.revealDebounceIdDiff);
|
|
704
1063
|
this.revealDebounceIdDiff = null;
|
|
705
1064
|
}
|
|
1065
|
+
if (this.revealIdleTimerIdDiff != null) {
|
|
1066
|
+
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1067
|
+
this.revealIdleTimerIdDiff = null;
|
|
1068
|
+
}
|
|
1069
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1070
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1071
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1072
|
+
}
|
|
1073
|
+
this.revealTicketDiff = 0;
|
|
706
1074
|
this.lastRevealLineDiff = null;
|
|
707
1075
|
this.rafScheduler.cancel("content-size-change-diff");
|
|
708
1076
|
this.rafScheduler.cancel("sync-last-known-modified");
|
|
@@ -716,7 +1084,7 @@ var DiffEditorManager = class {
|
|
|
716
1084
|
this.lastKnownModifiedCode = model.getValue();
|
|
717
1085
|
this.lastKnownModifiedLineCount = model.getLineCount();
|
|
718
1086
|
}
|
|
719
|
-
}
|
|
1087
|
+
} finally {
|
|
720
1088
|
this.lastKnownModifiedDirty = false;
|
|
721
1089
|
}
|
|
722
1090
|
}
|
|
@@ -760,10 +1128,20 @@ var DiffEditorManager = class {
|
|
|
760
1128
|
else this.applyMinimalEditToModel(m, prevM, modified);
|
|
761
1129
|
this.lastKnownModifiedCode = modified;
|
|
762
1130
|
const newMLineCount = m.getLineCount();
|
|
763
|
-
if (newMLineCount !== prevMLineCount)
|
|
1131
|
+
if (newMLineCount !== prevMLineCount) {
|
|
1132
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1133
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1134
|
+
const computed$2 = this.computedHeight();
|
|
1135
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1136
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1137
|
+
this.lastContainer.style.overflow = "auto";
|
|
1138
|
+
}
|
|
1139
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newMLineCount);
|
|
1140
|
+
else this.maybeScrollDiffToBottom(newMLineCount, prevMLineCount);
|
|
1141
|
+
}
|
|
764
1142
|
}
|
|
765
1143
|
}
|
|
766
|
-
flushAppendBufferDiff() {
|
|
1144
|
+
async flushAppendBufferDiff() {
|
|
767
1145
|
if (!this.diffEditorView) return;
|
|
768
1146
|
if (this.appendBufferDiff.length === 0) return;
|
|
769
1147
|
this.appendBufferDiffScheduled = false;
|
|
@@ -773,39 +1151,128 @@ var DiffEditorManager = class {
|
|
|
773
1151
|
this.appendBufferDiff.length = 0;
|
|
774
1152
|
return;
|
|
775
1153
|
}
|
|
776
|
-
|
|
1154
|
+
let parts = this.appendBufferDiff.splice(0);
|
|
1155
|
+
const prevLineInit = model.getLineCount();
|
|
1156
|
+
const totalText = parts.join("");
|
|
1157
|
+
const totalChars = totalText.length;
|
|
1158
|
+
if (parts.length === 1 && totalChars > 5e3) {
|
|
1159
|
+
const lines = totalText.split(/\r?\n/);
|
|
1160
|
+
const chunkSize = 200;
|
|
1161
|
+
const chunks = [];
|
|
1162
|
+
for (let i = 0; i < lines.length; i += chunkSize) chunks.push(`${lines.slice(i, i + chunkSize).join("\n")}\n`);
|
|
1163
|
+
if (chunks.length > 1) parts = chunks;
|
|
1164
|
+
}
|
|
1165
|
+
const applyChunked = parts.length > 1 && (totalChars > 2e3 || model.getLineCount && model.getLineCount() + 0 - prevLineInit > 50);
|
|
1166
|
+
log("diff", "flushAppendBufferDiff start", {
|
|
1167
|
+
partsCount: parts.length,
|
|
1168
|
+
totalChars,
|
|
1169
|
+
applyChunked
|
|
1170
|
+
});
|
|
1171
|
+
let prevLine = prevLineInit;
|
|
1172
|
+
const watcherApi = this.diffScrollWatcher;
|
|
1173
|
+
let suppressedByFlush = false;
|
|
1174
|
+
if (watcherApi && typeof watcherApi.setSuppressed === "function") try {
|
|
1175
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1176
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1177
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1178
|
+
}
|
|
1179
|
+
watcherApi.setSuppressed(true);
|
|
1180
|
+
suppressedByFlush = true;
|
|
1181
|
+
} catch {}
|
|
1182
|
+
if (applyChunked) {
|
|
1183
|
+
log("diff", "flushAppendBufferDiff applying chunked", { partsLen: parts.length });
|
|
1184
|
+
let idx = 0;
|
|
1185
|
+
for (const part of parts) {
|
|
1186
|
+
if (!part) continue;
|
|
1187
|
+
idx += 1;
|
|
1188
|
+
log("diff", "flushAppendBufferDiff chunk", {
|
|
1189
|
+
idx,
|
|
1190
|
+
partLen: part.length,
|
|
1191
|
+
prevLine
|
|
1192
|
+
});
|
|
1193
|
+
const lastColumn$1 = model.getLineMaxColumn(prevLine);
|
|
1194
|
+
const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
|
|
1195
|
+
model.applyEdits([{
|
|
1196
|
+
range: range$1,
|
|
1197
|
+
text: part,
|
|
1198
|
+
forceMoveMarkers: true
|
|
1199
|
+
}]);
|
|
1200
|
+
this.lastKnownModifiedCode = model.getValue();
|
|
1201
|
+
const newLine$1 = model.getLineCount();
|
|
1202
|
+
this.lastKnownModifiedLineCount = newLine$1;
|
|
1203
|
+
await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
|
|
1204
|
+
const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
|
|
1205
|
+
log("diff", "flushAppendBufferDiff chunk metrics", {
|
|
1206
|
+
idx,
|
|
1207
|
+
newLine: newLine$1,
|
|
1208
|
+
prevLine,
|
|
1209
|
+
shouldImmediate: shouldImmediate$1
|
|
1210
|
+
});
|
|
1211
|
+
if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1212
|
+
const computed$3 = this.computedHeight();
|
|
1213
|
+
if (computed$3 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1214
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1215
|
+
this.lastContainer.style.overflow = "auto";
|
|
1216
|
+
}
|
|
1217
|
+
if (shouldImmediate$1) this.scheduleImmediateRevealAfterLayoutDiff(newLine$1);
|
|
1218
|
+
else this.maybeScrollDiffToBottom(newLine$1, prevLine);
|
|
1219
|
+
prevLine = newLine$1;
|
|
1220
|
+
log("diff", "flushAppendBufferDiff chunk applied", {
|
|
1221
|
+
idx,
|
|
1222
|
+
newLine: newLine$1
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
const text = totalText;
|
|
777
1229
|
this.appendBufferDiff.length = 0;
|
|
1230
|
+
prevLine = model.getLineCount();
|
|
1231
|
+
const lastColumn = model.getLineMaxColumn(prevLine);
|
|
1232
|
+
const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
|
|
1233
|
+
model.applyEdits([{
|
|
1234
|
+
range,
|
|
1235
|
+
text,
|
|
1236
|
+
forceMoveMarkers: true
|
|
1237
|
+
}]);
|
|
1238
|
+
this.lastKnownModifiedCode = model.getValue();
|
|
1239
|
+
const newLine = model.getLineCount();
|
|
1240
|
+
this.lastKnownModifiedLineCount = newLine;
|
|
1241
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1242
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1243
|
+
const computed$2 = this.computedHeight();
|
|
1244
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1245
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
1246
|
+
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
1247
|
+
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
1248
|
+
var _editor4, _me2$getModel2, _me2$getScrollTop2;
|
|
1249
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor4 = monaco_shim_exports.editor) === null || _editor4 === void 0 ? void 0 : _editor4.ScrollType);
|
|
1250
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1251
|
+
const me2 = this.diffEditorView.getModifiedEditor();
|
|
1252
|
+
const targetLine = ((_me2$getModel2 = me2.getModel()) === null || _me2$getModel2 === void 0 ? void 0 : _me2$getModel2.getLineCount()) ?? newLine;
|
|
1253
|
+
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
1254
|
+
else me2.revealLine(targetLine);
|
|
1255
|
+
this.lastRevealLineDiff = targetLine;
|
|
1256
|
+
this.shouldAutoScrollDiff = true;
|
|
1257
|
+
this.lastScrollTopDiff = ((_me2$getScrollTop2 = me2.getScrollTop) === null || _me2$getScrollTop2 === void 0 ? void 0 : _me2$getScrollTop2.call(me2)) ?? this.lastScrollTopDiff;
|
|
1258
|
+
} catch {}
|
|
1259
|
+
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
778
1260
|
try {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
model.applyEdits([{
|
|
783
|
-
range,
|
|
784
|
-
text,
|
|
785
|
-
forceMoveMarkers: true
|
|
786
|
-
}]);
|
|
787
|
-
try {
|
|
788
|
-
this.lastKnownModifiedCode = model.getValue();
|
|
789
|
-
} catch {}
|
|
790
|
-
const newLine = model.getLineCount();
|
|
791
|
-
this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
792
|
-
this.lastKnownModifiedLineCount = newLine;
|
|
1261
|
+
var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7;
|
|
1262
|
+
this.shouldAutoScrollDiff = true;
|
|
1263
|
+
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;
|
|
793
1264
|
} catch {}
|
|
794
1265
|
}
|
|
795
1266
|
applyMinimalEditToModel(model, prev, next) {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
} catch {}
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
} catch {}
|
|
1267
|
+
const maxChars = minimalEditMaxChars;
|
|
1268
|
+
const ratio = minimalEditMaxChangeRatio;
|
|
1269
|
+
const maxLen = Math.max(prev.length, next.length);
|
|
1270
|
+
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1271
|
+
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1272
|
+
model.setValue(next);
|
|
1273
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
809
1276
|
const res = computeMinimalEdit(prev, next);
|
|
810
1277
|
if (!res) return;
|
|
811
1278
|
const { start, endPrevIncl, replaceText } = res;
|
|
@@ -817,9 +1284,7 @@ var DiffEditorManager = class {
|
|
|
817
1284
|
text: replaceText,
|
|
818
1285
|
forceMoveMarkers: true
|
|
819
1286
|
}]);
|
|
820
|
-
|
|
821
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
822
|
-
} catch {}
|
|
1287
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
823
1288
|
}
|
|
824
1289
|
appendToModel(model, appendText) {
|
|
825
1290
|
if (!appendText) return;
|
|
@@ -831,9 +1296,7 @@ var DiffEditorManager = class {
|
|
|
831
1296
|
text: appendText,
|
|
832
1297
|
forceMoveMarkers: true
|
|
833
1298
|
}]);
|
|
834
|
-
|
|
835
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
836
|
-
} catch {}
|
|
1299
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
837
1300
|
}
|
|
838
1301
|
};
|
|
839
1302
|
|
|
@@ -847,12 +1310,14 @@ var EditorManager = class {
|
|
|
847
1310
|
_hasScrollBar = false;
|
|
848
1311
|
shouldAutoScroll = true;
|
|
849
1312
|
scrollWatcher = null;
|
|
1313
|
+
scrollWatcherSuppressionTimer = null;
|
|
850
1314
|
lastScrollTop = 0;
|
|
851
1315
|
cachedScrollHeight = null;
|
|
852
1316
|
cachedLineHeight = null;
|
|
853
1317
|
cachedComputedHeight = null;
|
|
854
1318
|
cachedLineCount = null;
|
|
855
1319
|
lastKnownCodeDirty = false;
|
|
1320
|
+
debug = false;
|
|
856
1321
|
measureViewport() {
|
|
857
1322
|
var _this$editorView$getL, _this$editorView, _this$editorView$getS, _this$editorView2, _this$editorView$getS2, _this$editorView3;
|
|
858
1323
|
if (!this.editorView) return null;
|
|
@@ -880,8 +1345,10 @@ var EditorManager = class {
|
|
|
880
1345
|
revealDebounceId = null;
|
|
881
1346
|
revealDebounceMs = defaultRevealDebounceMs;
|
|
882
1347
|
revealIdleTimerId = null;
|
|
1348
|
+
revealTicket = 0;
|
|
883
1349
|
revealStrategyOption;
|
|
884
1350
|
revealBatchOnIdleMsOption;
|
|
1351
|
+
scrollWatcherSuppressionMs = 500;
|
|
885
1352
|
constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, revealDebounceMsOption) {
|
|
886
1353
|
this.options = options;
|
|
887
1354
|
this.maxHeightValue = maxHeightValue;
|
|
@@ -892,6 +1359,21 @@ var EditorManager = class {
|
|
|
892
1359
|
this.autoScrollThresholdLines = autoScrollThresholdLines;
|
|
893
1360
|
this.revealDebounceMsOption = revealDebounceMsOption;
|
|
894
1361
|
}
|
|
1362
|
+
initDebugFlag() {
|
|
1363
|
+
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) {
|
|
1364
|
+
this.debug = Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (this.options && this.options.debug !== void 0) {
|
|
1368
|
+
this.debug = Boolean(this.options.debug);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
this.debug = false;
|
|
1372
|
+
}
|
|
1373
|
+
dlog(...args) {
|
|
1374
|
+
if (!this.debug) return;
|
|
1375
|
+
log("EditorManager", ...args);
|
|
1376
|
+
}
|
|
895
1377
|
hasVerticalScrollbar() {
|
|
896
1378
|
if (!this.editorView) return false;
|
|
897
1379
|
if (this._hasScrollBar) return true;
|
|
@@ -913,19 +1395,38 @@ var EditorManager = class {
|
|
|
913
1395
|
const lineCount = this.cachedLineCount ?? ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getLineCount()) ?? 1;
|
|
914
1396
|
const lineHeight = editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
915
1397
|
const height = Math.min(lineCount * lineHeight + padding, this.maxHeightValue);
|
|
1398
|
+
log("EditorManager.computedHeight", {
|
|
1399
|
+
lineCount,
|
|
1400
|
+
lineHeight,
|
|
1401
|
+
computed: height,
|
|
1402
|
+
maxHeightValue: this.maxHeightValue
|
|
1403
|
+
});
|
|
916
1404
|
return height;
|
|
917
1405
|
}
|
|
918
1406
|
maybeScrollToBottom(targetLine) {
|
|
919
1407
|
this.rafScheduler.schedule("maybe-scroll", () => {
|
|
920
|
-
|
|
1408
|
+
const hasVS = this.hasVerticalScrollbar();
|
|
1409
|
+
this.dlog("maybeScrollToBottom called", {
|
|
1410
|
+
autoScrollOnUpdate: this.autoScrollOnUpdate,
|
|
1411
|
+
shouldAutoScroll: this.shouldAutoScroll,
|
|
1412
|
+
hasVerticalScrollbar: hasVS,
|
|
1413
|
+
targetLine
|
|
1414
|
+
});
|
|
1415
|
+
if (!(this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar())) {
|
|
1416
|
+
this.dlog("maybeScrollToBottom skipped (auto-scroll conditions not met)");
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
921
1419
|
const model = this.editorView.getModel();
|
|
922
1420
|
const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
923
1421
|
const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
|
|
924
1422
|
if (typeof batchMs === "number" && batchMs > 0) {
|
|
925
1423
|
if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
|
|
1424
|
+
const ticket = ++this.revealTicket;
|
|
1425
|
+
this.dlog("scheduled idle reveal ticket=", ticket, "line=", line, "batchMs=", batchMs);
|
|
926
1426
|
this.revealIdleTimerId = setTimeout(() => {
|
|
927
1427
|
this.revealIdleTimerId = null;
|
|
928
|
-
this.
|
|
1428
|
+
this.dlog("idle reveal timer firing, ticket=", ticket, "line=", line);
|
|
1429
|
+
this.performReveal(line, ticket);
|
|
929
1430
|
}, batchMs);
|
|
930
1431
|
return;
|
|
931
1432
|
}
|
|
@@ -936,14 +1437,22 @@ var EditorManager = class {
|
|
|
936
1437
|
const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
|
|
937
1438
|
this.revealDebounceId = setTimeout(() => {
|
|
938
1439
|
this.revealDebounceId = null;
|
|
939
|
-
this.
|
|
1440
|
+
const ticket = ++this.revealTicket;
|
|
1441
|
+
this.dlog("scheduled debounce reveal ticket=", ticket, "line=", line, "ms=", ms);
|
|
1442
|
+
this.performReveal(line, ticket);
|
|
940
1443
|
}, ms);
|
|
941
1444
|
});
|
|
942
1445
|
}
|
|
943
|
-
performReveal(line) {
|
|
1446
|
+
performReveal(line, ticket) {
|
|
944
1447
|
this.rafScheduler.schedule("reveal", () => {
|
|
945
1448
|
var _editor;
|
|
1449
|
+
if (ticket !== this.revealTicket) {
|
|
1450
|
+
this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
this.dlog("performReveal executing, ticket=", ticket, "line=", line);
|
|
946
1454
|
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
1455
|
+
this.dlog("performReveal strategy=", strategy);
|
|
947
1456
|
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
948
1457
|
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
949
1458
|
try {
|
|
@@ -960,11 +1469,59 @@ var EditorManager = class {
|
|
|
960
1469
|
}
|
|
961
1470
|
});
|
|
962
1471
|
}
|
|
1472
|
+
performImmediateReveal(line, ticket) {
|
|
1473
|
+
this.dlog("performImmediateReveal line=", line, "ticket=", ticket);
|
|
1474
|
+
try {
|
|
1475
|
+
var _editor2;
|
|
1476
|
+
if (!this.editorView) return;
|
|
1477
|
+
if (ticket !== this.revealTicket) {
|
|
1478
|
+
this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
1482
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1483
|
+
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
1484
|
+
else this.editorView.revealLine(line);
|
|
1485
|
+
} catch {}
|
|
1486
|
+
try {
|
|
1487
|
+
this.measureViewport();
|
|
1488
|
+
} catch {}
|
|
1489
|
+
}
|
|
1490
|
+
forceReveal(line) {
|
|
1491
|
+
try {
|
|
1492
|
+
var _editor3;
|
|
1493
|
+
if (!this.editorView) return;
|
|
1494
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
1495
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1496
|
+
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
1497
|
+
else this.editorView.revealLine(line);
|
|
1498
|
+
} catch {}
|
|
1499
|
+
try {
|
|
1500
|
+
this.measureViewport();
|
|
1501
|
+
} catch {}
|
|
1502
|
+
try {
|
|
1503
|
+
var _this$editorView4, _this$editorView4$get;
|
|
1504
|
+
this.shouldAutoScroll = true;
|
|
1505
|
+
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;
|
|
1506
|
+
} catch {}
|
|
1507
|
+
}
|
|
1508
|
+
isOverflowAuto() {
|
|
1509
|
+
try {
|
|
1510
|
+
return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
|
|
1511
|
+
} catch {
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
shouldPerformImmediateReveal() {
|
|
1516
|
+
return this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar() && this.isOverflowAuto();
|
|
1517
|
+
}
|
|
963
1518
|
async createEditor(container, code, language, currentTheme) {
|
|
964
|
-
var _this$editorView$getS3, _this$
|
|
1519
|
+
var _this$editorView$getS3, _this$editorView5, _this$editorView$getO, _this$editorView6, _this$editorView$getM, _this$editorView$onDi, _this$editorView7;
|
|
965
1520
|
this.cleanup();
|
|
966
1521
|
this.lastContainer = container;
|
|
967
|
-
|
|
1522
|
+
this.initDebugFlag();
|
|
1523
|
+
this.dlog("createEditor container, maxHeight", this.maxHeightValue);
|
|
1524
|
+
container.style.overflow = "hidden";
|
|
968
1525
|
container.style.maxHeight = this.maxHeightCSS;
|
|
969
1526
|
this.editorView = monaco_shim_exports.editor.create(container, {
|
|
970
1527
|
value: code,
|
|
@@ -995,22 +1552,51 @@ var EditorManager = class {
|
|
|
995
1552
|
}
|
|
996
1553
|
if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
|
|
997
1554
|
this.revealIdleTimerId = null;
|
|
998
|
-
|
|
1555
|
+
const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
|
|
1556
|
+
container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
|
|
1557
|
+
this.editorHeightManager = createHeightManager(container, () => {
|
|
1558
|
+
const computed$2 = this.computedHeight(this.editorView);
|
|
1559
|
+
const clamped = Math.min(computed$2, this.maxHeightValue);
|
|
1560
|
+
return Math.max(clamped, MIN_VISIBLE_HEIGHT);
|
|
1561
|
+
});
|
|
999
1562
|
this.editorHeightManager.update();
|
|
1000
|
-
|
|
1001
|
-
|
|
1563
|
+
const initialComputed = this.computedHeight(this.editorView);
|
|
1564
|
+
if (initialComputed >= this.maxHeightValue - 1) {
|
|
1565
|
+
container.style.height = `${this.maxHeightValue}px`;
|
|
1566
|
+
container.style.overflow = "auto";
|
|
1567
|
+
this.dlog("applied immediate maxHeight on createEditor", this.maxHeightValue);
|
|
1568
|
+
}
|
|
1569
|
+
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;
|
|
1570
|
+
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;
|
|
1002
1571
|
this.cachedComputedHeight = this.computedHeight(this.editorView);
|
|
1003
1572
|
this.cachedLineCount = ((_this$editorView$getM = this.editorView.getModel()) === null || _this$editorView$getM === void 0 ? void 0 : _this$editorView$getM.getLineCount()) ?? null;
|
|
1004
|
-
(_this$editorView$onDi = (_this$
|
|
1573
|
+
(_this$editorView$onDi = (_this$editorView7 = this.editorView).onDidContentSizeChange) === null || _this$editorView$onDi === void 0 || _this$editorView$onDi.call(_this$editorView7, () => {
|
|
1005
1574
|
this._hasScrollBar = false;
|
|
1006
1575
|
this.rafScheduler.schedule("content-size-change", () => {
|
|
1007
1576
|
try {
|
|
1008
|
-
var _this$
|
|
1009
|
-
this.
|
|
1010
|
-
|
|
1011
|
-
|
|
1577
|
+
var _this$editorView8, _this$editorHeightMan, _this$editorHeightMan2;
|
|
1578
|
+
this.dlog("content-size-change frame");
|
|
1579
|
+
const m = this.measureViewport();
|
|
1580
|
+
this.dlog("content-size-change measure", m);
|
|
1581
|
+
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;
|
|
1582
|
+
if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
|
|
1583
|
+
this.dlog("content-size-change skipped height update (suppressed)");
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
this.dlog("content-size-change calling heightManager.update");
|
|
1012
1587
|
(_this$editorHeightMan2 = this.editorHeightManager) === null || _this$editorHeightMan2 === void 0 || _this$editorHeightMan2.update();
|
|
1013
|
-
|
|
1588
|
+
const computed$2 = this.computedHeight(this.editorView);
|
|
1589
|
+
if (this.lastContainer) {
|
|
1590
|
+
const prevOverflow = this.lastContainer.style.overflow;
|
|
1591
|
+
const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
1592
|
+
if (prevOverflow !== newOverflow) {
|
|
1593
|
+
this.lastContainer.style.overflow = newOverflow;
|
|
1594
|
+
if (newOverflow === "auto" && this.shouldAutoScroll) this.maybeScrollToBottom();
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
} catch (err) {
|
|
1598
|
+
error("EditorManager", "content-size-change error", err);
|
|
1599
|
+
}
|
|
1014
1600
|
});
|
|
1015
1601
|
});
|
|
1016
1602
|
this.editorView.onDidChangeModelContent(() => {
|
|
@@ -1041,15 +1627,67 @@ var EditorManager = class {
|
|
|
1041
1627
|
}
|
|
1042
1628
|
syncLastKnownCode() {
|
|
1043
1629
|
if (!this.editorView || !this.lastKnownCodeDirty) return;
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1630
|
+
const model = this.editorView.getModel();
|
|
1631
|
+
if (model) {
|
|
1632
|
+
this.lastKnownCode = model.getValue();
|
|
1633
|
+
this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
|
|
1634
|
+
}
|
|
1635
|
+
this.lastKnownCodeDirty = false;
|
|
1636
|
+
}
|
|
1637
|
+
suppressScrollWatcher(ms) {
|
|
1638
|
+
if (!this.scrollWatcher || typeof this.scrollWatcher.setSuppressed !== "function") return;
|
|
1639
|
+
this.dlog("suppressScrollWatcher", ms);
|
|
1640
|
+
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1641
|
+
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1642
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1643
|
+
}
|
|
1644
|
+
this.scrollWatcher.setSuppressed(true);
|
|
1645
|
+
this.scrollWatcherSuppressionTimer = setTimeout(() => {
|
|
1646
|
+
if (this.scrollWatcher && typeof this.scrollWatcher.setSuppressed === "function") {
|
|
1647
|
+
this.scrollWatcher.setSuppressed(false);
|
|
1648
|
+
this.dlog("suppressScrollWatcher cleared");
|
|
1049
1649
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1650
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1651
|
+
}, ms);
|
|
1652
|
+
}
|
|
1653
|
+
scheduleImmediateRevealAfterLayout(line) {
|
|
1654
|
+
const ticket = ++this.revealTicket;
|
|
1655
|
+
this.dlog("scheduleImmediateRevealAfterLayout ticket=", ticket, "line=", line);
|
|
1656
|
+
this.rafScheduler.schedule("immediate-reveal", async () => {
|
|
1657
|
+
try {
|
|
1658
|
+
const target = this.editorView && this.editorHeightManager ? Math.min(this.computedHeight(this.editorView), this.maxHeightValue) : -1;
|
|
1659
|
+
if (target !== -1 && this.editorHeightManager) await this.waitForHeightApplied(target, 500);
|
|
1660
|
+
else await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r())));
|
|
1661
|
+
this.dlog("running delayed immediate reveal", "ticket=", ticket, "line=", line);
|
|
1662
|
+
this.performImmediateReveal(line, ticket);
|
|
1663
|
+
} catch (err) {
|
|
1664
|
+
error("EditorManager", "scheduleImmediateRevealAfterLayout error", err);
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
waitForHeightApplied(target, timeoutMs = 500) {
|
|
1669
|
+
return new Promise((resolve) => {
|
|
1670
|
+
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1671
|
+
const check = () => {
|
|
1672
|
+
try {
|
|
1673
|
+
var _this$editorHeightMan3, _this$editorHeightMan4;
|
|
1674
|
+
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;
|
|
1675
|
+
if (last !== -1 && Math.abs(last - target) <= 12) {
|
|
1676
|
+
this.dlog("waitForHeightApplied satisfied", last, "target=", target);
|
|
1677
|
+
resolve();
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1681
|
+
if (now - start > timeoutMs) {
|
|
1682
|
+
log("EditorManager", "waitForHeightApplied timeout", last, "target=", target);
|
|
1683
|
+
resolve();
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
} catch {}
|
|
1687
|
+
requestAnimationFrame(check);
|
|
1688
|
+
};
|
|
1689
|
+
check();
|
|
1690
|
+
});
|
|
1053
1691
|
}
|
|
1054
1692
|
updateCode(newCode, codeLanguage) {
|
|
1055
1693
|
this.pendingUpdate = {
|
|
@@ -1073,7 +1711,13 @@ var EditorManager = class {
|
|
|
1073
1711
|
this.lastKnownCode = newCode;
|
|
1074
1712
|
const newLineCount$1 = model.getLineCount();
|
|
1075
1713
|
this.cachedLineCount = newLineCount$1;
|
|
1076
|
-
if (newLineCount$1 !== prevLineCount$1)
|
|
1714
|
+
if (newLineCount$1 !== prevLineCount$1) {
|
|
1715
|
+
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1716
|
+
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1717
|
+
const computed$2 = this.computedHeight(this.editorView);
|
|
1718
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1719
|
+
this.forceReveal(newLineCount$1);
|
|
1720
|
+
}
|
|
1077
1721
|
return;
|
|
1078
1722
|
}
|
|
1079
1723
|
const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() : this.lastKnownCode ?? this.editorView.getValue();
|
|
@@ -1089,7 +1733,12 @@ var EditorManager = class {
|
|
|
1089
1733
|
this.lastKnownCode = newCode;
|
|
1090
1734
|
const newLineCount = model.getLineCount();
|
|
1091
1735
|
this.cachedLineCount = newLineCount;
|
|
1092
|
-
if (newLineCount !== prevLineCount)
|
|
1736
|
+
if (newLineCount !== prevLineCount) {
|
|
1737
|
+
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1738
|
+
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1739
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayout(newLineCount);
|
|
1740
|
+
else this.maybeScrollToBottom(newLineCount);
|
|
1741
|
+
}
|
|
1093
1742
|
}
|
|
1094
1743
|
appendCode(appendText, codeLanguage) {
|
|
1095
1744
|
if (!this.editorView) return;
|
|
@@ -1109,21 +1758,19 @@ var EditorManager = class {
|
|
|
1109
1758
|
if (!this.editorView) return;
|
|
1110
1759
|
const model = this.editorView.getModel();
|
|
1111
1760
|
if (!model) return;
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
} catch {}
|
|
1761
|
+
const maxChars = minimalEditMaxChars;
|
|
1762
|
+
const ratio = minimalEditMaxChangeRatio;
|
|
1763
|
+
const maxLen = Math.max(prev.length, next.length);
|
|
1764
|
+
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1765
|
+
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1766
|
+
const prevLineCount = model.getLineCount();
|
|
1767
|
+
model.setValue(next);
|
|
1768
|
+
this.lastKnownCode = next;
|
|
1769
|
+
const newLineCount = model.getLineCount();
|
|
1770
|
+
this.cachedLineCount = newLineCount;
|
|
1771
|
+
if (newLineCount !== prevLineCount) this.maybeScrollToBottom(newLineCount);
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1127
1774
|
const res = computeMinimalEdit(prev, next);
|
|
1128
1775
|
if (!res) return;
|
|
1129
1776
|
const { start, endPrevIncl, replaceText } = res;
|
|
@@ -1167,7 +1814,14 @@ var EditorManager = class {
|
|
|
1167
1814
|
const newLineCount = model.getLineCount();
|
|
1168
1815
|
if (lastLine !== newLineCount) {
|
|
1169
1816
|
this.cachedLineCount = newLineCount;
|
|
1170
|
-
this.
|
|
1817
|
+
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1818
|
+
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1819
|
+
const computed$2 = this.computedHeight(this.editorView);
|
|
1820
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1821
|
+
if (shouldImmediate) try {
|
|
1822
|
+
this.forceReveal(newLineCount);
|
|
1823
|
+
} catch {}
|
|
1824
|
+
else this.maybeScrollToBottom(newLineCount);
|
|
1171
1825
|
}
|
|
1172
1826
|
}
|
|
1173
1827
|
setLanguage(language, languages$1) {
|
|
@@ -1185,16 +1839,33 @@ var EditorManager = class {
|
|
|
1185
1839
|
this.rafScheduler.cancel("update");
|
|
1186
1840
|
this.rafScheduler.cancel("sync-last-known");
|
|
1187
1841
|
this.rafScheduler.cancel("content-size-change");
|
|
1842
|
+
this.rafScheduler.cancel("maybe-scroll");
|
|
1843
|
+
this.rafScheduler.cancel("reveal");
|
|
1844
|
+
this.rafScheduler.cancel("immediate-reveal");
|
|
1845
|
+
this.rafScheduler.cancel("maybe-resume");
|
|
1188
1846
|
this.pendingUpdate = null;
|
|
1189
1847
|
this.rafScheduler.cancel("append");
|
|
1190
1848
|
this.appendBufferScheduled = false;
|
|
1191
1849
|
this.appendBuffer.length = 0;
|
|
1850
|
+
if (this.revealDebounceId != null) {
|
|
1851
|
+
clearTimeout(this.revealDebounceId);
|
|
1852
|
+
this.revealDebounceId = null;
|
|
1853
|
+
}
|
|
1854
|
+
if (this.revealIdleTimerId != null) {
|
|
1855
|
+
clearTimeout(this.revealIdleTimerId);
|
|
1856
|
+
this.revealIdleTimerId = null;
|
|
1857
|
+
}
|
|
1858
|
+
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1859
|
+
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1860
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1861
|
+
}
|
|
1192
1862
|
if (this.editorView) {
|
|
1193
1863
|
this.editorView.dispose();
|
|
1194
1864
|
this.editorView = null;
|
|
1195
1865
|
}
|
|
1196
1866
|
this.lastKnownCode = null;
|
|
1197
1867
|
if (this.lastContainer) {
|
|
1868
|
+
this.lastContainer.style.minHeight = "";
|
|
1198
1869
|
this.lastContainer.innerHTML = "";
|
|
1199
1870
|
this.lastContainer = null;
|
|
1200
1871
|
}
|
|
@@ -1212,13 +1883,27 @@ var EditorManager = class {
|
|
|
1212
1883
|
this.pendingUpdate = null;
|
|
1213
1884
|
this.rafScheduler.cancel("sync-last-known");
|
|
1214
1885
|
if (this.scrollWatcher) {
|
|
1215
|
-
|
|
1886
|
+
try {
|
|
1887
|
+
this.scrollWatcher.dispose();
|
|
1888
|
+
} catch {}
|
|
1216
1889
|
this.scrollWatcher = null;
|
|
1217
1890
|
}
|
|
1218
1891
|
if (this.revealDebounceId != null) {
|
|
1219
1892
|
clearTimeout(this.revealDebounceId);
|
|
1220
1893
|
this.revealDebounceId = null;
|
|
1221
1894
|
}
|
|
1895
|
+
if (this.revealIdleTimerId != null) {
|
|
1896
|
+
clearTimeout(this.revealIdleTimerId);
|
|
1897
|
+
this.revealIdleTimerId = null;
|
|
1898
|
+
}
|
|
1899
|
+
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1900
|
+
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1901
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1902
|
+
}
|
|
1903
|
+
this.rafScheduler.cancel("maybe-scroll");
|
|
1904
|
+
this.rafScheduler.cancel("reveal");
|
|
1905
|
+
this.rafScheduler.cancel("immediate-reveal");
|
|
1906
|
+
this.rafScheduler.cancel("maybe-resume");
|
|
1222
1907
|
this._hasScrollBar = false;
|
|
1223
1908
|
this.shouldAutoScroll = !!this.autoScrollInitial;
|
|
1224
1909
|
this.lastScrollTop = 0;
|
|
@@ -1525,6 +2210,7 @@ let RevealStrategy = /* @__PURE__ */ function(RevealStrategy$1) {
|
|
|
1525
2210
|
* getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
|
|
1526
2211
|
* getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
|
|
1527
2212
|
* getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
|
|
2213
|
+
* getCode: () => string | { original: string, modified: string } | null,
|
|
1528
2214
|
* }} 返回对象包含以下方法和属性:
|
|
1529
2215
|
*
|
|
1530
2216
|
* @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
|
|
@@ -1544,6 +2230,7 @@ let RevealStrategy = /* @__PURE__ */ function(RevealStrategy$1) {
|
|
|
1544
2230
|
* @property {Function} getEditorView - 获取当前编辑器实例
|
|
1545
2231
|
* @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
|
|
1546
2232
|
* @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
|
|
2233
|
+
* @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
|
|
1547
2234
|
*
|
|
1548
2235
|
* @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
|
|
1549
2236
|
*
|
|
@@ -1704,9 +2391,7 @@ function useMonaco(monacoOptions = {}) {
|
|
|
1704
2391
|
flush: "post",
|
|
1705
2392
|
immediate: true
|
|
1706
2393
|
});
|
|
1707
|
-
|
|
1708
|
-
if (editorView) lastKnownCode = editorView.getValue();
|
|
1709
|
-
} catch {}
|
|
2394
|
+
if (editorView) lastKnownCode = editorView.getValue();
|
|
1710
2395
|
return editorView;
|
|
1711
2396
|
}
|
|
1712
2397
|
function computedHeight(editorView$1) {
|
|
@@ -2050,7 +2735,26 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2050
2735
|
return monaco_shim_exports;
|
|
2051
2736
|
},
|
|
2052
2737
|
setUpdateThrottleMs,
|
|
2053
|
-
getUpdateThrottleMs
|
|
2738
|
+
getUpdateThrottleMs,
|
|
2739
|
+
getCode() {
|
|
2740
|
+
if (editorView) try {
|
|
2741
|
+
var _editorView$getModel;
|
|
2742
|
+
return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
|
|
2743
|
+
} catch {
|
|
2744
|
+
return null;
|
|
2745
|
+
}
|
|
2746
|
+
if (diffEditorView || originalModel && modifiedModel) try {
|
|
2747
|
+
const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
|
|
2748
|
+
const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
|
|
2749
|
+
return {
|
|
2750
|
+
original,
|
|
2751
|
+
modified
|
|
2752
|
+
};
|
|
2753
|
+
} catch {
|
|
2754
|
+
return null;
|
|
2755
|
+
}
|
|
2756
|
+
return null;
|
|
2757
|
+
}
|
|
2054
2758
|
};
|
|
2055
2759
|
}
|
|
2056
2760
|
|