stream-monaco 0.0.3 → 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/dist/index.cjs +482 -153
- package/dist/index.js +482 -153
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -231,18 +231,18 @@ const monaco = monaco_editor;
|
|
|
231
231
|
//#endregion
|
|
232
232
|
//#region src/utils/logger.ts
|
|
233
233
|
let seq = 0;
|
|
234
|
-
const
|
|
234
|
+
const DEBUG = (() => {
|
|
235
235
|
try {
|
|
236
236
|
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) return Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
237
237
|
try {
|
|
238
238
|
const proc = node_process.default;
|
|
239
|
-
if (proc && proc.env && proc.env.NODE_ENV
|
|
239
|
+
if (proc && proc.env && proc.env.NODE_ENV === "production") return false;
|
|
240
240
|
} catch {}
|
|
241
241
|
} catch {}
|
|
242
|
-
return
|
|
242
|
+
return true;
|
|
243
243
|
})();
|
|
244
244
|
function log(tag, ...args) {
|
|
245
|
-
if (!
|
|
245
|
+
if (!DEBUG) return;
|
|
246
246
|
try {
|
|
247
247
|
seq += 1;
|
|
248
248
|
const id = `#${seq}`;
|
|
@@ -255,7 +255,7 @@ function log(tag, ...args) {
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
function error(tag, ...args) {
|
|
258
|
-
if (!
|
|
258
|
+
if (!DEBUG) return;
|
|
259
259
|
try {
|
|
260
260
|
console.error(`[${tag}]`, ...args);
|
|
261
261
|
} catch (err) {
|
|
@@ -382,41 +382,45 @@ function createRafScheduler(timeSource) {
|
|
|
382
382
|
//#region src/utils/scroll.ts
|
|
383
383
|
function createScrollWatcherForEditor(ed, opts) {
|
|
384
384
|
var _ed$getScrollTop, _ed$onDidScrollChange;
|
|
385
|
-
const DEBUG = (() => {
|
|
386
|
-
try {
|
|
387
|
-
if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) return Boolean(window.__STREAM_MONACO_DEBUG__);
|
|
388
|
-
try {
|
|
389
|
-
const proc = node_process.default;
|
|
390
|
-
if (proc && proc.env && proc.env.NODE_ENV === "production") return false;
|
|
391
|
-
} catch {}
|
|
392
|
-
} catch {}
|
|
393
|
-
return true;
|
|
394
|
-
})();
|
|
395
385
|
const initial = ((_ed$getScrollTop = ed.getScrollTop) === null || _ed$getScrollTop === void 0 ? void 0 : _ed$getScrollTop.call(ed)) ?? 0;
|
|
396
386
|
opts.setLast(initial);
|
|
397
|
-
|
|
387
|
+
log("scrollWatcher", "initial scrollTop=", initial);
|
|
398
388
|
let suppressedExternally = false;
|
|
399
389
|
const THRESHOLD_PX = 6;
|
|
390
|
+
let domNode = null;
|
|
391
|
+
let interactionListener = null;
|
|
400
392
|
const listener = (e) => {
|
|
401
393
|
var _ed$getScrollTop2;
|
|
402
394
|
if (suppressedExternally) {
|
|
403
|
-
|
|
395
|
+
log("scrollWatcher", "suppressedExternally, ignoring event");
|
|
404
396
|
return;
|
|
405
397
|
}
|
|
406
398
|
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;
|
|
407
399
|
const delta = currentTop - opts.getLast();
|
|
408
400
|
opts.setLast(currentTop);
|
|
409
401
|
if (Math.abs(delta) < THRESHOLD_PX) {
|
|
410
|
-
|
|
402
|
+
log("scrollWatcher", "small delta ignored", delta);
|
|
403
|
+
try {
|
|
404
|
+
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
405
|
+
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
406
|
+
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
407
|
+
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
408
|
+
const distance = scrollHeight - (currentTop + viewportH);
|
|
409
|
+
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
410
|
+
log("scrollWatcher", "small delta but at bottom, maybe resume", { distance });
|
|
411
|
+
opts.onMaybeResume();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
} catch {}
|
|
411
415
|
return;
|
|
412
416
|
}
|
|
413
|
-
|
|
417
|
+
log("scrollWatcher", "delta=", delta, "currentTop=", currentTop);
|
|
414
418
|
if (delta < 0) {
|
|
415
|
-
|
|
419
|
+
log("scrollWatcher", "pause detected delta=", delta);
|
|
416
420
|
opts.onPause();
|
|
417
421
|
return;
|
|
418
422
|
}
|
|
419
|
-
|
|
423
|
+
log("scrollWatcher", "maybe resume delta=", delta);
|
|
420
424
|
opts.onMaybeResume();
|
|
421
425
|
};
|
|
422
426
|
const disp = ((_ed$onDidScrollChange = ed.onDidScrollChange) === null || _ed$onDidScrollChange === void 0 ? void 0 : _ed$onDidScrollChange.call(ed, listener)) ?? null;
|
|
@@ -426,11 +430,56 @@ function createScrollWatcherForEditor(ed, opts) {
|
|
|
426
430
|
if (disp && typeof disp.dispose === "function") disp.dispose();
|
|
427
431
|
else if (typeof disp === "function") disp();
|
|
428
432
|
} catch {}
|
|
429
|
-
|
|
433
|
+
log("scrollWatcher", "dispose");
|
|
430
434
|
},
|
|
431
435
|
setSuppressed(v) {
|
|
432
|
-
|
|
433
|
-
if (
|
|
436
|
+
const newVal = !!v;
|
|
437
|
+
if (newVal === suppressedExternally) return;
|
|
438
|
+
suppressedExternally = newVal;
|
|
439
|
+
log("scrollWatcher", "setSuppressed =>", suppressedExternally);
|
|
440
|
+
try {
|
|
441
|
+
if (!domNode && typeof ed.getDomNode === "function") domNode = ed.getDomNode();
|
|
442
|
+
if (suppressedExternally && domNode) {
|
|
443
|
+
if (!interactionListener) {
|
|
444
|
+
interactionListener = () => {
|
|
445
|
+
try {
|
|
446
|
+
var _ed$getScrollTop3;
|
|
447
|
+
log("scrollWatcher", "user interaction detected while suppressed, cancelling suppression");
|
|
448
|
+
opts.onPause();
|
|
449
|
+
suppressedExternally = false;
|
|
450
|
+
const cur = ((_ed$getScrollTop3 = ed.getScrollTop) === null || _ed$getScrollTop3 === void 0 ? void 0 : _ed$getScrollTop3.call(ed)) ?? 0;
|
|
451
|
+
opts.setLast(cur);
|
|
452
|
+
try {
|
|
453
|
+
const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
|
|
454
|
+
const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
|
|
455
|
+
const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
|
|
456
|
+
if (typeof scrollHeight === "number" && typeof viewportH === "number") {
|
|
457
|
+
const distance = scrollHeight - (cur + viewportH);
|
|
458
|
+
if (distance <= Math.max(THRESHOLD_PX, 0)) {
|
|
459
|
+
log("scrollWatcher", "interaction moved to bottom, maybe resume", { distance });
|
|
460
|
+
opts.onMaybeResume();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
} catch {}
|
|
464
|
+
if (domNode && interactionListener) {
|
|
465
|
+
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
466
|
+
domNode.removeEventListener("pointerdown", interactionListener);
|
|
467
|
+
domNode.removeEventListener("touchstart", interactionListener);
|
|
468
|
+
}
|
|
469
|
+
interactionListener = null;
|
|
470
|
+
} catch {}
|
|
471
|
+
};
|
|
472
|
+
domNode.addEventListener("wheel", interactionListener, { passive: true });
|
|
473
|
+
domNode.addEventListener("pointerdown", interactionListener);
|
|
474
|
+
domNode.addEventListener("touchstart", interactionListener);
|
|
475
|
+
}
|
|
476
|
+
} else if (domNode && interactionListener) {
|
|
477
|
+
domNode.removeEventListener("wheel", interactionListener, { passive: true });
|
|
478
|
+
domNode.removeEventListener("pointerdown", interactionListener);
|
|
479
|
+
domNode.removeEventListener("touchstart", interactionListener);
|
|
480
|
+
interactionListener = null;
|
|
481
|
+
}
|
|
482
|
+
} catch {}
|
|
434
483
|
}
|
|
435
484
|
};
|
|
436
485
|
return api;
|
|
@@ -478,11 +527,14 @@ var DiffEditorManager = class {
|
|
|
478
527
|
};
|
|
479
528
|
}
|
|
480
529
|
lastRevealLineDiff = null;
|
|
530
|
+
revealTicketDiff = 0;
|
|
481
531
|
revealDebounceIdDiff = null;
|
|
482
532
|
revealDebounceMs = defaultRevealDebounceMs;
|
|
483
533
|
revealIdleTimerIdDiff = null;
|
|
484
534
|
revealStrategyOption;
|
|
485
535
|
revealBatchOnIdleMsOption;
|
|
536
|
+
scrollWatcherSuppressionMs = 500;
|
|
537
|
+
diffScrollWatcherSuppressionTimer = null;
|
|
486
538
|
appendBufferDiff = [];
|
|
487
539
|
appendBufferDiffScheduled = false;
|
|
488
540
|
rafScheduler = createRafScheduler();
|
|
@@ -512,6 +564,26 @@ var DiffEditorManager = class {
|
|
|
512
564
|
const desired = Math.max(fromLines, scrollH);
|
|
513
565
|
return Math.min(desired, this.maxHeightValue);
|
|
514
566
|
}
|
|
567
|
+
isOverflowAutoDiff() {
|
|
568
|
+
return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
|
|
569
|
+
}
|
|
570
|
+
shouldPerformImmediateRevealDiff() {
|
|
571
|
+
return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
|
|
572
|
+
}
|
|
573
|
+
suppressScrollWatcherDiff(ms) {
|
|
574
|
+
if (!this.diffScrollWatcher || typeof this.diffScrollWatcher.setSuppressed !== "function") return;
|
|
575
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
576
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
577
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
578
|
+
}
|
|
579
|
+
this.diffScrollWatcher.setSuppressed(true);
|
|
580
|
+
this.diffScrollWatcherSuppressionTimer = setTimeout(() => {
|
|
581
|
+
try {
|
|
582
|
+
this.diffScrollWatcher.setSuppressed(false);
|
|
583
|
+
} catch {}
|
|
584
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
585
|
+
}, ms);
|
|
586
|
+
}
|
|
515
587
|
hasVerticalScrollbarModified() {
|
|
516
588
|
if (!this.diffEditorView) return false;
|
|
517
589
|
if (this._hasScrollBar) return true;
|
|
@@ -531,21 +603,56 @@ var DiffEditorManager = class {
|
|
|
531
603
|
}
|
|
532
604
|
maybeScrollDiffToBottom(targetLine, prevLineOverride) {
|
|
533
605
|
this.rafScheduler.schedule("maybe-scroll-diff", () => {
|
|
606
|
+
log("diff", "maybeScrollDiffToBottom called", {
|
|
607
|
+
targetLine,
|
|
608
|
+
prevLineOverride,
|
|
609
|
+
diffAutoScroll: this.diffAutoScroll,
|
|
610
|
+
autoScrollOnUpdate: this.autoScrollOnUpdate,
|
|
611
|
+
shouldAutoScrollDiff: this.shouldAutoScrollDiff
|
|
612
|
+
});
|
|
534
613
|
if (!this.diffEditorView) return;
|
|
535
|
-
|
|
614
|
+
const hasV = this.hasVerticalScrollbarModified();
|
|
615
|
+
log("diff", "hasVerticalScrollbarModified ->", hasV);
|
|
616
|
+
if (!(this.diffAutoScroll && this.autoScrollOnUpdate && this.shouldAutoScrollDiff && hasV)) return;
|
|
536
617
|
const me = this.diffEditorView.getModifiedEditor();
|
|
537
618
|
const model = me.getModel();
|
|
538
619
|
const currentLine = (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
539
620
|
const line = targetLine ?? currentLine;
|
|
540
621
|
const prevLine = typeof prevLineOverride === "number" ? prevLineOverride : this.lastKnownModifiedLineCount ?? -1;
|
|
622
|
+
log("diff", "scroll metrics", {
|
|
623
|
+
prevLine,
|
|
624
|
+
currentLine,
|
|
625
|
+
line,
|
|
626
|
+
lastRevealLineDiff: this.lastRevealLineDiff
|
|
627
|
+
});
|
|
541
628
|
if (prevLine !== -1 && prevLine === currentLine && line === currentLine) return;
|
|
542
629
|
if (this.lastRevealLineDiff !== null && this.lastRevealLineDiff === line) return;
|
|
543
630
|
const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
|
|
631
|
+
log("diff", "reveal timing", {
|
|
632
|
+
batchMs,
|
|
633
|
+
revealDebounceMs: this.revealDebounceMs,
|
|
634
|
+
revealDebounceMsOption: this.revealDebounceMsOption
|
|
635
|
+
});
|
|
544
636
|
if (typeof batchMs === "number" && batchMs > 0) {
|
|
637
|
+
if (hasV) {
|
|
638
|
+
const ticket$1 = ++this.revealTicketDiff;
|
|
639
|
+
log("diff", "has scrollbar -> immediate ticketed reveal", {
|
|
640
|
+
ticket: ticket$1,
|
|
641
|
+
line
|
|
642
|
+
});
|
|
643
|
+
this.performRevealDiffTicketed(line, ticket$1);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
545
646
|
if (this.revealIdleTimerIdDiff != null) clearTimeout(this.revealIdleTimerIdDiff);
|
|
647
|
+
const ticket = ++this.revealTicketDiff;
|
|
648
|
+
log("diff", "scheduling idle reveal", {
|
|
649
|
+
ticket,
|
|
650
|
+
batchMs,
|
|
651
|
+
line
|
|
652
|
+
});
|
|
546
653
|
this.revealIdleTimerIdDiff = setTimeout(() => {
|
|
547
654
|
this.revealIdleTimerIdDiff = null;
|
|
548
|
-
this.
|
|
655
|
+
this.performRevealDiffTicketed(line, ticket);
|
|
549
656
|
}, batchMs);
|
|
550
657
|
return;
|
|
551
658
|
}
|
|
@@ -556,14 +663,32 @@ var DiffEditorManager = class {
|
|
|
556
663
|
const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
|
|
557
664
|
this.revealDebounceIdDiff = setTimeout(() => {
|
|
558
665
|
this.revealDebounceIdDiff = null;
|
|
559
|
-
this.
|
|
666
|
+
const ticket = ++this.revealTicketDiff;
|
|
667
|
+
log("diff", "debounced reveal firing", {
|
|
668
|
+
ticket,
|
|
669
|
+
line
|
|
670
|
+
});
|
|
671
|
+
this.performRevealDiffTicketed(line, ticket);
|
|
560
672
|
}, ms);
|
|
561
673
|
this.lastKnownModifiedLineCount = currentLine;
|
|
562
674
|
});
|
|
563
675
|
}
|
|
564
|
-
|
|
676
|
+
performRevealDiffTicketed(line, ticket) {
|
|
565
677
|
this.rafScheduler.schedule("revealDiff", () => {
|
|
566
678
|
var _editor;
|
|
679
|
+
if (this.diffScrollWatcher) {
|
|
680
|
+
log("diff", "performRevealDiffTicketed - suppressing watcher", {
|
|
681
|
+
ticket,
|
|
682
|
+
line,
|
|
683
|
+
ms: this.scrollWatcherSuppressionMs
|
|
684
|
+
});
|
|
685
|
+
this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs);
|
|
686
|
+
}
|
|
687
|
+
if (ticket !== this.revealTicketDiff) return;
|
|
688
|
+
log("diff", "performRevealDiffTicketed - performing reveal", {
|
|
689
|
+
ticket,
|
|
690
|
+
line
|
|
691
|
+
});
|
|
567
692
|
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
568
693
|
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
569
694
|
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
@@ -581,13 +706,71 @@ var DiffEditorManager = class {
|
|
|
581
706
|
} catch {}
|
|
582
707
|
}
|
|
583
708
|
this.lastRevealLineDiff = line;
|
|
709
|
+
log("diff", "performRevealDiffTicketed - revealed", {
|
|
710
|
+
line,
|
|
711
|
+
lastRevealLineDiff: this.lastRevealLineDiff
|
|
712
|
+
});
|
|
713
|
+
try {
|
|
714
|
+
var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2;
|
|
715
|
+
this.shouldAutoScrollDiff = true;
|
|
716
|
+
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;
|
|
717
|
+
} catch {}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
performImmediateRevealDiff(line, ticket) {
|
|
721
|
+
var _editor2;
|
|
722
|
+
if (!this.diffEditorView) return;
|
|
723
|
+
if (ticket !== this.revealTicketDiff) return;
|
|
724
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
725
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
726
|
+
const me = this.diffEditorView.getModifiedEditor();
|
|
727
|
+
if (typeof immediate !== "undefined") me.revealLine(line, immediate);
|
|
728
|
+
else me.revealLine(line);
|
|
729
|
+
this.measureViewportDiff();
|
|
730
|
+
log("diff", "performImmediateRevealDiff", {
|
|
731
|
+
line,
|
|
732
|
+
ticket
|
|
733
|
+
});
|
|
734
|
+
try {
|
|
735
|
+
var _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
|
|
736
|
+
this.shouldAutoScrollDiff = true;
|
|
737
|
+
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;
|
|
738
|
+
} catch {}
|
|
739
|
+
}
|
|
740
|
+
scheduleImmediateRevealAfterLayoutDiff(line) {
|
|
741
|
+
const ticket = ++this.revealTicketDiff;
|
|
742
|
+
this.rafScheduler.schedule("immediate-reveal-diff", async () => {
|
|
743
|
+
const target = this.diffEditorView && this.diffHeightManager ? Math.min(this.computedHeight(), this.maxHeightValue) : -1;
|
|
744
|
+
if (target !== -1 && this.diffHeightManager) {
|
|
745
|
+
if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
|
|
746
|
+
await this.waitForHeightAppliedDiff(target);
|
|
747
|
+
}
|
|
748
|
+
this.performImmediateRevealDiff(line, ticket);
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
waitForHeightAppliedDiff(target, timeoutMs = 500) {
|
|
752
|
+
return new Promise((resolve) => {
|
|
753
|
+
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
754
|
+
const check = () => {
|
|
755
|
+
const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
|
|
756
|
+
if (applied >= target - 1) {
|
|
757
|
+
resolve();
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
|
|
761
|
+
resolve();
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
requestAnimationFrame(check);
|
|
765
|
+
};
|
|
766
|
+
check();
|
|
584
767
|
});
|
|
585
768
|
}
|
|
586
769
|
async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
|
|
587
770
|
var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
|
|
588
771
|
this.cleanup();
|
|
589
772
|
this.lastContainer = container;
|
|
590
|
-
container.style.overflow = "
|
|
773
|
+
container.style.overflow = "hidden";
|
|
591
774
|
container.style.maxHeight = this.maxHeightCSS;
|
|
592
775
|
const lang = processedLanguage(language) || language;
|
|
593
776
|
this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
|
|
@@ -636,13 +819,23 @@ var DiffEditorManager = class {
|
|
|
636
819
|
}
|
|
637
820
|
});
|
|
638
821
|
}
|
|
639
|
-
|
|
822
|
+
log("diff", "createDiffEditor", {
|
|
823
|
+
autoScrollInitial: this.autoScrollInitial,
|
|
824
|
+
diffAutoScroll: this.diffAutoScroll
|
|
825
|
+
});
|
|
826
|
+
const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
|
|
827
|
+
container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
|
|
640
828
|
if (this.diffHeightManager) {
|
|
641
829
|
this.diffHeightManager.dispose();
|
|
642
830
|
this.diffHeightManager = null;
|
|
643
831
|
}
|
|
644
832
|
this.diffHeightManager = createHeightManager(container, () => this.computedHeight());
|
|
645
833
|
this.diffHeightManager.update();
|
|
834
|
+
const initialComputed = this.computedHeight();
|
|
835
|
+
if (initialComputed >= this.maxHeightValue - 1) {
|
|
836
|
+
container.style.height = `${this.maxHeightValue}px`;
|
|
837
|
+
container.style.overflow = "auto";
|
|
838
|
+
}
|
|
646
839
|
const me = this.diffEditorView.getModifiedEditor();
|
|
647
840
|
this.cachedScrollHeightDiff = ((_me$getScrollHeight2 = me.getScrollHeight) === null || _me$getScrollHeight2 === void 0 ? void 0 : _me$getScrollHeight2.call(me)) ?? null;
|
|
648
841
|
this.cachedLineHeightDiff = ((_me$getOption = me.getOption) === null || _me$getOption === void 0 ? void 0 : _me$getOption.call(me, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
|
|
@@ -652,33 +845,54 @@ var DiffEditorManager = class {
|
|
|
652
845
|
(_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
|
|
653
846
|
this._hasScrollBar = false;
|
|
654
847
|
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
848
|
+
var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag, _this$diffHeightManag2;
|
|
849
|
+
this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
|
|
850
|
+
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;
|
|
851
|
+
this.cachedComputedHeightDiff = this.computedHeight();
|
|
852
|
+
if ((_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 ? void 0 : _this$diffHeightManag.isSuppressed()) return;
|
|
853
|
+
(_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
|
|
854
|
+
const computed$1 = this.computedHeight();
|
|
855
|
+
if (this.lastContainer) {
|
|
856
|
+
const prevOverflow = this.lastContainer.style.overflow;
|
|
857
|
+
const newOverflow = computed$1 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
858
|
+
if (prevOverflow !== newOverflow) {
|
|
859
|
+
this.lastContainer.style.overflow = newOverflow;
|
|
860
|
+
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
861
|
+
var _this$modifiedModel;
|
|
862
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel = this.modifiedModel) === null || _this$modifiedModel === void 0 ? void 0 : _this$modifiedModel.getLineCount());
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
663
866
|
});
|
|
664
867
|
});
|
|
665
868
|
(_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
|
|
666
869
|
this._hasScrollBar = false;
|
|
667
870
|
this.rafScheduler.schedule("content-size-change-diff", () => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
871
|
+
var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
|
|
872
|
+
this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
|
|
873
|
+
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;
|
|
874
|
+
this.cachedComputedHeightDiff = this.computedHeight();
|
|
875
|
+
if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
|
|
876
|
+
(_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
|
|
877
|
+
const computed$1 = this.computedHeight();
|
|
878
|
+
if (this.lastContainer) {
|
|
879
|
+
const prevOverflow = this.lastContainer.style.overflow;
|
|
880
|
+
const newOverflow = computed$1 >= this.maxHeightValue - 1 ? "auto" : "hidden";
|
|
881
|
+
if (prevOverflow !== newOverflow) {
|
|
882
|
+
this.lastContainer.style.overflow = newOverflow;
|
|
883
|
+
if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
|
|
884
|
+
var _this$modifiedModel2;
|
|
885
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount());
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
676
889
|
});
|
|
677
890
|
});
|
|
678
891
|
mEditor.onDidChangeModelContent(() => {
|
|
679
892
|
this.lastKnownModifiedDirty = true;
|
|
680
893
|
this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
|
|
681
894
|
});
|
|
895
|
+
this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), this.lastKnownModifiedLineCount ?? void 0);
|
|
682
896
|
return this.diffEditorView;
|
|
683
897
|
}
|
|
684
898
|
updateDiff(originalCode, modifiedCode, codeLanguage) {
|
|
@@ -738,11 +952,37 @@ var DiffEditorManager = class {
|
|
|
738
952
|
}
|
|
739
953
|
const prev = this.lastKnownModifiedCode ?? this.modifiedModel.getValue();
|
|
740
954
|
if (prev === newCode) return;
|
|
955
|
+
const prevLine = this.modifiedModel.getLineCount();
|
|
741
956
|
if (newCode.startsWith(prev) && prev.length < newCode.length) {
|
|
742
|
-
const prevLine = this.modifiedModel.getLineCount();
|
|
743
957
|
this.appendToModel(this.modifiedModel, newCode.slice(prev.length));
|
|
744
958
|
this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), prevLine);
|
|
745
|
-
} else
|
|
959
|
+
} else {
|
|
960
|
+
this.applyMinimalEditToModel(this.modifiedModel, prev, newCode);
|
|
961
|
+
const newLine = this.modifiedModel.getLineCount();
|
|
962
|
+
if (newLine !== prevLine) {
|
|
963
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
964
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
965
|
+
const computed$1 = this.computedHeight();
|
|
966
|
+
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
967
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
968
|
+
this.lastContainer.style.overflow = "auto";
|
|
969
|
+
}
|
|
970
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
971
|
+
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
972
|
+
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
973
|
+
var _editor3, _me2$getModel, _me2$getScrollTop;
|
|
974
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
975
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
976
|
+
const me2 = this.diffEditorView.getModifiedEditor();
|
|
977
|
+
const targetLine = ((_me2$getModel = me2.getModel()) === null || _me2$getModel === void 0 ? void 0 : _me2$getModel.getLineCount()) ?? newLine;
|
|
978
|
+
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
979
|
+
else me2.revealLine(targetLine);
|
|
980
|
+
this.lastRevealLineDiff = targetLine;
|
|
981
|
+
this.shouldAutoScrollDiff = true;
|
|
982
|
+
this.lastScrollTopDiff = ((_me2$getScrollTop = me2.getScrollTop) === null || _me2$getScrollTop === void 0 ? void 0 : _me2$getScrollTop.call(me2)) ?? this.lastScrollTopDiff;
|
|
983
|
+
} catch {}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
746
986
|
this.lastKnownModifiedCode = newCode;
|
|
747
987
|
}
|
|
748
988
|
appendOriginal(appendText, codeLanguage) {
|
|
@@ -752,9 +992,7 @@ var DiffEditorManager = class {
|
|
|
752
992
|
if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
|
|
753
993
|
}
|
|
754
994
|
this.appendToModel(this.originalModel, appendText);
|
|
755
|
-
|
|
756
|
-
this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
757
|
-
} catch {}
|
|
995
|
+
this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
758
996
|
}
|
|
759
997
|
appendModified(appendText, codeLanguage) {
|
|
760
998
|
if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
|
|
@@ -823,6 +1061,15 @@ var DiffEditorManager = class {
|
|
|
823
1061
|
clearTimeout(this.revealDebounceIdDiff);
|
|
824
1062
|
this.revealDebounceIdDiff = null;
|
|
825
1063
|
}
|
|
1064
|
+
if (this.revealIdleTimerIdDiff != null) {
|
|
1065
|
+
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1066
|
+
this.revealIdleTimerIdDiff = null;
|
|
1067
|
+
}
|
|
1068
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1069
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1070
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1071
|
+
}
|
|
1072
|
+
this.revealTicketDiff = 0;
|
|
826
1073
|
this.lastRevealLineDiff = null;
|
|
827
1074
|
}
|
|
828
1075
|
safeClean() {
|
|
@@ -843,6 +1090,15 @@ var DiffEditorManager = class {
|
|
|
843
1090
|
clearTimeout(this.revealDebounceIdDiff);
|
|
844
1091
|
this.revealDebounceIdDiff = null;
|
|
845
1092
|
}
|
|
1093
|
+
if (this.revealIdleTimerIdDiff != null) {
|
|
1094
|
+
clearTimeout(this.revealIdleTimerIdDiff);
|
|
1095
|
+
this.revealIdleTimerIdDiff = null;
|
|
1096
|
+
}
|
|
1097
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1098
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1099
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1100
|
+
}
|
|
1101
|
+
this.revealTicketDiff = 0;
|
|
846
1102
|
this.lastRevealLineDiff = null;
|
|
847
1103
|
this.rafScheduler.cancel("content-size-change-diff");
|
|
848
1104
|
this.rafScheduler.cancel("sync-last-known-modified");
|
|
@@ -856,7 +1112,7 @@ var DiffEditorManager = class {
|
|
|
856
1112
|
this.lastKnownModifiedCode = model.getValue();
|
|
857
1113
|
this.lastKnownModifiedLineCount = model.getLineCount();
|
|
858
1114
|
}
|
|
859
|
-
}
|
|
1115
|
+
} finally {
|
|
860
1116
|
this.lastKnownModifiedDirty = false;
|
|
861
1117
|
}
|
|
862
1118
|
}
|
|
@@ -900,10 +1156,20 @@ var DiffEditorManager = class {
|
|
|
900
1156
|
else this.applyMinimalEditToModel(m, prevM, modified);
|
|
901
1157
|
this.lastKnownModifiedCode = modified;
|
|
902
1158
|
const newMLineCount = m.getLineCount();
|
|
903
|
-
if (newMLineCount !== prevMLineCount)
|
|
1159
|
+
if (newMLineCount !== prevMLineCount) {
|
|
1160
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1161
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1162
|
+
const computed$1 = this.computedHeight();
|
|
1163
|
+
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1164
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1165
|
+
this.lastContainer.style.overflow = "auto";
|
|
1166
|
+
}
|
|
1167
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newMLineCount);
|
|
1168
|
+
else this.maybeScrollDiffToBottom(newMLineCount, prevMLineCount);
|
|
1169
|
+
}
|
|
904
1170
|
}
|
|
905
1171
|
}
|
|
906
|
-
flushAppendBufferDiff() {
|
|
1172
|
+
async flushAppendBufferDiff() {
|
|
907
1173
|
if (!this.diffEditorView) return;
|
|
908
1174
|
if (this.appendBufferDiff.length === 0) return;
|
|
909
1175
|
this.appendBufferDiffScheduled = false;
|
|
@@ -913,39 +1179,128 @@ var DiffEditorManager = class {
|
|
|
913
1179
|
this.appendBufferDiff.length = 0;
|
|
914
1180
|
return;
|
|
915
1181
|
}
|
|
916
|
-
|
|
1182
|
+
let parts = this.appendBufferDiff.splice(0);
|
|
1183
|
+
const prevLineInit = model.getLineCount();
|
|
1184
|
+
const totalText = parts.join("");
|
|
1185
|
+
const totalChars = totalText.length;
|
|
1186
|
+
if (parts.length === 1 && totalChars > 5e3) {
|
|
1187
|
+
const lines = totalText.split(/\r?\n/);
|
|
1188
|
+
const chunkSize = 200;
|
|
1189
|
+
const chunks = [];
|
|
1190
|
+
for (let i = 0; i < lines.length; i += chunkSize) chunks.push(`${lines.slice(i, i + chunkSize).join("\n")}\n`);
|
|
1191
|
+
if (chunks.length > 1) parts = chunks;
|
|
1192
|
+
}
|
|
1193
|
+
const applyChunked = parts.length > 1 && (totalChars > 2e3 || model.getLineCount && model.getLineCount() + 0 - prevLineInit > 50);
|
|
1194
|
+
log("diff", "flushAppendBufferDiff start", {
|
|
1195
|
+
partsCount: parts.length,
|
|
1196
|
+
totalChars,
|
|
1197
|
+
applyChunked
|
|
1198
|
+
});
|
|
1199
|
+
let prevLine = prevLineInit;
|
|
1200
|
+
const watcherApi = this.diffScrollWatcher;
|
|
1201
|
+
let suppressedByFlush = false;
|
|
1202
|
+
if (watcherApi && typeof watcherApi.setSuppressed === "function") try {
|
|
1203
|
+
if (this.diffScrollWatcherSuppressionTimer != null) {
|
|
1204
|
+
clearTimeout(this.diffScrollWatcherSuppressionTimer);
|
|
1205
|
+
this.diffScrollWatcherSuppressionTimer = null;
|
|
1206
|
+
}
|
|
1207
|
+
watcherApi.setSuppressed(true);
|
|
1208
|
+
suppressedByFlush = true;
|
|
1209
|
+
} catch {}
|
|
1210
|
+
if (applyChunked) {
|
|
1211
|
+
log("diff", "flushAppendBufferDiff applying chunked", { partsLen: parts.length });
|
|
1212
|
+
let idx = 0;
|
|
1213
|
+
for (const part of parts) {
|
|
1214
|
+
if (!part) continue;
|
|
1215
|
+
idx += 1;
|
|
1216
|
+
log("diff", "flushAppendBufferDiff chunk", {
|
|
1217
|
+
idx,
|
|
1218
|
+
partLen: part.length,
|
|
1219
|
+
prevLine
|
|
1220
|
+
});
|
|
1221
|
+
const lastColumn$1 = model.getLineMaxColumn(prevLine);
|
|
1222
|
+
const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
|
|
1223
|
+
model.applyEdits([{
|
|
1224
|
+
range: range$1,
|
|
1225
|
+
text: part,
|
|
1226
|
+
forceMoveMarkers: true
|
|
1227
|
+
}]);
|
|
1228
|
+
this.lastKnownModifiedCode = model.getValue();
|
|
1229
|
+
const newLine$1 = model.getLineCount();
|
|
1230
|
+
this.lastKnownModifiedLineCount = newLine$1;
|
|
1231
|
+
await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
|
|
1232
|
+
const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
|
|
1233
|
+
log("diff", "flushAppendBufferDiff chunk metrics", {
|
|
1234
|
+
idx,
|
|
1235
|
+
newLine: newLine$1,
|
|
1236
|
+
prevLine,
|
|
1237
|
+
shouldImmediate: shouldImmediate$1
|
|
1238
|
+
});
|
|
1239
|
+
if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1240
|
+
const computed$2 = this.computedHeight();
|
|
1241
|
+
if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
|
|
1242
|
+
this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1243
|
+
this.lastContainer.style.overflow = "auto";
|
|
1244
|
+
}
|
|
1245
|
+
if (shouldImmediate$1) this.scheduleImmediateRevealAfterLayoutDiff(newLine$1);
|
|
1246
|
+
else this.maybeScrollDiffToBottom(newLine$1, prevLine);
|
|
1247
|
+
prevLine = newLine$1;
|
|
1248
|
+
log("diff", "flushAppendBufferDiff chunk applied", {
|
|
1249
|
+
idx,
|
|
1250
|
+
newLine: newLine$1
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
const text = totalText;
|
|
917
1257
|
this.appendBufferDiff.length = 0;
|
|
1258
|
+
prevLine = model.getLineCount();
|
|
1259
|
+
const lastColumn = model.getLineMaxColumn(prevLine);
|
|
1260
|
+
const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
|
|
1261
|
+
model.applyEdits([{
|
|
1262
|
+
range,
|
|
1263
|
+
text,
|
|
1264
|
+
forceMoveMarkers: true
|
|
1265
|
+
}]);
|
|
1266
|
+
this.lastKnownModifiedCode = model.getValue();
|
|
1267
|
+
const newLine = model.getLineCount();
|
|
1268
|
+
this.lastKnownModifiedLineCount = newLine;
|
|
1269
|
+
const shouldImmediate = this.shouldPerformImmediateRevealDiff();
|
|
1270
|
+
if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
|
|
1271
|
+
const computed$1 = this.computedHeight();
|
|
1272
|
+
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1273
|
+
if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
|
|
1274
|
+
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
1275
|
+
if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
|
|
1276
|
+
var _editor4, _me2$getModel2, _me2$getScrollTop2;
|
|
1277
|
+
const ScrollType = monaco_shim_exports.ScrollType || ((_editor4 = monaco_shim_exports.editor) === null || _editor4 === void 0 ? void 0 : _editor4.ScrollType);
|
|
1278
|
+
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1279
|
+
const me2 = this.diffEditorView.getModifiedEditor();
|
|
1280
|
+
const targetLine = ((_me2$getModel2 = me2.getModel()) === null || _me2$getModel2 === void 0 ? void 0 : _me2$getModel2.getLineCount()) ?? newLine;
|
|
1281
|
+
if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
|
|
1282
|
+
else me2.revealLine(targetLine);
|
|
1283
|
+
this.lastRevealLineDiff = targetLine;
|
|
1284
|
+
this.shouldAutoScrollDiff = true;
|
|
1285
|
+
this.lastScrollTopDiff = ((_me2$getScrollTop2 = me2.getScrollTop) === null || _me2$getScrollTop2 === void 0 ? void 0 : _me2$getScrollTop2.call(me2)) ?? this.lastScrollTopDiff;
|
|
1286
|
+
} catch {}
|
|
1287
|
+
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
918
1288
|
try {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
model.applyEdits([{
|
|
923
|
-
range,
|
|
924
|
-
text,
|
|
925
|
-
forceMoveMarkers: true
|
|
926
|
-
}]);
|
|
927
|
-
try {
|
|
928
|
-
this.lastKnownModifiedCode = model.getValue();
|
|
929
|
-
} catch {}
|
|
930
|
-
const newLine = model.getLineCount();
|
|
931
|
-
this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
932
|
-
this.lastKnownModifiedLineCount = newLine;
|
|
1289
|
+
var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7;
|
|
1290
|
+
this.shouldAutoScrollDiff = true;
|
|
1291
|
+
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;
|
|
933
1292
|
} catch {}
|
|
934
1293
|
}
|
|
935
1294
|
applyMinimalEditToModel(model, prev, next) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
} catch {}
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
} catch {}
|
|
1295
|
+
const maxChars = minimalEditMaxChars;
|
|
1296
|
+
const ratio = minimalEditMaxChangeRatio;
|
|
1297
|
+
const maxLen = Math.max(prev.length, next.length);
|
|
1298
|
+
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1299
|
+
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1300
|
+
model.setValue(next);
|
|
1301
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
949
1304
|
const res = computeMinimalEdit(prev, next);
|
|
950
1305
|
if (!res) return;
|
|
951
1306
|
const { start, endPrevIncl, replaceText } = res;
|
|
@@ -957,9 +1312,7 @@ var DiffEditorManager = class {
|
|
|
957
1312
|
text: replaceText,
|
|
958
1313
|
forceMoveMarkers: true
|
|
959
1314
|
}]);
|
|
960
|
-
|
|
961
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
962
|
-
} catch {}
|
|
1315
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
963
1316
|
}
|
|
964
1317
|
appendToModel(model, appendText) {
|
|
965
1318
|
if (!appendText) return;
|
|
@@ -971,9 +1324,7 @@ var DiffEditorManager = class {
|
|
|
971
1324
|
text: appendText,
|
|
972
1325
|
forceMoveMarkers: true
|
|
973
1326
|
}]);
|
|
974
|
-
|
|
975
|
-
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
976
|
-
} catch {}
|
|
1327
|
+
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
977
1328
|
}
|
|
978
1329
|
};
|
|
979
1330
|
|
|
@@ -1072,14 +1423,12 @@ var EditorManager = class {
|
|
|
1072
1423
|
const lineCount = this.cachedLineCount ?? ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getLineCount()) ?? 1;
|
|
1073
1424
|
const lineHeight = editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
1074
1425
|
const height = Math.min(lineCount * lineHeight + padding, this.maxHeightValue);
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
});
|
|
1082
|
-
} catch {}
|
|
1426
|
+
log("EditorManager.computedHeight", {
|
|
1427
|
+
lineCount,
|
|
1428
|
+
lineHeight,
|
|
1429
|
+
computed: height,
|
|
1430
|
+
maxHeightValue: this.maxHeightValue
|
|
1431
|
+
});
|
|
1083
1432
|
return height;
|
|
1084
1433
|
}
|
|
1085
1434
|
maybeScrollToBottom(targetLine) {
|
|
@@ -1130,7 +1479,6 @@ var EditorManager = class {
|
|
|
1130
1479
|
return;
|
|
1131
1480
|
}
|
|
1132
1481
|
this.dlog("performReveal executing, ticket=", ticket, "line=", line);
|
|
1133
|
-
this.lastPerformedRevealTicket = ticket;
|
|
1134
1482
|
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
1135
1483
|
this.dlog("performReveal strategy=", strategy);
|
|
1136
1484
|
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
@@ -1158,7 +1506,6 @@ var EditorManager = class {
|
|
|
1158
1506
|
this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
1159
1507
|
return;
|
|
1160
1508
|
}
|
|
1161
|
-
this.lastPerformedRevealTicket = ticket;
|
|
1162
1509
|
const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
1163
1510
|
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
1164
1511
|
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
@@ -1308,35 +1655,28 @@ var EditorManager = class {
|
|
|
1308
1655
|
}
|
|
1309
1656
|
syncLastKnownCode() {
|
|
1310
1657
|
if (!this.editorView || !this.lastKnownCodeDirty) return;
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
|
|
1316
|
-
}
|
|
1317
|
-
} catch {} finally {
|
|
1318
|
-
this.lastKnownCodeDirty = false;
|
|
1658
|
+
const model = this.editorView.getModel();
|
|
1659
|
+
if (model) {
|
|
1660
|
+
this.lastKnownCode = model.getValue();
|
|
1661
|
+
this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
|
|
1319
1662
|
}
|
|
1663
|
+
this.lastKnownCodeDirty = false;
|
|
1320
1664
|
}
|
|
1321
1665
|
suppressScrollWatcher(ms) {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1666
|
+
if (!this.scrollWatcher || typeof this.scrollWatcher.setSuppressed !== "function") return;
|
|
1667
|
+
this.dlog("suppressScrollWatcher", ms);
|
|
1668
|
+
if (this.scrollWatcherSuppressionTimer != null) {
|
|
1669
|
+
clearTimeout(this.scrollWatcherSuppressionTimer);
|
|
1670
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1671
|
+
}
|
|
1672
|
+
this.scrollWatcher.setSuppressed(true);
|
|
1673
|
+
this.scrollWatcherSuppressionTimer = setTimeout(() => {
|
|
1674
|
+
if (this.scrollWatcher && typeof this.scrollWatcher.setSuppressed === "function") {
|
|
1675
|
+
this.scrollWatcher.setSuppressed(false);
|
|
1676
|
+
this.dlog("suppressScrollWatcher cleared");
|
|
1328
1677
|
}
|
|
1329
|
-
this.
|
|
1330
|
-
|
|
1331
|
-
try {
|
|
1332
|
-
if (this.scrollWatcher && typeof this.scrollWatcher.setSuppressed === "function") {
|
|
1333
|
-
this.scrollWatcher.setSuppressed(false);
|
|
1334
|
-
this.dlog("suppressScrollWatcher cleared");
|
|
1335
|
-
}
|
|
1336
|
-
} catch {}
|
|
1337
|
-
this.scrollWatcherSuppressionTimer = null;
|
|
1338
|
-
}, ms);
|
|
1339
|
-
} catch {}
|
|
1678
|
+
this.scrollWatcherSuppressionTimer = null;
|
|
1679
|
+
}, ms);
|
|
1340
1680
|
}
|
|
1341
1681
|
scheduleImmediateRevealAfterLayout(line) {
|
|
1342
1682
|
const ticket = ++this.revealTicket;
|
|
@@ -1402,14 +1742,9 @@ var EditorManager = class {
|
|
|
1402
1742
|
if (newLineCount$1 !== prevLineCount$1) {
|
|
1403
1743
|
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1404
1744
|
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
} catch {}
|
|
1409
|
-
if (shouldImmediate) try {
|
|
1410
|
-
this.forceReveal(newLineCount$1);
|
|
1411
|
-
} catch {}
|
|
1412
|
-
else this.maybeScrollToBottom(newLineCount$1);
|
|
1745
|
+
const computed$1 = this.computedHeight(this.editorView);
|
|
1746
|
+
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1747
|
+
this.forceReveal(newLineCount$1);
|
|
1413
1748
|
}
|
|
1414
1749
|
return;
|
|
1415
1750
|
}
|
|
@@ -1451,21 +1786,19 @@ var EditorManager = class {
|
|
|
1451
1786
|
if (!this.editorView) return;
|
|
1452
1787
|
const model = this.editorView.getModel();
|
|
1453
1788
|
if (!model) return;
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
}
|
|
1468
|
-
} catch {}
|
|
1789
|
+
const maxChars = minimalEditMaxChars;
|
|
1790
|
+
const ratio = minimalEditMaxChangeRatio;
|
|
1791
|
+
const maxLen = Math.max(prev.length, next.length);
|
|
1792
|
+
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
1793
|
+
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
1794
|
+
const prevLineCount = model.getLineCount();
|
|
1795
|
+
model.setValue(next);
|
|
1796
|
+
this.lastKnownCode = next;
|
|
1797
|
+
const newLineCount = model.getLineCount();
|
|
1798
|
+
this.cachedLineCount = newLineCount;
|
|
1799
|
+
if (newLineCount !== prevLineCount) this.maybeScrollToBottom(newLineCount);
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1469
1802
|
const res = computeMinimalEdit(prev, next);
|
|
1470
1803
|
if (!res) return;
|
|
1471
1804
|
const { start, endPrevIncl, replaceText } = res;
|
|
@@ -1511,10 +1844,8 @@ var EditorManager = class {
|
|
|
1511
1844
|
this.cachedLineCount = newLineCount;
|
|
1512
1845
|
const shouldImmediate = this.shouldPerformImmediateReveal();
|
|
1513
1846
|
if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1517
|
-
} catch {}
|
|
1847
|
+
const computed$1 = this.computedHeight(this.editorView);
|
|
1848
|
+
if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
|
|
1518
1849
|
if (shouldImmediate) try {
|
|
1519
1850
|
this.forceReveal(newLineCount);
|
|
1520
1851
|
} catch {}
|
|
@@ -2088,9 +2419,7 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2088
2419
|
flush: "post",
|
|
2089
2420
|
immediate: true
|
|
2090
2421
|
});
|
|
2091
|
-
|
|
2092
|
-
if (editorView) lastKnownCode = editorView.getValue();
|
|
2093
|
-
} catch {}
|
|
2422
|
+
if (editorView) lastKnownCode = editorView.getValue();
|
|
2094
2423
|
return editorView;
|
|
2095
2424
|
}
|
|
2096
2425
|
function computedHeight(editorView$1) {
|