stream-monaco 0.0.21 → 0.0.36

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.
@@ -147,9 +147,14 @@ function processedLanguage(language) {
147
147
  //#endregion
148
148
  //#region src/monaco-shim.ts
149
149
  var monaco_shim_exports = {};
150
- __export(monaco_shim_exports, { default: () => monaco });
150
+ __export(monaco_shim_exports, {
151
+ ScrollType: () => ScrollType,
152
+ default: () => monaco
153
+ });
151
154
  __reExport(monaco_shim_exports, require("monaco-editor/esm/vs/editor/editor.api"));
155
+ var _editor;
152
156
  const monaco = monaco_editor_esm_vs_editor_editor_api;
157
+ const ScrollType = Reflect.get(monaco_editor_esm_vs_editor_editor_api, "ScrollType") ?? ((_editor = monaco_editor_esm_vs_editor_editor_api.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
153
158
 
154
159
  //#endregion
155
160
  //#region src/constant.ts
@@ -472,6 +477,809 @@ function createScrollWatcherForEditor(ed, opts) {
472
477
  return api;
473
478
  }
474
479
 
480
+ //#endregion
481
+ //#region src/core/diffAppearance.ts
482
+ function parseCssColorRgb(color) {
483
+ const normalized = color.trim().toLowerCase();
484
+ const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
485
+ if (rgbMatch) return [
486
+ Number.parseFloat(rgbMatch[1]),
487
+ Number.parseFloat(rgbMatch[2]),
488
+ Number.parseFloat(rgbMatch[3])
489
+ ];
490
+ const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
491
+ if (!hexMatch) return null;
492
+ const hex = hexMatch[1];
493
+ if (hex.length === 3 || hex.length === 4) return [
494
+ Number.parseInt(`${hex[0]}${hex[0]}`, 16),
495
+ Number.parseInt(`${hex[1]}${hex[1]}`, 16),
496
+ Number.parseInt(`${hex[2]}${hex[2]}`, 16)
497
+ ];
498
+ if (hex.length === 6 || hex.length === 8) return [
499
+ Number.parseInt(hex.slice(0, 2), 16),
500
+ Number.parseInt(hex.slice(2, 4), 16),
501
+ Number.parseInt(hex.slice(4, 6), 16)
502
+ ];
503
+ return null;
504
+ }
505
+ function resolveCssColorLuminance(color) {
506
+ const rgb = parseCssColorRgb(color);
507
+ if (!rgb) return null;
508
+ const channel = (value) => {
509
+ const normalized = Math.max(0, Math.min(255, value)) / 255;
510
+ return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
511
+ };
512
+ const [r, g, b] = rgb;
513
+ return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
514
+ }
515
+ function looksLikeDarkThemeName(themeName) {
516
+ if (!themeName) return false;
517
+ const normalized = themeName.toLowerCase();
518
+ return [
519
+ "dark",
520
+ "night",
521
+ "moon",
522
+ "black",
523
+ "dracula",
524
+ "mocha",
525
+ "frappe",
526
+ "macchiato",
527
+ "palenight",
528
+ "ocean",
529
+ "poimandres",
530
+ "monokai",
531
+ "laserwave",
532
+ "tokyo",
533
+ "slack-dark",
534
+ "rose-pine",
535
+ "github-dark",
536
+ "material-theme",
537
+ "one-dark",
538
+ "catppuccin-mocha",
539
+ "catppuccin-frappe",
540
+ "catppuccin-macchiato"
541
+ ].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
542
+ }
543
+ function looksLikeLightThemeName(themeName) {
544
+ if (!themeName) return false;
545
+ const normalized = themeName.toLowerCase();
546
+ return [
547
+ "light",
548
+ "day",
549
+ "dawn",
550
+ "latte",
551
+ "solarized-light",
552
+ "github-light",
553
+ "rose-pine-dawn",
554
+ "catppuccin-latte",
555
+ "one-light",
556
+ "vitesse-light",
557
+ "snazzy-light",
558
+ "material-lighter",
559
+ "material-theme-lighter",
560
+ "lotus"
561
+ ].some((token) => normalized.includes(token));
562
+ }
563
+ function resolveDiffAppearance({ container, diffAppearance, diffEditorView, themeName }) {
564
+ var _diffEditorView$getMo, _diffEditorView$getMo2, _diffEditorView$getOr, _diffEditorView$getOr2;
565
+ if (diffAppearance === "light") return "light";
566
+ if (diffAppearance === "dark") return "dark";
567
+ if (looksLikeDarkThemeName(themeName)) return "dark";
568
+ if (looksLikeLightThemeName(themeName)) return "light";
569
+ const appearanceProbeNodes = [
570
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo2 = (_diffEditorView$getMo = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo2 === void 0 ? void 0 : _diffEditorView$getMo2.call(_diffEditorView$getMo),
571
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr2 = (_diffEditorView$getOr = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr2 === void 0 ? void 0 : _diffEditorView$getOr2.call(_diffEditorView$getOr),
572
+ container
573
+ ];
574
+ for (const node of appearanceProbeNodes) {
575
+ if (!(node instanceof HTMLElement)) continue;
576
+ const style = globalThis.getComputedStyle(node);
577
+ const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
578
+ const candidates = [
579
+ style.getPropertyValue("--stream-monaco-editor-bg"),
580
+ style.getPropertyValue("--vscode-editor-background"),
581
+ editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
582
+ style.backgroundColor
583
+ ];
584
+ for (const color of candidates) {
585
+ const luminance = resolveCssColorLuminance(color);
586
+ if (luminance == null) continue;
587
+ return luminance <= .42 ? "dark" : "light";
588
+ }
589
+ }
590
+ return looksLikeDarkThemeName(themeName) ? "dark" : "light";
591
+ }
592
+ function syncDiffRootThemeVariables(container, diffEditorView, appearance) {
593
+ var _diffEditorView$getMo3, _diffEditorView$getMo4, _diffEditorView$getOr3, _diffEditorView$getOr4;
594
+ const probeNodes = [
595
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo4 = (_diffEditorView$getMo3 = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo4 === void 0 ? void 0 : _diffEditorView$getMo4.call(_diffEditorView$getMo3),
596
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr4 = (_diffEditorView$getOr3 = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr4 === void 0 ? void 0 : _diffEditorView$getOr4.call(_diffEditorView$getOr3),
597
+ container
598
+ ];
599
+ const containerStyle = globalThis.getComputedStyle(container);
600
+ const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
601
+ let backgroundColor = null;
602
+ let foregroundColor = null;
603
+ for (const node of probeNodes) {
604
+ if (!(node instanceof HTMLElement)) continue;
605
+ const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
606
+ const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
607
+ const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
608
+ if (!backgroundColor && resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
609
+ const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
610
+ if (!foregroundColor && resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
611
+ if (backgroundColor && foregroundColor) break;
612
+ }
613
+ const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
614
+ if (resolvedBackgroundColor) container.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
615
+ else container.style.removeProperty("--stream-monaco-editor-bg");
616
+ if (foregroundColor) container.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
617
+ else container.style.removeProperty("--stream-monaco-editor-fg");
618
+ }
619
+ function resolveDiffUnchangedLineInfoRailMetrics(node) {
620
+ const editorRoot = node.closest(".monaco-editor");
621
+ if (!editorRoot) return {
622
+ leftInset: 0,
623
+ width: null
624
+ };
625
+ const editorRect = editorRoot.getBoundingClientRect();
626
+ const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
627
+ const rect = candidate.getBoundingClientRect();
628
+ return rect.width > 0 && rect.height > 0;
629
+ });
630
+ if (!lineNumberNode) return {
631
+ leftInset: 0,
632
+ width: null
633
+ };
634
+ const lineNumberRect = lineNumberNode.getBoundingClientRect();
635
+ return {
636
+ leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
637
+ width: Math.max(0, lineNumberRect.width) || null
638
+ };
639
+ }
640
+ function applyDiffRootAppearanceClass({ appearanceClasses, container, currentSignature, diffAppearance, diffEditorView, isInlineMode, layoutModeClasses, lineStyle, lineStyleClasses, themeName, unchangedRegionStyle, unchangedRegionStyleClasses }) {
641
+ if (!container) return currentSignature;
642
+ const resolvedAppearance = resolveDiffAppearance({
643
+ container,
644
+ diffAppearance,
645
+ diffEditorView,
646
+ themeName
647
+ });
648
+ syncDiffRootThemeVariables(container, diffEditorView, resolvedAppearance);
649
+ const containerClassList = container.classList;
650
+ const activeLineStyleClass = `stream-monaco-diff-style-${lineStyle}`;
651
+ const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${unchangedRegionStyle}`;
652
+ const activeLayoutModeClass = isInlineMode ? "stream-monaco-diff-inline" : "stream-monaco-diff-side-by-side";
653
+ const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
654
+ const nextSignature = [
655
+ activeLineStyleClass,
656
+ activeUnchangedRegionStyleClass,
657
+ activeLayoutModeClass,
658
+ activeAppearanceClass
659
+ ].join("|");
660
+ if (currentSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return currentSignature;
661
+ containerClassList.add("stream-monaco-diff-root");
662
+ for (const className of lineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
663
+ for (const className of unchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
664
+ for (const className of layoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
665
+ for (const className of appearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
666
+ return nextSignature;
667
+ }
668
+
669
+ //#endregion
670
+ //#region src/core/diffHunk.ts
671
+ function createDiffHunkActionNode(side, onAction) {
672
+ const node = document.createElement("div");
673
+ node.className = "stream-monaco-diff-hunk-actions";
674
+ node.dataset.side = side;
675
+ const createButton = (action, label) => {
676
+ const button = document.createElement("button");
677
+ button.type = "button";
678
+ button.textContent = label;
679
+ button.dataset.action = action;
680
+ button.addEventListener("click", (event) => {
681
+ event.preventDefault();
682
+ event.stopPropagation();
683
+ onAction(side, action);
684
+ });
685
+ return button;
686
+ };
687
+ node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
688
+ return node;
689
+ }
690
+ function hasOriginalLines(change) {
691
+ return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
692
+ }
693
+ function hasModifiedLines(change) {
694
+ return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
695
+ }
696
+ function inferInlineDiffHunkHoverSide(change, hoverLine, targetElement) {
697
+ if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
698
+ if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
699
+ if (!hasModifiedLines(change)) return "upper";
700
+ if (!hasOriginalLines(change)) return "lower";
701
+ const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
702
+ return hoverLine < modifiedAnchor ? "upper" : "lower";
703
+ }
704
+ function distanceToLineChange(side, change, line) {
705
+ const hasRange = side === "original" ? hasOriginalLines(change) : hasModifiedLines(change);
706
+ const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
707
+ const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
708
+ if (hasRange) {
709
+ if (line < start) return start - line;
710
+ if (line > end) return line - end;
711
+ return 0;
712
+ }
713
+ const fallbackAnchor = Math.max(1, start || end || 1);
714
+ return Math.abs(line - fallbackAnchor);
715
+ }
716
+ function findLineChangeByHoverLine(lineChanges, side, line) {
717
+ if (lineChanges.length === 0) return null;
718
+ let best = null;
719
+ let bestDistance = Number.POSITIVE_INFINITY;
720
+ for (const change of lineChanges) {
721
+ const distance = distanceToLineChange(side, change, line);
722
+ if (distance < bestDistance) {
723
+ bestDistance = distance;
724
+ best = change;
725
+ if (distance === 0) break;
726
+ }
727
+ }
728
+ if (bestDistance > 2) return null;
729
+ return best;
730
+ }
731
+ function getFullLineRange(model, startLine, endLine) {
732
+ if (endLine < startLine) return null;
733
+ const lineCount = model.getLineCount();
734
+ if (lineCount < 1) return null;
735
+ const start = Math.max(1, Math.min(startLine, lineCount));
736
+ const end = Math.max(start, Math.min(endLine, lineCount));
737
+ if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
738
+ return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
739
+ }
740
+ function getLinesText(model, startLine, endLine) {
741
+ const range = getFullLineRange(model, startLine, endLine);
742
+ if (!range) return "";
743
+ return model.getValueInRange(range);
744
+ }
745
+ function getInsertRangeBeforeLine(model, lineNumber) {
746
+ const lineCount = model.getLineCount();
747
+ if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
748
+ if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
749
+ const lastLine = lineCount;
750
+ const lastColumn = model.getLineMaxColumn(lastLine);
751
+ return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
752
+ }
753
+ function getInsertRangeAfterLine(model, lineNumber) {
754
+ const lineCount = model.getLineCount();
755
+ if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
756
+ if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
757
+ const lastLine = lineCount;
758
+ const lastColumn = model.getLineMaxColumn(lastLine);
759
+ return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
760
+ }
761
+ function applyDefaultDiffHunkAction(context) {
762
+ const { action, side, lineChange, originalModel, modifiedModel } = context;
763
+ const hasOriginal = hasOriginalLines(lineChange);
764
+ const hasModified = hasModifiedLines(lineChange);
765
+ if (action === "revert" && side === "upper") {
766
+ if (!hasOriginal) return;
767
+ const text = getLinesText(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
768
+ if (!text) return;
769
+ const range = hasModified ? getInsertRangeBeforeLine(modifiedModel, lineChange.modifiedStartLineNumber) : getInsertRangeAfterLine(modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
770
+ modifiedModel.applyEdits([{
771
+ range,
772
+ text,
773
+ forceMoveMarkers: true
774
+ }]);
775
+ return;
776
+ }
777
+ if (action === "revert" && side === "lower") {
778
+ if (!hasModified) return;
779
+ const range = getFullLineRange(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
780
+ if (!range) return;
781
+ modifiedModel.applyEdits([{
782
+ range,
783
+ text: "",
784
+ forceMoveMarkers: true
785
+ }]);
786
+ return;
787
+ }
788
+ if (action === "stage" && side === "upper") {
789
+ if (!hasOriginal) return;
790
+ const range = getFullLineRange(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
791
+ if (!range) return;
792
+ originalModel.applyEdits([{
793
+ range,
794
+ text: "",
795
+ forceMoveMarkers: true
796
+ }]);
797
+ return;
798
+ }
799
+ if (action === "stage" && side === "lower") {
800
+ if (!hasModified) return;
801
+ const text = getLinesText(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
802
+ if (!text) return;
803
+ const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
804
+ const range = getInsertRangeAfterLine(originalModel, anchor);
805
+ originalModel.applyEdits([{
806
+ range,
807
+ text,
808
+ forceMoveMarkers: true
809
+ }]);
810
+ }
811
+ }
812
+ function setDiffHunkNodeEnabled(node, enabled) {
813
+ if (!node) return;
814
+ const buttons = node.querySelectorAll("button");
815
+ buttons.forEach((button) => {
816
+ button.disabled = !enabled;
817
+ });
818
+ }
819
+ function positionDiffHunkNode(node, editor, anchorLine, extraOffsetY = 0) {
820
+ var _editor$getScrollTop;
821
+ const host = editor.getContainerDomNode();
822
+ const line = Math.max(1, anchorLine);
823
+ const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
824
+ const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
825
+ const nodeWidth = node.offsetWidth || 130;
826
+ const nodeHeight = node.offsetHeight || 30;
827
+ const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
828
+ const hostTop = host.offsetTop;
829
+ const minTop = hostTop + 4;
830
+ const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
831
+ const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
832
+ node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
833
+ node.style.display = "flex";
834
+ }
835
+
836
+ //#endregion
837
+ //#region src/core/diffUnchanged.ts
838
+ function formatDiffUnchangedCountLabel(text) {
839
+ const match = text.match(/\d+/);
840
+ const count = match ? Number.parseInt(match[0], 10) : NaN;
841
+ if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
842
+ return text.replace(/hidden/gi, "unmodified");
843
+ }
844
+ function countDiffLines(startLineNumber, endLineNumber) {
845
+ return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
846
+ }
847
+ function measureDiffUnchangedSurroundingLines(primaryNode) {
848
+ const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
849
+ if (!editorRoot) return {
850
+ previousVisibleLine: null,
851
+ nextVisibleLine: null
852
+ };
853
+ const widgetRect = primaryNode.getBoundingClientRect();
854
+ let previousVisibleLine = null;
855
+ let nextVisibleLine = null;
856
+ const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
857
+ lineNumberNodes.forEach((node) => {
858
+ var _node$textContent;
859
+ const lineNumber = Number.parseInt(((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim()) || "", 10);
860
+ if (!Number.isFinite(lineNumber)) return;
861
+ const top = node.getBoundingClientRect().top;
862
+ if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
863
+ else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
864
+ });
865
+ return {
866
+ previousVisibleLine,
867
+ nextVisibleLine
868
+ };
869
+ }
870
+ function formatDiffMetadataRange(startLineNumber, lineCount) {
871
+ return `${startLineNumber},${Math.max(0, lineCount)}`;
872
+ }
873
+ function buildDiffHunkMetadataLabel(change, options) {
874
+ const { contextLineCount, modifiedTotalLines, originalTotalLines } = options;
875
+ const originalChangedCount = countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
876
+ const modifiedChangedCount = countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
877
+ const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
878
+ const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
879
+ const originalStart = Math.max(1, originalAnchor - contextLineCount);
880
+ const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
881
+ const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
882
+ const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
883
+ const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
884
+ const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
885
+ return {
886
+ modifiedStart,
887
+ originalStart,
888
+ label: `@@ -${formatDiffMetadataRange(originalStart, originalDisplayCount)} +${formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
889
+ };
890
+ }
891
+ function resolveDiffMetadataLabel(options) {
892
+ var _metadataEntries$Math;
893
+ const { contextLineCount, lineChanges, modifiedTotalLines, originalTotalLines, pairIndex, primaryNode } = options;
894
+ if (lineChanges.length === 0) return null;
895
+ const metadataEntries = lineChanges.map((change) => buildDiffHunkMetadataLabel(change, {
896
+ contextLineCount,
897
+ modifiedTotalLines,
898
+ originalTotalLines
899
+ }));
900
+ const { nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
901
+ if (nextVisibleLine != null) {
902
+ const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
903
+ for (const candidateStart of candidateStarts) {
904
+ const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
905
+ if (matching) return matching.label;
906
+ }
907
+ }
908
+ return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
909
+ }
910
+ function resolveDiffUnchangedSummaryLabel(options) {
911
+ const { countText, unchangedRegionStyle,...metadataOptions } = options;
912
+ if (unchangedRegionStyle !== "metadata") return countText;
913
+ return resolveDiffMetadataLabel(metadataOptions) ?? countText;
914
+ }
915
+ function resolveDiffUnchangedRevealLayout(options) {
916
+ const { countText, modelLineCount, pairCount, pairIndex, primaryNode } = options;
917
+ let showTopHandle = pairCount === 1 || pairIndex > 0;
918
+ let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
919
+ const countMatch = countText.match(/\d+/);
920
+ const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
921
+ if (!Number.isFinite(hiddenCount)) return {
922
+ showTopHandle,
923
+ showBottomHandle
924
+ };
925
+ const { previousVisibleLine, nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
926
+ if (previousVisibleLine == null && nextVisibleLine != null) {
927
+ showTopHandle = false;
928
+ showBottomHandle = true;
929
+ return {
930
+ showTopHandle,
931
+ showBottomHandle
932
+ };
933
+ }
934
+ if (nextVisibleLine == null && previousVisibleLine != null) {
935
+ showTopHandle = true;
936
+ showBottomHandle = false;
937
+ return {
938
+ showTopHandle,
939
+ showBottomHandle
940
+ };
941
+ }
942
+ if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
943
+ showTopHandle = false;
944
+ showBottomHandle = true;
945
+ }
946
+ if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
947
+ showTopHandle = true;
948
+ showBottomHandle = false;
949
+ }
950
+ return {
951
+ showTopHandle,
952
+ showBottomHandle
953
+ };
954
+ }
955
+ function resolveDiffUnchangedMergeRole(options) {
956
+ const { diffRoot, modifiedHost, node, originalHost } = options;
957
+ if (typeof HTMLElement === "undefined") return "none";
958
+ if (!(diffRoot instanceof HTMLElement)) return "none";
959
+ const nodeRect = node.getBoundingClientRect();
960
+ const nodeCenter = nodeRect.left + nodeRect.width / 2;
961
+ if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
962
+ const originalRect = originalHost.getBoundingClientRect();
963
+ const modifiedRect = modifiedHost.getBoundingClientRect();
964
+ const originalCenter = originalRect.left + originalRect.width / 2;
965
+ const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
966
+ return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
967
+ }
968
+ const diffRect = diffRoot.getBoundingClientRect();
969
+ return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
970
+ }
971
+
972
+ //#endregion
973
+ //#region src/core/diffUnchangedDom.ts
974
+ const diffUnchangedSummaryStyleClasses = [
975
+ "stream-monaco-unchanged-summary-line-info",
976
+ "stream-monaco-unchanged-summary-line-info-basic",
977
+ "stream-monaco-unchanged-summary-metadata",
978
+ "stream-monaco-unchanged-summary-simple"
979
+ ];
980
+ function createDiffUnchangedBridgeScaffold() {
981
+ const bridge = document.createElement("div");
982
+ bridge.className = "stream-monaco-diff-unchanged-bridge";
983
+ bridge.setAttribute("role", "group");
984
+ syncDiffUnchangedBridgeVisibility(bridge, false);
985
+ const summary = document.createElement("button");
986
+ summary.type = "button";
987
+ summary.className = "stream-monaco-unchanged-summary";
988
+ const visualMeta = document.createElement("div");
989
+ visualMeta.className = "stream-monaco-unchanged-meta";
990
+ summary.append(visualMeta);
991
+ const divider = document.createElement("span");
992
+ divider.className = "stream-monaco-unchanged-pane-divider";
993
+ divider.setAttribute("aria-hidden", "true");
994
+ bridge.append(summary, divider);
995
+ return {
996
+ bridge,
997
+ summary,
998
+ visualMeta,
999
+ divider
1000
+ };
1001
+ }
1002
+ function createDiffUnchangedBridgeOverlay() {
1003
+ const overlay = document.createElement("div");
1004
+ overlay.className = "stream-monaco-diff-unchanged-overlay";
1005
+ return overlay;
1006
+ }
1007
+ function syncDiffUnchangedBridgeVisibility(bridge, visible) {
1008
+ bridge.hidden = !visible;
1009
+ bridge.toggleAttribute("aria-hidden", !visible);
1010
+ }
1011
+ function clearDiffUnchangedBridgeSourceClasses(container) {
1012
+ const bridgedCenters = container.querySelectorAll(".stream-monaco-unchanged-bridge-source");
1013
+ bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
1014
+ }
1015
+ function resetDiffUnchangedOverlayTransform(overlay) {
1016
+ if (!overlay) return;
1017
+ overlay.style.transform = "translate3d(0px, 0px, 0px)";
1018
+ }
1019
+ function resolveDiffUnchangedViewZoneHeight(unchangedRegionStyle) {
1020
+ return unchangedRegionStyle === "simple" ? 28 : 32;
1021
+ }
1022
+ function collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
1023
+ const widgetTopValues = Array.from(editorRoot.querySelectorAll(".diff-hidden-lines-widget")).map((node) => Number.parseFloat(node.style.top || "NaN")).filter((value) => Number.isFinite(value) && value > -1e5);
1024
+ if (widgetTopValues.length === 0) return [];
1025
+ return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
1026
+ const zoneTop = Number.parseFloat(node.style.top || "NaN");
1027
+ const currentHeight = Number.parseFloat(node.style.height || "0");
1028
+ return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
1029
+ }).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
1030
+ }
1031
+ function findDiffUnchangedActivationAction(...roots) {
1032
+ for (const root of roots) {
1033
+ const action = (root === null || root === void 0 ? void 0 : root.querySelector("a, button")) ?? null;
1034
+ if (action) return action;
1035
+ }
1036
+ return null;
1037
+ }
1038
+ function findDiffUnchangedExpandAction(root) {
1039
+ return (root === null || root === void 0 ? void 0 : root.querySelector("a")) ?? null;
1040
+ }
1041
+ function shouldIgnoreDiffUnchangedCenterClickTarget(target) {
1042
+ return target instanceof HTMLElement && Boolean(target.closest("a, .breadcrumb-item"));
1043
+ }
1044
+ function shouldHandleDiffUnchangedCenterClick(event) {
1045
+ return event.button === 0 && !shouldIgnoreDiffUnchangedCenterClickTarget(event.target);
1046
+ }
1047
+ function activateDiffUnchangedExpandAction(root, onBeforeActivate) {
1048
+ const action = findDiffUnchangedExpandAction(root);
1049
+ if (!action) return false;
1050
+ onBeforeActivate === null || onBeforeActivate === void 0 || onBeforeActivate(action);
1051
+ action.click();
1052
+ return true;
1053
+ }
1054
+ function syncDiffUnchangedCenterNode(node, mergeRole) {
1055
+ node.classList.add("stream-monaco-clickable");
1056
+ node.title = "Click to expand all unmodified lines";
1057
+ node.classList.toggle("stream-monaco-unchanged-merged-secondary", mergeRole === "secondary");
1058
+ node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
1059
+ }
1060
+ function syncDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
1061
+ const lastStyle = metaNode.dataset.style;
1062
+ const lastLabel = metaNode.dataset.label;
1063
+ if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
1064
+ metaNode.dataset.style = unchangedRegionStyle;
1065
+ metaNode.dataset.label = summaryLabel;
1066
+ metaNode.replaceChildren();
1067
+ metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
1068
+ if (unchangedRegionStyle === "simple") {
1069
+ const simpleBar = document.createElement("span");
1070
+ simpleBar.className = "stream-monaco-unchanged-simple-bar";
1071
+ simpleBar.setAttribute("aria-hidden", "true");
1072
+ metaNode.append(simpleBar);
1073
+ return;
1074
+ }
1075
+ const label = document.createElement("span");
1076
+ label.className = unchangedRegionStyle === "metadata" ? "stream-monaco-unchanged-metadata-label" : "stream-monaco-unchanged-count";
1077
+ label.textContent = summaryLabel;
1078
+ metaNode.append(label);
1079
+ }
1080
+ function syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel) {
1081
+ summary.classList.remove(...diffUnchangedSummaryStyleClasses);
1082
+ summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
1083
+ const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
1084
+ summary.disabled = !summaryInteractive;
1085
+ summary.tabIndex = summaryInteractive ? 0 : -1;
1086
+ if (summaryInteractive) {
1087
+ summary.removeAttribute("aria-hidden");
1088
+ summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
1089
+ summary.title = "Expand all unmodified lines";
1090
+ return;
1091
+ }
1092
+ if (unchangedRegionStyle === "simple") {
1093
+ summary.setAttribute("aria-hidden", "true");
1094
+ summary.removeAttribute("aria-label");
1095
+ summary.title = "";
1096
+ return;
1097
+ }
1098
+ summary.removeAttribute("aria-hidden");
1099
+ summary.removeAttribute("aria-label");
1100
+ summary.title = "";
1101
+ }
1102
+ function syncDiffUnchangedExpandAction(action, hidden) {
1103
+ action.classList.add("stream-monaco-unchanged-expand");
1104
+ action.dataset.streamMonacoLabel = "Expand all";
1105
+ action.title = "Expand all unmodified lines";
1106
+ action.setAttribute("aria-label", "Expand all unmodified lines");
1107
+ action.toggleAttribute("aria-hidden", hidden);
1108
+ action.tabIndex = hidden ? -1 : 0;
1109
+ }
1110
+ function createDiffUnchangedRevealButton(direction) {
1111
+ const button = document.createElement("button");
1112
+ button.type = "button";
1113
+ button.className = "stream-monaco-unchanged-reveal";
1114
+ button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
1115
+ button.dataset.direction = direction;
1116
+ return button;
1117
+ }
1118
+ function syncDiffUnchangedRevealButtonNode(button, handle, label) {
1119
+ button.hidden = !handle;
1120
+ button.disabled = !handle;
1121
+ button.toggleAttribute("aria-hidden", !handle);
1122
+ button.title = handle ? label : "";
1123
+ button.setAttribute("aria-label", handle ? label : "");
1124
+ }
1125
+ function bindDiffUnchangedRevealButtonAction(button, handle, onActivate) {
1126
+ button.onclick = handle ? (event) => {
1127
+ event.preventDefault();
1128
+ event.stopPropagation();
1129
+ onActivate(handle);
1130
+ } : null;
1131
+ }
1132
+ function shouldHandleDiffUnchangedWheel(event) {
1133
+ return Math.abs(event.deltaY) >= .5 || Math.abs(event.deltaX) >= .5;
1134
+ }
1135
+ function resolveDiffUnchangedWheelScrollTarget(scrollTop, scrollLeft, event) {
1136
+ return {
1137
+ targetScrollTop: scrollTop + event.deltaY,
1138
+ targetScrollLeft: scrollLeft + event.deltaX,
1139
+ syncHorizontal: Math.abs(event.deltaX) >= .5
1140
+ };
1141
+ }
1142
+ function syncDiffUnchangedBridgeNode(options) {
1143
+ const { bridge, bridgeLeftInset, bridgeRailWidth, containerRect, containerScrollLeft, containerScrollTop, editorBackgroundColor, primaryAnchorRect, primaryStyle, secondaryAnchorRect, unchangedRegionStyle } = options;
1144
+ bridge.className = "stream-monaco-diff-unchanged-bridge";
1145
+ bridge.classList.add(`stream-monaco-diff-unchanged-bridge-${unchangedRegionStyle}`);
1146
+ bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + containerScrollLeft + bridgeLeftInset}px`;
1147
+ bridge.style.top = `${primaryAnchorRect.top - containerRect.top + containerScrollTop}px`;
1148
+ bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
1149
+ bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
1150
+ bridge.style.color = primaryStyle.color;
1151
+ bridge.style.fontFamily = primaryStyle.fontFamily;
1152
+ bridge.style.fontSize = primaryStyle.fontSize;
1153
+ bridge.style.lineHeight = primaryStyle.lineHeight;
1154
+ bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
1155
+ bridge.style.setProperty("--stream-monaco-editor-bg", editorBackgroundColor);
1156
+ bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
1157
+ if (bridgeRailWidth) {
1158
+ bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
1159
+ return;
1160
+ }
1161
+ bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
1162
+ }
1163
+ function syncDiffUnchangedRailNode(rail, showTopHandle, showBottomHandle) {
1164
+ const shouldRenderRail = showTopHandle || showBottomHandle;
1165
+ rail.hidden = !shouldRenderRail;
1166
+ rail.toggleAttribute("aria-hidden", !shouldRenderRail);
1167
+ rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
1168
+ rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
1169
+ rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
1170
+ }
1171
+ function dispatchSyntheticPrimaryMouseDown(node) {
1172
+ const view = node.ownerDocument.defaultView;
1173
+ if (!view) return;
1174
+ const rect = node.getBoundingClientRect();
1175
+ node.dispatchEvent(new view.MouseEvent("mousedown", {
1176
+ bubbles: true,
1177
+ cancelable: true,
1178
+ button: 0,
1179
+ clientX: rect.left + rect.width / 2,
1180
+ clientY: rect.top + rect.height / 2
1181
+ }));
1182
+ }
1183
+ function dispatchSyntheticPrimaryMouseTap(node) {
1184
+ const view = node.ownerDocument.defaultView;
1185
+ if (!view) return;
1186
+ const rect = node.getBoundingClientRect();
1187
+ const clientX = rect.left + rect.width / 2;
1188
+ const clientY = rect.top + rect.height / 2;
1189
+ node.dispatchEvent(new view.MouseEvent("mousedown", {
1190
+ bubbles: true,
1191
+ cancelable: true,
1192
+ button: 0,
1193
+ clientX,
1194
+ clientY
1195
+ }));
1196
+ node.dispatchEvent(new view.MouseEvent("mouseup", {
1197
+ bubbles: true,
1198
+ cancelable: true,
1199
+ button: 0,
1200
+ clientX,
1201
+ clientY
1202
+ }));
1203
+ }
1204
+
1205
+ //#endregion
1206
+ //#region src/core/diffViewport.ts
1207
+ function computeDiffRawHeight({ diffEditorView, maxHeightValue }) {
1208
+ var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
1209
+ if (!diffEditorView) return Math.min(18 + padding, maxHeightValue);
1210
+ const modifiedEditor = diffEditorView.getModifiedEditor();
1211
+ const originalEditor = diffEditorView.getOriginalEditor();
1212
+ const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
1213
+ const originalLineCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
1214
+ const modifiedLineCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
1215
+ const lineCount = Math.max(originalLineCount, modifiedLineCount);
1216
+ const fromLines = lineCount * lineHeight + padding;
1217
+ const scrollHeight = Math.max(((_originalEditor$getSc = originalEditor.getScrollHeight) === null || _originalEditor$getSc === void 0 ? void 0 : _originalEditor$getSc.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc === void 0 ? void 0 : _modifiedEditor$getSc.call(modifiedEditor)) ?? 0);
1218
+ return Math.min(Math.max(fromLines, scrollHeight), maxHeightValue);
1219
+ }
1220
+ function computeDiffHeight({ inlineDiffStreamingHeightFloor, inlineDiffStreamingPresentationActive, isInlineMode, rawHeight }) {
1221
+ if (!isInlineMode || !inlineDiffStreamingPresentationActive && inlineDiffStreamingHeightFloor <= 0) return {
1222
+ height: rawHeight,
1223
+ nextInlineDiffStreamingHeightFloor: inlineDiffStreamingHeightFloor
1224
+ };
1225
+ const nextInlineDiffStreamingHeightFloor = Math.max(rawHeight, inlineDiffStreamingHeightFloor);
1226
+ return {
1227
+ height: nextInlineDiffStreamingHeightFloor,
1228
+ nextInlineDiffStreamingHeightFloor
1229
+ };
1230
+ }
1231
+ function readContainerLayoutSize(container) {
1232
+ var _container$getBoundin;
1233
+ const rect = (_container$getBoundin = container.getBoundingClientRect) === null || _container$getBoundin === void 0 ? void 0 : _container$getBoundin.call(container);
1234
+ return {
1235
+ width: container.clientWidth || (rect === null || rect === void 0 ? void 0 : rect.width) || 0,
1236
+ height: container.clientHeight || (rect === null || rect === void 0 ? void 0 : rect.height) || 0
1237
+ };
1238
+ }
1239
+ function hasVerticalScrollbar(measurement) {
1240
+ const epsilon = Math.max(2, Math.round(measurement.lineHeight / 8));
1241
+ return measurement.scrollHeight > measurement.computedHeight + Math.max(padding / 2, epsilon);
1242
+ }
1243
+ function isUserNearBottom(measurement, options) {
1244
+ const lineThreshold = options.autoScrollThresholdLines * measurement.lineHeight;
1245
+ const threshold = Math.max(lineThreshold || 0, options.autoScrollThresholdPx);
1246
+ const distance = measurement.scrollHeight - (measurement.scrollTop + measurement.viewportHeight);
1247
+ return distance <= threshold;
1248
+ }
1249
+ function revealEditorLine(editor, line, strategy, scrollType) {
1250
+ if (strategy === "bottom") {
1251
+ if (typeof scrollType !== "undefined") editor.revealLine(line, scrollType);
1252
+ else editor.revealLine(line);
1253
+ return;
1254
+ }
1255
+ if (strategy === "center") {
1256
+ if (typeof scrollType !== "undefined") editor.revealLineInCenter(line, scrollType);
1257
+ else editor.revealLineInCenter(line);
1258
+ return;
1259
+ }
1260
+ if (typeof scrollType !== "undefined") editor.revealLineInCenterIfOutsideViewport(line, scrollType);
1261
+ else editor.revealLineInCenterIfOutsideViewport(line);
1262
+ }
1263
+ function waitForElementHeightApplied(element, target, timeoutMs = 500) {
1264
+ return new Promise((resolve) => {
1265
+ const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1266
+ const check = () => {
1267
+ const applied = element ? Number.parseFloat((element.style.height || "").replace("px", "")) || 0 : -1;
1268
+ if (applied >= target - 1) {
1269
+ resolve();
1270
+ return;
1271
+ }
1272
+ const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1273
+ if (now - start > timeoutMs) {
1274
+ resolve();
1275
+ return;
1276
+ }
1277
+ requestAnimationFrame(check);
1278
+ };
1279
+ check();
1280
+ });
1281
+ }
1282
+
475
1283
  //#endregion
476
1284
  //#region src/core/DiffEditorManager.ts
477
1285
  var DiffEditorManager = class DiffEditorManager {
@@ -495,6 +1303,8 @@ var DiffEditorManager = class DiffEditorManager {
495
1303
  lastKnownModifiedCode = null;
496
1304
  lastKnownModifiedLineCount = null;
497
1305
  pendingDiffUpdate = null;
1306
+ minimalEditMaxCharsValue = minimalEditMaxChars;
1307
+ minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
498
1308
  shouldAutoScrollDiff = true;
499
1309
  diffScrollWatcher = null;
500
1310
  lastScrollTopDiff = 0;
@@ -503,6 +1313,7 @@ var DiffEditorManager = class DiffEditorManager {
503
1313
  cachedLineHeightDiff = null;
504
1314
  cachedComputedHeightDiff = null;
505
1315
  lastKnownModifiedDirty = false;
1316
+ programmaticModifiedContentChangeDepth = 0;
506
1317
  measureViewportDiff() {
507
1318
  var _me$getLayoutInfo, _me$getScrollTop, _me$getScrollHeight;
508
1319
  if (!this.diffEditorView) return null;
@@ -555,8 +1366,14 @@ var DiffEditorManager = class DiffEditorManager {
555
1366
  diffComputedVersions = null;
556
1367
  preserveNativeDiffDecorationsOnStaleAppend = false;
557
1368
  diffPresentationDisposables = [];
1369
+ diffPresentationObserver = null;
558
1370
  fallbackOriginalDecorationIds = [];
559
1371
  fallbackModifiedDecorationIds = [];
1372
+ fallbackInlineDeletedZoneIds = [];
1373
+ fallbackInlineDeletedZoneSignature = null;
1374
+ inlineDiffStreamingPresentationActive = false;
1375
+ inlineDiffStreamingPresentationIdleTimer = null;
1376
+ inlineDiffStreamingHeightFloor = 0;
560
1377
  diffHunkHideTimer = null;
561
1378
  diffUnchangedRegionDisposables = [];
562
1379
  diffUnchangedRegionObserver = null;
@@ -569,9 +1386,11 @@ var DiffEditorManager = class DiffEditorManager {
569
1386
  diffUnchangedOverlayScrollLeft = 0;
570
1387
  diffRootAppearanceSignature = null;
571
1388
  diffPersistedUnchangedModelState = null;
1389
+ diffPreviousUnchangedModelState = null;
572
1390
  pendingPreparedDiffViewModel = null;
573
1391
  cancelRafs() {
574
1392
  this.rafScheduler.cancel("sync-diff-presentation");
1393
+ this.rafScheduler.cancel("sync-diff-layout");
575
1394
  this.rafScheduler.cancel("capture-diff-unchanged-state");
576
1395
  this.rafScheduler.cancel("restore-diff-unchanged-state");
577
1396
  this.rafScheduler.cancel("patch-diff-unchanged-regions");
@@ -634,6 +1453,8 @@ var DiffEditorManager = class DiffEditorManager {
634
1453
  this.diffAutoScroll = diffAutoScroll;
635
1454
  this.revealDebounceMsOption = revealDebounceMsOption;
636
1455
  this.diffUpdateThrottleMsOption = diffUpdateThrottleMsOption;
1456
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
1457
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
637
1458
  }
638
1459
  resolveDiffHideUnchangedRegionsOption() {
639
1460
  const normalize = (value) => {
@@ -658,6 +1479,9 @@ var DiffEditorManager = class DiffEditorManager {
658
1479
  revealLineCount: 5
659
1480
  };
660
1481
  }
1482
+ resolveDiffGlyphMarginOption(hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption()) {
1483
+ return (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) ? true : this.options.glyphMargin;
1484
+ }
661
1485
  resolveDiffLineStyleOption() {
662
1486
  return this.options.diffLineStyle === "bar" ? "bar" : "background";
663
1487
  }
@@ -671,188 +1495,21 @@ var DiffEditorManager = class DiffEditorManager {
671
1495
  if (typeof explicitThrottle === "number") return explicitThrottle;
672
1496
  return 50;
673
1497
  }
674
- parseCssColorRgb(color) {
675
- const normalized = color.trim().toLowerCase();
676
- const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
677
- if (rgbMatch) return [
678
- Number.parseFloat(rgbMatch[1]),
679
- Number.parseFloat(rgbMatch[2]),
680
- Number.parseFloat(rgbMatch[3])
681
- ];
682
- const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
683
- if (!hexMatch) return null;
684
- const hex = hexMatch[1];
685
- if (hex.length === 3 || hex.length === 4) return [
686
- Number.parseInt(`${hex[0]}${hex[0]}`, 16),
687
- Number.parseInt(`${hex[1]}${hex[1]}`, 16),
688
- Number.parseInt(`${hex[2]}${hex[2]}`, 16)
689
- ];
690
- if (hex.length === 6 || hex.length === 8) return [
691
- Number.parseInt(hex.slice(0, 2), 16),
692
- Number.parseInt(hex.slice(2, 4), 16),
693
- Number.parseInt(hex.slice(4, 6), 16)
694
- ];
695
- return null;
696
- }
697
- resolveCssColorLuminance(color) {
698
- const rgb = this.parseCssColorRgb(color);
699
- if (!rgb) return null;
700
- const channel = (value) => {
701
- const normalized = Math.max(0, Math.min(255, value)) / 255;
702
- return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
703
- };
704
- const [r, g, b] = rgb;
705
- return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
706
- }
707
- resolveDiffUnchangedLineInfoRailMetrics(node) {
708
- const editorRoot = node.closest(".monaco-editor");
709
- if (!editorRoot) return {
710
- leftInset: 0,
711
- width: null
712
- };
713
- const editorRect = editorRoot.getBoundingClientRect();
714
- const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
715
- const rect = candidate.getBoundingClientRect();
716
- return rect.width > 0 && rect.height > 0;
717
- });
718
- if (!lineNumberNode) return {
719
- leftInset: 0,
720
- width: null
721
- };
722
- const lineNumberRect = lineNumberNode.getBoundingClientRect();
723
- return {
724
- leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
725
- width: Math.max(0, lineNumberRect.width) || null
726
- };
727
- }
728
- looksLikeDarkThemeName(themeName) {
729
- if (!themeName) return false;
730
- const normalized = themeName.toLowerCase();
731
- return [
732
- "dark",
733
- "night",
734
- "moon",
735
- "black",
736
- "dracula",
737
- "mocha",
738
- "frappe",
739
- "macchiato",
740
- "palenight",
741
- "ocean",
742
- "poimandres",
743
- "monokai",
744
- "laserwave",
745
- "tokyo",
746
- "slack-dark",
747
- "rose-pine",
748
- "github-dark",
749
- "material-theme",
750
- "one-dark",
751
- "catppuccin-mocha",
752
- "catppuccin-frappe",
753
- "catppuccin-macchiato"
754
- ].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
755
- }
756
- looksLikeLightThemeName(themeName) {
757
- if (!themeName) return false;
758
- const normalized = themeName.toLowerCase();
759
- return [
760
- "light",
761
- "day",
762
- "dawn",
763
- "latte",
764
- "solarized-light",
765
- "github-light",
766
- "rose-pine-dawn",
767
- "catppuccin-latte",
768
- "one-light",
769
- "vitesse-light",
770
- "snazzy-light",
771
- "material-lighter",
772
- "material-theme-lighter",
773
- "lotus"
774
- ].some((token) => normalized.includes(token));
775
- }
776
- resolveDiffAppearanceOption() {
777
- var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2, _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
778
- if (this.options.diffAppearance === "light") return "light";
779
- if (this.options.diffAppearance === "dark") return "dark";
780
- if (this.looksLikeDarkThemeName(this.options.theme)) return "dark";
781
- if (this.looksLikeLightThemeName(this.options.theme)) return "light";
782
- const appearanceProbeNodes = [
783
- (_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 || (_this$diffEditorView$2 = (_this$diffEditorView$ = _this$diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$),
784
- (_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 || (_this$diffEditorView4 = (_this$diffEditorView3 = _this$diffEditorView2.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView4 === void 0 ? void 0 : _this$diffEditorView4.call(_this$diffEditorView3),
785
- this.lastContainer
786
- ];
787
- for (const node of appearanceProbeNodes) {
788
- if (!(node instanceof HTMLElement)) continue;
789
- const style = globalThis.getComputedStyle(node);
790
- const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
791
- const candidates = [
792
- style.getPropertyValue("--stream-monaco-editor-bg"),
793
- style.getPropertyValue("--vscode-editor-background"),
794
- editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
795
- style.backgroundColor
796
- ];
797
- for (const color of candidates) {
798
- const luminance = this.resolveCssColorLuminance(color);
799
- if (luminance == null) continue;
800
- return luminance <= .42 ? "dark" : "light";
801
- }
802
- }
803
- return this.looksLikeDarkThemeName(this.options.theme) ? "dark" : "light";
804
- }
805
- syncDiffRootThemeVariables(appearance) {
806
- var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7, _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10;
807
- if (!(this.lastContainer instanceof HTMLElement)) return;
808
- const probeNodes = [
809
- (_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || (_this$diffEditorView7 = (_this$diffEditorView6 = _this$diffEditorView5.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.call(_this$diffEditorView6),
810
- (_this$diffEditorView8 = this.diffEditorView) === null || _this$diffEditorView8 === void 0 || (_this$diffEditorView10 = (_this$diffEditorView9 = _this$diffEditorView8.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView10 === void 0 ? void 0 : _this$diffEditorView10.call(_this$diffEditorView9),
811
- this.lastContainer
812
- ];
813
- const containerStyle = globalThis.getComputedStyle(this.lastContainer);
814
- const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
815
- let backgroundColor = null;
816
- let foregroundColor = null;
817
- for (const node of probeNodes) {
818
- if (!(node instanceof HTMLElement)) continue;
819
- const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
820
- const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
821
- const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
822
- if (!backgroundColor && this.resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
823
- const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
824
- if (!foregroundColor && this.resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
825
- if (backgroundColor && foregroundColor) break;
826
- }
827
- const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
828
- if (resolvedBackgroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
829
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-bg");
830
- if (foregroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
831
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
832
- }
833
1498
  applyDiffRootAppearanceClass() {
834
- if (!this.lastContainer) return;
835
- const resolvedAppearance = this.resolveDiffAppearanceOption();
836
- this.syncDiffRootThemeVariables(resolvedAppearance);
837
- const containerClassList = this.lastContainer.classList;
838
- const activeLineStyleClass = `stream-monaco-diff-style-${this.resolveDiffLineStyleOption()}`;
839
- const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${this.resolveDiffUnchangedRegionStyleOption()}`;
840
- const sideBySide = !this.isDiffInlineMode();
841
- const activeLayoutModeClass = sideBySide ? "stream-monaco-diff-side-by-side" : "stream-monaco-diff-inline";
842
- const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
843
- const nextSignature = [
844
- activeLineStyleClass,
845
- activeUnchangedRegionStyleClass,
846
- activeLayoutModeClass,
847
- activeAppearanceClass
848
- ].join("|");
849
- if (this.diffRootAppearanceSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return;
850
- containerClassList.add("stream-monaco-diff-root");
851
- for (const className of DiffEditorManager.diffLineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
852
- for (const className of DiffEditorManager.diffUnchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
853
- for (const className of DiffEditorManager.diffLayoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
854
- for (const className of DiffEditorManager.diffAppearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
855
- this.diffRootAppearanceSignature = nextSignature;
1499
+ this.diffRootAppearanceSignature = applyDiffRootAppearanceClass({
1500
+ container: this.lastContainer,
1501
+ diffEditorView: this.diffEditorView,
1502
+ diffAppearance: this.options.diffAppearance,
1503
+ themeName: this.options.theme ?? null,
1504
+ currentSignature: this.diffRootAppearanceSignature,
1505
+ lineStyle: this.resolveDiffLineStyleOption(),
1506
+ unchangedRegionStyle: this.resolveDiffUnchangedRegionStyleOption(),
1507
+ isInlineMode: this.isDiffInlineMode(),
1508
+ lineStyleClasses: DiffEditorManager.diffLineStyleClasses,
1509
+ unchangedRegionStyleClasses: DiffEditorManager.diffUnchangedRegionStyleClasses,
1510
+ layoutModeClasses: DiffEditorManager.diffLayoutModeClasses,
1511
+ appearanceClasses: DiffEditorManager.diffAppearanceClasses
1512
+ });
856
1513
  }
857
1514
  disposeDiffHunkInteractions() {
858
1515
  if (this.diffHunkHideTimer != null) {
@@ -980,13 +1637,226 @@ var DiffEditorManager = class DiffEditorManager {
980
1637
  });
981
1638
  }
982
1639
  clearFallbackDiffDecorations() {
983
- var _this$diffEditorView11, _this$diffEditorView12;
984
- const originalEditor = (_this$diffEditorView11 = this.diffEditorView) === null || _this$diffEditorView11 === void 0 ? void 0 : _this$diffEditorView11.getOriginalEditor();
985
- const modifiedEditor = (_this$diffEditorView12 = this.diffEditorView) === null || _this$diffEditorView12 === void 0 ? void 0 : _this$diffEditorView12.getModifiedEditor();
1640
+ var _this$diffEditorView, _this$diffEditorView2;
1641
+ const originalEditor = (_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 ? void 0 : _this$diffEditorView.getOriginalEditor();
1642
+ const modifiedEditor = (_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 ? void 0 : _this$diffEditorView2.getModifiedEditor();
986
1643
  if (originalEditor && this.fallbackOriginalDecorationIds.length > 0) this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, []);
987
1644
  else this.fallbackOriginalDecorationIds = [];
988
1645
  if (modifiedEditor && this.fallbackModifiedDecorationIds.length > 0) this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, []);
989
1646
  else this.fallbackModifiedDecorationIds = [];
1647
+ this.clearFallbackInlineDeletedZones();
1648
+ }
1649
+ clearFallbackInlineDeletedZones() {
1650
+ var _this$diffEditorView3;
1651
+ const modifiedEditor = (_this$diffEditorView3 = this.diffEditorView) === null || _this$diffEditorView3 === void 0 ? void 0 : _this$diffEditorView3.getModifiedEditor();
1652
+ if (modifiedEditor && this.fallbackInlineDeletedZoneIds.length > 0) try {
1653
+ var _modifiedEditor$chang;
1654
+ (_modifiedEditor$chang = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang === void 0 || _modifiedEditor$chang.call(modifiedEditor, (accessor) => {
1655
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1656
+ });
1657
+ } catch {}
1658
+ this.fallbackInlineDeletedZoneIds = [];
1659
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1660
+ this.fallbackInlineDeletedZoneSignature = null;
1661
+ }
1662
+ clearFallbackInlineDeletedZoneWrapperContent() {
1663
+ var _this$lastContainer, _this$lastContainer2, _node$parentElement;
1664
+ const querySelectorAll = typeof ((_this$lastContainer = this.lastContainer) === null || _this$lastContainer === void 0 ? void 0 : _this$lastContainer.querySelectorAll) === "function" ? (_this$lastContainer2 = this.lastContainer) === null || _this$lastContainer2 === void 0 ? void 0 : _this$lastContainer2.querySelectorAll.bind(this.lastContainer) : null;
1665
+ if (!querySelectorAll) return;
1666
+ const nodes = Array.from(querySelectorAll(".stream-monaco-fallback-inline-delete-zone[data-stream-monaco-native-wrapper=\"true\"], .stream-monaco-fallback-inline-delete-margin[data-stream-monaco-native-wrapper=\"true\"]") ?? []);
1667
+ for (const node of nodes) (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 || _node$parentElement.removeChild(node);
1668
+ }
1669
+ clearInlineDiffStreamingPresentationIdleTimer() {
1670
+ if (this.inlineDiffStreamingPresentationIdleTimer != null) {
1671
+ clearTimeout(this.inlineDiffStreamingPresentationIdleTimer);
1672
+ this.inlineDiffStreamingPresentationIdleTimer = null;
1673
+ }
1674
+ }
1675
+ resetInlineDiffStreamingHeightFloor() {
1676
+ this.inlineDiffStreamingHeightFloor = 0;
1677
+ }
1678
+ syncDiffEditorLayoutToContainer() {
1679
+ if (!this.diffEditorView || !this.lastContainer) return;
1680
+ const { width, height } = readContainerLayoutSize(this.lastContainer);
1681
+ if (!(width > 0) || !(height > 0)) return;
1682
+ try {
1683
+ var _layout, _ref;
1684
+ (_layout = (_ref = this.diffEditorView).layout) === null || _layout === void 0 || _layout.call(_ref, {
1685
+ width: Math.round(width),
1686
+ height: Math.round(height)
1687
+ });
1688
+ } catch {
1689
+ try {
1690
+ var _layout2, _ref2;
1691
+ (_layout2 = (_ref2 = this.diffEditorView).layout) === null || _layout2 === void 0 || _layout2.call(_ref2);
1692
+ } catch {}
1693
+ }
1694
+ }
1695
+ scheduleSyncDiffEditorLayoutToContainer() {
1696
+ this.rafScheduler.schedule("sync-diff-layout", () => {
1697
+ this.syncDiffEditorLayoutToContainer();
1698
+ });
1699
+ }
1700
+ readModelLineContent(model, lineNumber) {
1701
+ const direct = model.getLineContent;
1702
+ if (typeof direct === "function") return direct.call(model, lineNumber);
1703
+ return model.getValue().split(/\r?\n/)[lineNumber - 1] ?? "";
1704
+ }
1705
+ hasVisibleNativeInlineDeleteNodes() {
1706
+ if (!this.lastContainer) return false;
1707
+ const querySelectorAll = typeof this.lastContainer.querySelectorAll === "function" ? this.lastContainer.querySelectorAll.bind(this.lastContainer) : null;
1708
+ if (!querySelectorAll) return false;
1709
+ const nodes = Array.from(querySelectorAll(".editor.modified .view-zones .line-delete, .editor.modified .inline-deleted-text, .editor.modified .inline-deleted-margin-view-zone") ?? []);
1710
+ return nodes.some((node) => {
1711
+ var _node$getBoundingClie, _globalThis$getComput, _globalThis;
1712
+ if (!(node instanceof HTMLElement)) return false;
1713
+ const rect = (_node$getBoundingClie = node.getBoundingClientRect) === null || _node$getBoundingClie === void 0 ? void 0 : _node$getBoundingClie.call(node);
1714
+ const style = (_globalThis$getComput = (_globalThis = globalThis).getComputedStyle) === null || _globalThis$getComput === void 0 ? void 0 : _globalThis$getComput.call(_globalThis, node);
1715
+ return ((rect === null || rect === void 0 ? void 0 : rect.width) ?? 0) > 0 && ((rect === null || rect === void 0 ? void 0 : rect.height) ?? 0) > 0 && (style === null || style === void 0 ? void 0 : style.display) !== "none" && (style === null || style === void 0 ? void 0 : style.visibility) !== "hidden" && Number.parseFloat((style === null || style === void 0 ? void 0 : style.opacity) || "1") > .01;
1716
+ });
1717
+ }
1718
+ countNativeInlineDeleteZoneNodes() {
1719
+ if (!this.lastContainer) return 0;
1720
+ const querySelectorAll = typeof this.lastContainer.querySelectorAll === "function" ? this.lastContainer.querySelectorAll.bind(this.lastContainer) : null;
1721
+ if (!querySelectorAll) return 0;
1722
+ const nodes = Array.from(querySelectorAll(".editor.modified .view-zones [monaco-view-zone], .editor.modified .margin-view-zones [monaco-view-zone]") ?? []);
1723
+ return nodes.filter((node) => {
1724
+ if (!(node instanceof HTMLElement)) return false;
1725
+ return node.matches(".view-lines.line-delete") || !!node.querySelector(".view-lines.line-delete") || node.matches(".inline-deleted-margin-view-zone") || !!node.querySelector(".inline-deleted-margin-view-zone");
1726
+ }).length;
1727
+ }
1728
+ syncFallbackInlineDeletedZones(lineChanges) {
1729
+ var _modifiedEditor$getMo, _EditorOption, _modifiedEditor$getOp, _this$lastContainer3, _this$lastContainer3$, _this$lastContainer4, _this$lastContainer4$;
1730
+ if (typeof document === "undefined" || !this.diffEditorView || !this.originalModel || !this.isDiffInlineMode()) {
1731
+ this.clearFallbackInlineDeletedZones();
1732
+ return;
1733
+ }
1734
+ const modifiedEditor = this.diffEditorView.getModifiedEditor();
1735
+ const modifiedModel = modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getMo = modifiedEditor.getModel) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.call(modifiedEditor);
1736
+ const originalModel = this.originalModel;
1737
+ if (!modifiedEditor || !modifiedModel || !originalModel) {
1738
+ this.fallbackInlineDeletedZoneIds = [];
1739
+ return;
1740
+ }
1741
+ const lineHeightOption = (_EditorOption = monaco_shim_exports.editor.EditorOption) === null || _EditorOption === void 0 ? void 0 : _EditorOption.lineHeight;
1742
+ const lineHeight = ((_modifiedEditor$getOp = modifiedEditor.getOption) === null || _modifiedEditor$getOp === void 0 ? void 0 : _modifiedEditor$getOp.call(modifiedEditor, lineHeightOption)) ?? 20;
1743
+ const relevantChanges = lineChanges.filter((change) => hasOriginalLines(change));
1744
+ const nativeViewWrappers = Array.from(((_this$lastContainer3 = this.lastContainer) === null || _this$lastContainer3 === void 0 || (_this$lastContainer3$ = _this$lastContainer3.querySelectorAll) === null || _this$lastContainer3$ === void 0 ? void 0 : _this$lastContainer3$.call(_this$lastContainer3, ".editor.modified .view-zones [monaco-view-zone]")) ?? []).filter((node) => {
1745
+ return node instanceof HTMLElement && !!node.querySelector(".view-lines.line-delete");
1746
+ });
1747
+ const nativeMarginWrappers = Array.from(((_this$lastContainer4 = this.lastContainer) === null || _this$lastContainer4 === void 0 || (_this$lastContainer4$ = _this$lastContainer4.querySelectorAll) === null || _this$lastContainer4$ === void 0 ? void 0 : _this$lastContainer4$.call(_this$lastContainer4, ".editor.modified .margin-view-zones [monaco-view-zone]")) ?? []).filter((node) => {
1748
+ return node instanceof HTMLElement && !!node.querySelector(".inline-deleted-margin-view-zone");
1749
+ });
1750
+ const nativePairs = nativeViewWrappers.map((viewWrapper) => {
1751
+ const id = viewWrapper.getAttribute("monaco-view-zone");
1752
+ if (!id) return null;
1753
+ const marginWrapper = nativeMarginWrappers.find((candidate) => candidate.getAttribute("monaco-view-zone") === id);
1754
+ return {
1755
+ id,
1756
+ top: Number.parseFloat(viewWrapper.style.top || "NaN"),
1757
+ viewWrapper,
1758
+ marginWrapper: marginWrapper ?? null
1759
+ };
1760
+ }).filter((entry) => !!entry && Number.isFinite(entry.top)).sort((left, right) => left.top - right.top);
1761
+ if (nativePairs.length >= relevantChanges.length && relevantChanges.length > 0) {
1762
+ const nextSignature$1 = nativePairs.slice(0, relevantChanges.length).map((pair, index) => {
1763
+ const change = relevantChanges[index];
1764
+ const text = Array.from({ length: change.originalEndLineNumber - change.originalStartLineNumber + 1 }, (_, offset) => this.readModelLineContent(originalModel, change.originalStartLineNumber + offset)).join("\n");
1765
+ return `${pair.id}:${text}`;
1766
+ }).join("|");
1767
+ if (nextSignature$1 && this.fallbackInlineDeletedZoneSignature === nextSignature$1 && this.fallbackInlineDeletedZoneIds.length === 0) return;
1768
+ if (this.fallbackInlineDeletedZoneIds.length > 0) {
1769
+ try {
1770
+ var _modifiedEditor$chang2;
1771
+ (_modifiedEditor$chang2 = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang2 === void 0 || _modifiedEditor$chang2.call(modifiedEditor, (accessor) => {
1772
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1773
+ });
1774
+ } catch {}
1775
+ this.fallbackInlineDeletedZoneIds = [];
1776
+ }
1777
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1778
+ relevantChanges.forEach((change, index) => {
1779
+ var _modifiedEditor$apply;
1780
+ const pair = nativePairs[index];
1781
+ const domNode = document.createElement("div");
1782
+ domNode.className = "stream-monaco-fallback-inline-delete-zone";
1783
+ domNode.setAttribute("aria-hidden", "true");
1784
+ domNode.setAttribute("data-stream-monaco-native-wrapper", "true");
1785
+ (_modifiedEditor$apply = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply === void 0 || _modifiedEditor$apply.call(modifiedEditor, domNode);
1786
+ for (let line = change.originalStartLineNumber; line <= change.originalEndLineNumber; line++) {
1787
+ const lineNode = document.createElement("div");
1788
+ lineNode.className = "stream-monaco-fallback-inline-delete-line";
1789
+ lineNode.textContent = this.readModelLineContent(originalModel, line);
1790
+ lineNode.style.height = `${lineHeight}px`;
1791
+ lineNode.style.lineHeight = `${lineHeight}px`;
1792
+ domNode.append(lineNode);
1793
+ }
1794
+ pair.viewWrapper.append(domNode);
1795
+ if (pair.marginWrapper) {
1796
+ var _modifiedEditor$apply2;
1797
+ const marginDomNode = document.createElement("div");
1798
+ marginDomNode.className = "stream-monaco-fallback-inline-delete-margin";
1799
+ marginDomNode.setAttribute("aria-hidden", "true");
1800
+ marginDomNode.setAttribute("data-stream-monaco-native-wrapper", "true");
1801
+ marginDomNode.style.height = "100%";
1802
+ (_modifiedEditor$apply2 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply2 === void 0 || _modifiedEditor$apply2.call(modifiedEditor, marginDomNode);
1803
+ pair.marginWrapper.append(marginDomNode);
1804
+ }
1805
+ });
1806
+ this.fallbackInlineDeletedZoneSignature = nextSignature$1 || null;
1807
+ return;
1808
+ }
1809
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1810
+ const nextZones = relevantChanges.map((change) => {
1811
+ var _modifiedEditor$apply3, _modifiedEditor$apply4;
1812
+ const lineCount = change.originalEndLineNumber - change.originalStartLineNumber + 1;
1813
+ if (lineCount < 1) return null;
1814
+ const domNode = document.createElement("div");
1815
+ domNode.className = "stream-monaco-fallback-inline-delete-zone";
1816
+ domNode.setAttribute("aria-hidden", "true");
1817
+ (_modifiedEditor$apply3 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply3 === void 0 || _modifiedEditor$apply3.call(modifiedEditor, domNode);
1818
+ for (let line = change.originalStartLineNumber; line <= change.originalEndLineNumber; line++) {
1819
+ const lineNode = document.createElement("div");
1820
+ lineNode.className = "stream-monaco-fallback-inline-delete-line";
1821
+ lineNode.textContent = this.readModelLineContent(originalModel, line);
1822
+ lineNode.style.height = `${lineHeight}px`;
1823
+ lineNode.style.lineHeight = `${lineHeight}px`;
1824
+ domNode.append(lineNode);
1825
+ }
1826
+ const marginDomNode = document.createElement("div");
1827
+ marginDomNode.className = "stream-monaco-fallback-inline-delete-margin";
1828
+ marginDomNode.setAttribute("aria-hidden", "true");
1829
+ (_modifiedEditor$apply4 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply4 === void 0 || _modifiedEditor$apply4.call(modifiedEditor, marginDomNode);
1830
+ const anchorLine = Math.max(0, Math.min(modifiedModel.getLineCount(), (change.modifiedStartLineNumber || 1) - 1));
1831
+ return {
1832
+ afterLineNumber: anchorLine,
1833
+ heightInLines: lineCount,
1834
+ domNode,
1835
+ marginDomNode
1836
+ };
1837
+ }).filter(Boolean);
1838
+ const nextSignature = nextZones.map((zone) => {
1839
+ var _zone$domNode;
1840
+ const text = typeof ((_zone$domNode = zone.domNode) === null || _zone$domNode === void 0 ? void 0 : _zone$domNode.textContent) === "string" ? zone.domNode.textContent : "";
1841
+ return `${zone.afterLineNumber}:${zone.heightInLines}:${text}`;
1842
+ }).join("|");
1843
+ if (nextSignature && this.fallbackInlineDeletedZoneSignature === nextSignature && this.fallbackInlineDeletedZoneIds.length === nextZones.length) return;
1844
+ try {
1845
+ var _modifiedEditor$chang3;
1846
+ (_modifiedEditor$chang3 = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang3 === void 0 || _modifiedEditor$chang3.call(modifiedEditor, (accessor) => {
1847
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1848
+ this.fallbackInlineDeletedZoneIds = nextZones.map((zone) => accessor.addZone(zone));
1849
+ });
1850
+ this.fallbackInlineDeletedZoneSignature = nextSignature || null;
1851
+ } catch {
1852
+ this.fallbackInlineDeletedZoneIds = [];
1853
+ this.fallbackInlineDeletedZoneSignature = null;
1854
+ }
1855
+ try {
1856
+ var _modifiedEditor$layou, _render;
1857
+ (_modifiedEditor$layou = modifiedEditor.layout) === null || _modifiedEditor$layou === void 0 || _modifiedEditor$layou.call(modifiedEditor);
1858
+ (_render = modifiedEditor.render) === null || _render === void 0 || _render.call(modifiedEditor, true);
1859
+ } catch {}
990
1860
  }
991
1861
  toWholeLineDecoration(side, startLineNumber, endLineNumber) {
992
1862
  if (endLineNumber < startLineNumber || startLineNumber < 1) return null;
@@ -1004,26 +1874,45 @@ var DiffEditorManager = class DiffEditorManager {
1004
1874
  };
1005
1875
  }
1006
1876
  syncDiffPresentationDecorations() {
1007
- var _this$diffEditorView$3, _this$lastContainer$q, _this$lastContainer;
1877
+ var _this$diffEditorView$, _this$lastContainer$q, _this$lastContainer5;
1008
1878
  if (!this.diffEditorView || !this.lastContainer) return;
1009
1879
  const nativeFresh = this.hasFreshNativeDiffResult();
1010
- const keepNativeDecorationsWhileStale = !nativeFresh && this.preserveNativeDiffDecorationsOnStaleAppend && ((((_this$diffEditorView$3 = this.diffEditorView.getLineChanges()) === null || _this$diffEditorView$3 === void 0 ? void 0 : _this$diffEditorView$3.length) ?? 0) > 0 || !!((_this$lastContainer$q = (_this$lastContainer = this.lastContainer).querySelector) === null || _this$lastContainer$q === void 0 ? void 0 : _this$lastContainer$q.call(_this$lastContainer, ".line-insert, .line-delete, .gutter-insert, .gutter-delete")));
1880
+ const useInlineMode = this.isDiffInlineMode();
1881
+ const lineChanges = this.getEffectiveLineChanges();
1882
+ const nativeInlineDeleteZoneCount = useInlineMode ? this.countNativeInlineDeleteZoneNodes() : 0;
1883
+ const hasNativeInlineDeleteZoneNodes = nativeInlineDeleteZoneCount > 0;
1884
+ const hasNativeInlineDeleteNodes = useInlineMode && this.hasVisibleNativeInlineDeleteNodes();
1885
+ const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1886
+ const useInlineStaleFallback = shouldKeepInlineFallback;
1887
+ this.lastContainer.classList.toggle("stream-monaco-diff-inline-native-ready", useInlineMode && !shouldKeepInlineFallback && (nativeFresh || hasNativeInlineDeleteNodes || hasNativeInlineDeleteZoneNodes));
1888
+ const keepNativeDecorationsWhileStale = !useInlineStaleFallback && !nativeFresh && this.preserveNativeDiffDecorationsOnStaleAppend && ((((_this$diffEditorView$ = this.diffEditorView.getLineChanges()) === null || _this$diffEditorView$ === void 0 ? void 0 : _this$diffEditorView$.length) ?? 0) > 0 || !!((_this$lastContainer$q = (_this$lastContainer5 = this.lastContainer).querySelector) === null || _this$lastContainer$q === void 0 ? void 0 : _this$lastContainer$q.call(_this$lastContainer5, ".line-insert, .line-delete, .gutter-insert, .gutter-delete")));
1011
1889
  this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh && !keepNativeDecorationsWhileStale);
1012
- if (nativeFresh) {
1890
+ if (nativeFresh && !shouldKeepInlineFallback) {
1013
1891
  this.clearFallbackDiffDecorations();
1014
1892
  return;
1015
1893
  }
1016
1894
  const originalEditor = this.diffEditorView.getOriginalEditor();
1017
1895
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
1018
- const lineChanges = this.getEffectiveLineChanges();
1019
1896
  const originalDecorations = lineChanges.map((change) => this.toWholeLineDecoration("original", change.originalStartLineNumber, change.originalEndLineNumber)).filter(Boolean);
1020
1897
  const modifiedDecorations = lineChanges.map((change) => this.toWholeLineDecoration("modified", change.modifiedStartLineNumber, change.modifiedEndLineNumber)).filter(Boolean);
1021
1898
  this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, originalDecorations);
1022
1899
  this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, modifiedDecorations);
1900
+ if (useInlineStaleFallback) this.syncFallbackInlineDeletedZones(lineChanges);
1901
+ else this.clearFallbackInlineDeletedZones();
1023
1902
  }
1024
1903
  disposeDiffPresentationTracking() {
1025
1904
  this.clearFallbackDiffDecorations();
1026
- if (this.lastContainer) this.lastContainer.classList.remove("stream-monaco-diff-native-stale");
1905
+ if (this.diffPresentationObserver) {
1906
+ this.diffPresentationObserver.disconnect();
1907
+ this.diffPresentationObserver = null;
1908
+ }
1909
+ this.clearInlineDiffStreamingPresentationIdleTimer();
1910
+ this.inlineDiffStreamingPresentationActive = false;
1911
+ this.resetInlineDiffStreamingHeightFloor();
1912
+ if (this.lastContainer) {
1913
+ this.lastContainer.classList.remove("stream-monaco-diff-native-stale");
1914
+ this.lastContainer.classList.remove("stream-monaco-diff-inline-native-ready");
1915
+ }
1027
1916
  this.diffComputedVersions = null;
1028
1917
  this.diffPresentationDisposables.forEach((disposable) => disposable.dispose());
1029
1918
  this.diffPresentationDisposables = [];
@@ -1374,6 +2263,31 @@ var DiffEditorManager = class DiffEditorManager {
1374
2263
  border: 0 !important;
1375
2264
  box-shadow: var(--stream-monaco-removed-line-shadow);
1376
2265
  }
2266
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-zone {
2267
+ box-sizing: border-box;
2268
+ width: 100%;
2269
+ pointer-events: none;
2270
+ }
2271
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-line {
2272
+ box-sizing: border-box;
2273
+ width: 100%;
2274
+ overflow: hidden;
2275
+ white-space: pre;
2276
+ color: inherit;
2277
+ background: var(--stream-monaco-removed-line-fill);
2278
+ box-shadow: var(--stream-monaco-removed-line-shadow);
2279
+ }
2280
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-margin {
2281
+ box-sizing: border-box;
2282
+ width: 100%;
2283
+ background: var(--stream-monaco-removed-gutter);
2284
+ pointer-events: none;
2285
+ }
2286
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-zone,
2287
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-line,
2288
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-margin {
2289
+ display: none !important;
2290
+ }
1377
2291
  .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-gutter-insert,
1378
2292
  .stream-monaco-diff-root .monaco-diff-editor .stream-monaco-fallback-gutter-insert {
1379
2293
  background: var(--stream-monaco-added-gutter) !important;
@@ -1503,6 +2417,9 @@ var DiffEditorManager = class DiffEditorManager {
1503
2417
  }
1504
2418
  .stream-monaco-diff-root .monaco-diff-editor .editor.original .current-line {
1505
2419
  width: var(--stream-monaco-original-margin-width, auto) !important;
2420
+ display: none !important;
2421
+ opacity: 0 !important;
2422
+ pointer-events: none !important;
1506
2423
  }
1507
2424
  .stream-monaco-diff-root .monaco-diff-editor .editor.original .monaco-scrollable-element.editor-scrollable {
1508
2425
  left: var(--stream-monaco-original-scrollable-left, auto) !important;
@@ -1515,6 +2432,9 @@ var DiffEditorManager = class DiffEditorManager {
1515
2432
  }
1516
2433
  .stream-monaco-diff-root .monaco-diff-editor .editor.modified .current-line {
1517
2434
  width: var(--stream-monaco-modified-margin-width) !important;
2435
+ display: none !important;
2436
+ opacity: 0 !important;
2437
+ pointer-events: none !important;
1518
2438
  }
1519
2439
  .stream-monaco-diff-root .monaco-diff-editor .editor.modified .monaco-scrollable-element.editor-scrollable {
1520
2440
  left: var(--stream-monaco-modified-scrollable-left, var(--stream-monaco-modified-margin-width)) !important;
@@ -1545,15 +2465,39 @@ var DiffEditorManager = class DiffEditorManager {
1545
2465
  border: 0 !important;
1546
2466
  overflow: hidden !important;
1547
2467
  }
2468
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-editor,
2469
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-editor-background,
2470
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .lines-content {
2471
+ width: 0 !important;
2472
+ min-width: 0 !important;
2473
+ background: transparent !important;
2474
+ opacity: 0 !important;
2475
+ pointer-events: none !important;
2476
+ }
1548
2477
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-scrollable-element.editor-scrollable {
1549
2478
  left: 0 !important;
1550
2479
  width: 0 !important;
1551
2480
  }
2481
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin,
2482
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin-view-overlays,
2483
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin-view-zones,
2484
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .overflow-guard {
2485
+ display: none !important;
2486
+ width: 0 !important;
2487
+ min-width: 0 !important;
2488
+ }
1552
2489
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.modified {
1553
2490
  left: 0 !important;
1554
2491
  width: 100% !important;
1555
2492
  border-left: 0 !important;
1556
2493
  }
2494
+ .stream-monaco-diff-root.stream-monaco-diff-inline.stream-monaco-diff-native-stale .monaco-diff-editor .editor.modified .view-lines.line-delete,
2495
+ .stream-monaco-diff-root.stream-monaco-diff-inline.stream-monaco-diff-native-stale .monaco-diff-editor .editor.modified .inline-deleted-margin-view-zone {
2496
+ display: none !important;
2497
+ height: 0 !important;
2498
+ min-height: 0 !important;
2499
+ overflow: hidden !important;
2500
+ }
1557
2501
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .gutter-delete,
1558
2502
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .gutter-insert,
1559
2503
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .line-delete,
@@ -2143,6 +3087,9 @@ var DiffEditorManager = class DiffEditorManager {
2143
3087
  opacity: 0.92 !important;
2144
3088
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.14s ease, opacity 0.14s ease, box-shadow 0.14s ease;
2145
3089
  }
3090
+ .stream-monaco-diff-root .monaco-editor .fold-unchanged.stream-monaco-fold-unchanged-hidden {
3091
+ display: none !important;
3092
+ }
2146
3093
  .stream-monaco-diff-root .monaco-editor .fold-unchanged:hover,
2147
3094
  .stream-monaco-diff-root .monaco-editor .fold-unchanged.stream-monaco-focus-visible {
2148
3095
  opacity: 1 !important;
@@ -2213,33 +3160,14 @@ var DiffEditorManager = class DiffEditorManager {
2213
3160
  el.addEventListener(eventName, listener);
2214
3161
  bucket.push({ dispose: () => el.removeEventListener(eventName, listener) });
2215
3162
  }
2216
- createDiffHunkActionNode(side) {
2217
- const node = document.createElement("div");
2218
- node.className = "stream-monaco-diff-hunk-actions";
2219
- node.dataset.side = side;
2220
- const createButton = (action, label) => {
2221
- const button = document.createElement("button");
2222
- button.type = "button";
2223
- button.textContent = label;
2224
- button.dataset.action = action;
2225
- button.addEventListener("click", (event) => {
2226
- event.preventDefault();
2227
- event.stopPropagation();
2228
- this.applyDiffHunkAction(side, action);
2229
- });
2230
- return button;
2231
- };
2232
- node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
2233
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
2234
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseleave", () => this.scheduleHideDiffHunkActions());
2235
- return node;
2236
- }
2237
3163
  cloneSerializableValue(value) {
2238
3164
  if (typeof structuredClone === "function") return structuredClone(value);
2239
3165
  return JSON.parse(JSON.stringify(value));
2240
3166
  }
2241
3167
  capturePersistedDiffUnchangedState() {
2242
3168
  if (!this.diffEditorView) return;
3169
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved ?? this.resolveDiffHideUnchangedRegionsOption();
3170
+ if (!(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) || this.diffHideUnchangedRegionsDeferred) return;
2243
3171
  const state = this.diffEditorView.saveViewState();
2244
3172
  if (!(state === null || state === void 0 ? void 0 : state.modelState)) {
2245
3173
  this.diffPersistedUnchangedModelState = null;
@@ -2247,6 +3175,14 @@ var DiffEditorManager = class DiffEditorManager {
2247
3175
  }
2248
3176
  this.diffPersistedUnchangedModelState = this.cloneSerializableValue(state.modelState);
2249
3177
  }
3178
+ capturePreviousDiffUnchangedState() {
3179
+ if (!this.diffEditorView) return;
3180
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved ?? this.resolveDiffHideUnchangedRegionsOption();
3181
+ if (!(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) || this.diffHideUnchangedRegionsDeferred) return;
3182
+ const state = this.diffEditorView.saveViewState();
3183
+ if (!(state === null || state === void 0 ? void 0 : state.modelState)) return;
3184
+ this.diffPreviousUnchangedModelState = this.cloneSerializableValue(state.modelState);
3185
+ }
2250
3186
  scheduleCapturePersistedDiffUnchangedState(frames = 1) {
2251
3187
  this.rafScheduler.schedule("capture-diff-unchanged-state", () => {
2252
3188
  let remaining = Math.max(0, frames);
@@ -2272,6 +3208,20 @@ var DiffEditorManager = class DiffEditorManager {
2272
3208
  });
2273
3209
  this.applyPendingDiffScrollRestore();
2274
3210
  }
3211
+ restorePreviousDiffUnchangedState() {
3212
+ if (!this.diffEditorView || !this.diffPreviousUnchangedModelState) return false;
3213
+ const current = this.diffEditorView.saveViewState();
3214
+ if (!current) return false;
3215
+ const previous = this.cloneSerializableValue(this.diffPreviousUnchangedModelState);
3216
+ this.diffEditorView.restoreViewState({
3217
+ original: current.original,
3218
+ modified: current.modified,
3219
+ modelState: previous
3220
+ });
3221
+ this.diffPersistedUnchangedModelState = this.cloneSerializableValue(previous);
3222
+ this.applyPendingDiffScrollRestore();
3223
+ return true;
3224
+ }
2275
3225
  scheduleRestorePersistedDiffUnchangedState() {
2276
3226
  if (this.diffHideUnchangedRegionsDeferred) return;
2277
3227
  if (!this.diffPersistedUnchangedModelState) return;
@@ -2435,7 +3385,7 @@ var DiffEditorManager = class DiffEditorManager {
2435
3385
  readOnly: this.options.readOnly ?? true,
2436
3386
  lineDecorationsWidth: this.options.lineDecorationsWidth,
2437
3387
  lineNumbersMinChars: this.options.lineNumbersMinChars,
2438
- glyphMargin: this.options.glyphMargin,
3388
+ glyphMargin: this.resolveDiffGlyphMarginOption(hideUnchangedRegions),
2439
3389
  fontFamily: this.options.fontFamily,
2440
3390
  fontSize: this.options.fontSize,
2441
3391
  lineHeight: this.options.lineHeight,
@@ -2455,9 +3405,10 @@ var DiffEditorManager = class DiffEditorManager {
2455
3405
  };
2456
3406
  }
2457
3407
  refreshDiffPresentation() {
2458
- var _this$diffHeightManag;
3408
+ var _this$diffHideUnchang, _this$diffHeightManag;
2459
3409
  if (!this.diffEditorView) return;
2460
3410
  const hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption();
3411
+ const shouldRecomputeDiffViewModelForUnchangedRegions = !this.diffHideUnchangedRegionsDeferred && (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) === true && ((_this$diffHideUnchang = this.diffHideUnchangedRegionsResolved) === null || _this$diffHideUnchang === void 0 ? void 0 : _this$diffHideUnchang.enabled) === false && !!this.originalModel && !!this.modifiedModel;
2461
3412
  const presentationOptions = this.resolveDiffPresentationEditorOptions(hideUnchangedRegions);
2462
3413
  this.diffHideUnchangedRegionsResolved = hideUnchangedRegions;
2463
3414
  this.diffUpdateThrottleMs = this.resolveDiffStreamingThrottleMs();
@@ -2467,13 +3418,20 @@ var DiffEditorManager = class DiffEditorManager {
2467
3418
  this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
2468
3419
  }
2469
3420
  this.withLockedDiffScrollPosition(() => {
2470
- var _this$diffEditorView13;
2471
- (_this$diffEditorView13 = this.diffEditorView) === null || _this$diffEditorView13 === void 0 || _this$diffEditorView13.updateOptions(presentationOptions);
3421
+ var _this$diffEditorView4;
3422
+ (_this$diffEditorView4 = this.diffEditorView) === null || _this$diffEditorView4 === void 0 || _this$diffEditorView4.updateOptions(presentationOptions);
2472
3423
  });
2473
3424
  (_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 || _this$diffHeightManag.update();
2474
3425
  this.applyDiffRootAppearanceClass();
2475
3426
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2476
3427
  this.repositionDiffHunkNodes();
3428
+ if (shouldRecomputeDiffViewModelForUnchangedRegions) this.setDiffModels({
3429
+ original: this.originalModel,
3430
+ modified: this.modifiedModel
3431
+ }, {
3432
+ preserveViewState: true,
3433
+ preserveModelState: false
3434
+ });
2477
3435
  }
2478
3436
  restoreDeferredDiffUnchangedRegions() {
2479
3437
  this.clearDeferredDiffUnchangedRegionsIdleTimer();
@@ -2483,8 +3441,8 @@ var DiffEditorManager = class DiffEditorManager {
2483
3441
  if (!this.diffHideUnchangedRegionsDeferred) return;
2484
3442
  this.diffHideUnchangedRegionsDeferred = false;
2485
3443
  this.withLockedDiffScrollPosition(() => {
2486
- var _this$diffEditorView14;
2487
- (_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || _this$diffEditorView14.updateOptions({ hideUnchangedRegions });
3444
+ var _this$diffEditorView5;
3445
+ (_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || _this$diffEditorView5.updateOptions({ hideUnchangedRegions });
2488
3446
  });
2489
3447
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2490
3448
  if (this.shouldAutoScrollDiff) {
@@ -2493,6 +3451,22 @@ var DiffEditorManager = class DiffEditorManager {
2493
3451
  }
2494
3452
  }
2495
3453
  markDiffStreamingActivity() {
3454
+ var _this$lastContainer6;
3455
+ (_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || (_this$lastContainer6 = _this$lastContainer6.classList) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.remove("stream-monaco-diff-inline-native-ready");
3456
+ if (this.isDiffInlineMode()) {
3457
+ var _this$diffHeightManag2, _this$lastContainer7, _this$lastContainer7$;
3458
+ this.inlineDiffStreamingPresentationActive = true;
3459
+ this.inlineDiffStreamingHeightFloor = Math.max(this.inlineDiffStreamingHeightFloor, ((_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 ? void 0 : _this$diffHeightManag2.getLastApplied()) ?? 0, ((_this$lastContainer7 = this.lastContainer) === null || _this$lastContainer7 === void 0 || (_this$lastContainer7$ = _this$lastContainer7.getBoundingClientRect) === null || _this$lastContainer7$ === void 0 ? void 0 : _this$lastContainer7$.call(_this$lastContainer7).height) ?? 0);
3460
+ this.clearInlineDiffStreamingPresentationIdleTimer();
3461
+ this.inlineDiffStreamingPresentationIdleTimer = setTimeout(() => {
3462
+ var _this$diffHeightManag3;
3463
+ this.inlineDiffStreamingPresentationIdleTimer = null;
3464
+ this.inlineDiffStreamingPresentationActive = false;
3465
+ this.resetInlineDiffStreamingHeightFloor();
3466
+ this.scheduleSyncDiffPresentationDecorations();
3467
+ (_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 || _this$diffHeightManag3.update();
3468
+ }, 3e3);
3469
+ }
2496
3470
  const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved;
2497
3471
  if (!this.diffEditorView || !(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled)) return;
2498
3472
  this.clearDeferredDiffUnchangedRegionsIdleTimer();
@@ -2504,8 +3478,8 @@ var DiffEditorManager = class DiffEditorManager {
2504
3478
  this.diffHideUnchangedRegionsDeferred = true;
2505
3479
  this.hideAllDiffUnchangedBridgeEntries();
2506
3480
  this.withLockedDiffScrollPosition(() => {
2507
- var _this$diffEditorView15;
2508
- (_this$diffEditorView15 = this.diffEditorView) === null || _this$diffEditorView15 === void 0 || _this$diffEditorView15.updateOptions({ hideUnchangedRegions: {
3481
+ var _this$diffEditorView6;
3482
+ (_this$diffEditorView6 = this.diffEditorView) === null || _this$diffEditorView6 === void 0 || _this$diffEditorView6.updateOptions({ hideUnchangedRegions: {
2509
3483
  ...hideUnchangedRegions,
2510
3484
  enabled: false
2511
3485
  } });
@@ -2579,7 +3553,7 @@ var DiffEditorManager = class DiffEditorManager {
2579
3553
  var _this$diffUnchangedBr;
2580
3554
  this.clearDiffUnchangedBridgeSources();
2581
3555
  if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.replaceChildren();
2582
- if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.style.transform = "translate3d(0px, 0px, 0px)";
3556
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2583
3557
  this.diffUnchangedBridgeEntries.clear();
2584
3558
  this.diffUnchangedBridgePool.length = 0;
2585
3559
  this.diffUnchangedOverlayScrollTop = 0;
@@ -2589,30 +3563,27 @@ var DiffEditorManager = class DiffEditorManager {
2589
3563
  }
2590
3564
  clearDiffUnchangedBridgeSources() {
2591
3565
  if (!this.lastContainer) return;
2592
- const bridgedCenters = this.lastContainer.querySelectorAll(".stream-monaco-unchanged-bridge-source");
2593
- bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
3566
+ clearDiffUnchangedBridgeSourceClasses(this.lastContainer);
2594
3567
  }
2595
3568
  ensureDiffUnchangedBridgeOverlay() {
2596
3569
  if (!this.lastContainer) return null;
2597
3570
  if (!this.diffUnchangedBridgeOverlay) {
2598
- const overlay = document.createElement("div");
2599
- overlay.className = "stream-monaco-diff-unchanged-overlay";
3571
+ const overlay = createDiffUnchangedBridgeOverlay();
2600
3572
  this.lastContainer.append(overlay);
2601
3573
  this.diffUnchangedBridgeOverlay = overlay;
2602
3574
  }
2603
3575
  return this.diffUnchangedBridgeOverlay;
2604
3576
  }
2605
3577
  readDiffUnchangedOverlayScrollState() {
2606
- var _this$diffEditorView16, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
2607
- const modifiedEditor = (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 ? void 0 : _this$diffEditorView16.getModifiedEditor();
3578
+ var _this$diffEditorView7, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
3579
+ const modifiedEditor = (_this$diffEditorView7 = this.diffEditorView) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.getModifiedEditor();
2608
3580
  return {
2609
3581
  top: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc6 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc6 === void 0 ? void 0 : _modifiedEditor$getSc6.call(modifiedEditor)) ?? 0,
2610
3582
  left: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc7 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc7 === void 0 ? void 0 : _modifiedEditor$getSc7.call(modifiedEditor)) ?? 0
2611
3583
  };
2612
3584
  }
2613
3585
  syncDiffUnchangedOverlayScrollBaseline() {
2614
- const overlay = this.diffUnchangedBridgeOverlay;
2615
- if (overlay) overlay.style.transform = "translate3d(0px, 0px, 0px)";
3586
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2616
3587
  const { top, left } = this.readDiffUnchangedOverlayScrollState();
2617
3588
  this.diffUnchangedOverlayScrollTop = top;
2618
3589
  this.diffUnchangedOverlayScrollLeft = left;
@@ -2626,28 +3597,10 @@ var DiffEditorManager = class DiffEditorManager {
2626
3597
  if (Math.abs(deltaY) < .5 && Math.abs(deltaX) < .5) return;
2627
3598
  overlay.style.transform = `translate3d(${deltaX}px, ${deltaY}px, 0px)`;
2628
3599
  }
2629
- resolveDiffUnchangedViewZoneHeight() {
2630
- switch (this.resolveDiffUnchangedRegionStyleOption()) {
2631
- case "line-info":
2632
- case "line-info-basic":
2633
- case "metadata": return 32;
2634
- case "simple": return 28;
2635
- default: return 32;
2636
- }
2637
- }
2638
- collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
2639
- const widgetTopValues = Array.from(editorRoot.querySelectorAll(".diff-hidden-lines-widget")).map((node) => Number.parseFloat(node.style.top || "NaN")).filter((value) => Number.isFinite(value) && value > -1e5);
2640
- if (widgetTopValues.length === 0) return [];
2641
- return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
2642
- const zoneTop = Number.parseFloat(node.style.top || "NaN");
2643
- const currentHeight = Number.parseFloat(node.style.height || "0");
2644
- return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
2645
- }).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
2646
- }
2647
3600
  syncDiffUnchangedViewZoneHeightsForEditor(editor, editorRoot, targetHeight) {
2648
3601
  var _editor$getScrollTop, _editorInternal$_mode;
2649
3602
  if (!editor || !(editorRoot instanceof HTMLElement)) return false;
2650
- const zoneIds = this.collectDiffUnchangedViewZoneIds(editorRoot, ((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
3603
+ const zoneIds = collectDiffUnchangedViewZoneIds(editorRoot, ((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
2651
3604
  if (zoneIds.length === 0) return false;
2652
3605
  const editorInternal = editor;
2653
3606
  const zones = (_editorInternal$_mode = editorInternal._modelData) === null || _editorInternal$_mode === void 0 || (_editorInternal$_mode = _editorInternal$_mode.view) === null || _editorInternal$_mode === void 0 || (_editorInternal$_mode = _editorInternal$_mode._viewZones) === null || _editorInternal$_mode === void 0 ? void 0 : _editorInternal$_mode._zones;
@@ -2672,7 +3625,7 @@ var DiffEditorManager = class DiffEditorManager {
2672
3625
  syncDiffUnchangedViewZoneHeights() {
2673
3626
  var _originalEditor$getCo, _modifiedEditor$getCo3;
2674
3627
  if (!this.diffEditorView) return false;
2675
- const targetHeight = this.resolveDiffUnchangedViewZoneHeight();
3628
+ const targetHeight = resolveDiffUnchangedViewZoneHeight(this.resolveDiffUnchangedRegionStyleOption());
2676
3629
  const originalEditor = this.diffEditorView.getOriginalEditor();
2677
3630
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
2678
3631
  const originalChanged = this.syncDiffUnchangedViewZoneHeightsForEditor(originalEditor, (_originalEditor$getCo = originalEditor.getContainerDomNode) === null || _originalEditor$getCo === void 0 ? void 0 : _originalEditor$getCo.call(originalEditor), targetHeight);
@@ -2690,19 +3643,7 @@ var DiffEditorManager = class DiffEditorManager {
2690
3643
  return `${this.getDiffUnchangedNodeId(secondaryNode)}:${this.getDiffUnchangedNodeId(primaryNode)}`;
2691
3644
  }
2692
3645
  createDiffUnchangedBridgeEntry(key) {
2693
- const bridge = document.createElement("div");
2694
- bridge.className = "stream-monaco-diff-unchanged-bridge";
2695
- bridge.setAttribute("role", "group");
2696
- bridge.hidden = true;
2697
- const summary = document.createElement("button");
2698
- summary.type = "button";
2699
- summary.className = "stream-monaco-unchanged-summary";
2700
- const visualMeta = document.createElement("div");
2701
- visualMeta.className = "stream-monaco-unchanged-meta";
2702
- summary.append(visualMeta);
2703
- const divider = document.createElement("span");
2704
- divider.className = "stream-monaco-unchanged-pane-divider";
2705
- divider.setAttribute("aria-hidden", "true");
3646
+ const { bridge, summary, visualMeta, divider } = createDiffUnchangedBridgeScaffold();
2706
3647
  const entry = {
2707
3648
  key,
2708
3649
  bridge,
@@ -2721,16 +3662,15 @@ var DiffEditorManager = class DiffEditorManager {
2721
3662
  const onWheel = (event) => {
2722
3663
  var _modifiedEditor$getSc8, _modifiedEditor$getSc9, _originalEditor$setSc6, _modifiedEditor$setSc6;
2723
3664
  if (!this.diffEditorView) return;
2724
- if (Math.abs(event.deltaY) < .5 && Math.abs(event.deltaX) < .5) return;
3665
+ if (!shouldHandleDiffUnchangedWheel(event)) return;
2725
3666
  event.preventDefault();
2726
3667
  event.stopPropagation();
2727
3668
  const originalEditor = this.diffEditorView.getOriginalEditor();
2728
3669
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
2729
- const targetScrollTop = (((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0) + event.deltaY;
2730
- const targetScrollLeft = (((_modifiedEditor$getSc9 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc9 === void 0 ? void 0 : _modifiedEditor$getSc9.call(modifiedEditor)) ?? 0) + event.deltaX;
3670
+ const { syncHorizontal, targetScrollLeft, targetScrollTop } = resolveDiffUnchangedWheelScrollTarget(((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0, ((_modifiedEditor$getSc9 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc9 === void 0 ? void 0 : _modifiedEditor$getSc9.call(modifiedEditor)) ?? 0, event);
2731
3671
  (_originalEditor$setSc6 = originalEditor.setScrollTop) === null || _originalEditor$setSc6 === void 0 || _originalEditor$setSc6.call(originalEditor, targetScrollTop);
2732
3672
  (_modifiedEditor$setSc6 = modifiedEditor.setScrollTop) === null || _modifiedEditor$setSc6 === void 0 || _modifiedEditor$setSc6.call(modifiedEditor, targetScrollTop);
2733
- if (Math.abs(event.deltaX) >= .5) {
3673
+ if (syncHorizontal) {
2734
3674
  var _originalEditor$setSc7, _modifiedEditor$setSc7;
2735
3675
  (_originalEditor$setSc7 = originalEditor.setScrollLeft) === null || _originalEditor$setSc7 === void 0 || _originalEditor$setSc7.call(originalEditor, targetScrollLeft);
2736
3676
  (_modifiedEditor$setSc7 = modifiedEditor.setScrollLeft) === null || _modifiedEditor$setSc7 === void 0 || _modifiedEditor$setSc7.call(modifiedEditor, targetScrollLeft);
@@ -2739,7 +3679,6 @@ var DiffEditorManager = class DiffEditorManager {
2739
3679
  };
2740
3680
  bridge.addEventListener("wheel", onWheel, { passive: false });
2741
3681
  this.diffUnchangedRegionDisposables.push({ dispose: () => bridge.removeEventListener("wheel", onWheel) });
2742
- bridge.append(summary, divider);
2743
3682
  return entry;
2744
3683
  }
2745
3684
  acquireDiffUnchangedBridgeEntry(key) {
@@ -2747,16 +3686,14 @@ var DiffEditorManager = class DiffEditorManager {
2747
3686
  if (existing) return existing;
2748
3687
  const entry = this.diffUnchangedBridgePool.pop() ?? this.createDiffUnchangedBridgeEntry(key);
2749
3688
  entry.key = key;
2750
- entry.bridge.hidden = false;
2751
- entry.bridge.removeAttribute("aria-hidden");
3689
+ syncDiffUnchangedBridgeVisibility(entry.bridge, true);
2752
3690
  this.diffUnchangedBridgeEntries.set(key, entry);
2753
3691
  return entry;
2754
3692
  }
2755
3693
  releaseDiffUnchangedBridgeEntry(entry) {
2756
3694
  if (entry.key) this.diffUnchangedBridgeEntries.delete(entry.key);
2757
3695
  entry.key = null;
2758
- entry.bridge.hidden = true;
2759
- entry.bridge.setAttribute("aria-hidden", "true");
3696
+ syncDiffUnchangedBridgeVisibility(entry.bridge, false);
2760
3697
  this.diffUnchangedBridgePool.push(entry);
2761
3698
  }
2762
3699
  hideAllDiffUnchangedBridgeEntries() {
@@ -2782,51 +3719,15 @@ var DiffEditorManager = class DiffEditorManager {
2782
3719
  entry.activate();
2783
3720
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
2784
3721
  }
2785
- updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel) {
2786
- this.updateDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
2787
- }
2788
- updateDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
2789
- const lastStyle = metaNode.dataset.style;
2790
- const lastLabel = metaNode.dataset.label;
2791
- if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
2792
- metaNode.dataset.style = unchangedRegionStyle;
2793
- metaNode.dataset.label = summaryLabel;
2794
- metaNode.replaceChildren();
2795
- metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
2796
- if (unchangedRegionStyle === "simple") {
2797
- const simpleBar = document.createElement("span");
2798
- simpleBar.className = "stream-monaco-unchanged-simple-bar";
2799
- simpleBar.setAttribute("aria-hidden", "true");
2800
- metaNode.append(simpleBar);
2801
- return;
2802
- }
2803
- const label = document.createElement("span");
2804
- if (unchangedRegionStyle === "metadata") label.className = "stream-monaco-unchanged-metadata-label";
2805
- else label.className = "stream-monaco-unchanged-count";
2806
- label.textContent = summaryLabel;
2807
- metaNode.append(label);
2808
- }
2809
3722
  syncDiffUnchangedRevealButton(entry, slot, handle, direction, label) {
2810
3723
  const existingButton = entry[slot];
2811
- const button = existingButton ?? document.createElement("button");
2812
- if (!existingButton) {
2813
- button.type = "button";
2814
- button.className = "stream-monaco-unchanged-reveal";
2815
- button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
2816
- }
2817
- button.dataset.direction = direction;
2818
- button.hidden = !handle;
2819
- button.disabled = !handle;
2820
- button.toggleAttribute("aria-hidden", !handle);
2821
- button.title = handle ? label : "";
2822
- button.setAttribute("aria-label", handle ? label : "");
2823
- button.onclick = handle ? (event) => {
2824
- event.preventDefault();
2825
- event.stopPropagation();
3724
+ const button = existingButton ?? createDiffUnchangedRevealButton(direction);
3725
+ syncDiffUnchangedRevealButtonNode(button, handle, label);
3726
+ bindDiffUnchangedRevealButtonAction(button, handle, (nextHandle) => {
2826
3727
  this.hideAllDiffUnchangedBridgeEntries();
2827
- this.activateDiffUnchangedHandle(handle);
3728
+ this.activateDiffUnchangedHandle(nextHandle);
2828
3729
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
2829
- } : null;
3730
+ });
2830
3731
  entry[slot] = button;
2831
3732
  }
2832
3733
  syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle, showBottomHandle, bottomHandle) {
@@ -2834,14 +3735,9 @@ var DiffEditorManager = class DiffEditorManager {
2834
3735
  entry.rail = document.createElement("div");
2835
3736
  entry.rail.className = "stream-monaco-unchanged-rail";
2836
3737
  }
2837
- const shouldRenderRail = showTopHandle || showBottomHandle;
2838
3738
  this.syncDiffUnchangedRevealButton(entry, "topButton", showTopHandle ? topHandle : null, "down", "Reveal more unmodified lines below");
2839
3739
  this.syncDiffUnchangedRevealButton(entry, "bottomButton", showBottomHandle ? bottomHandle : null, "up", "Reveal more unmodified lines above");
2840
- entry.rail.hidden = !shouldRenderRail;
2841
- entry.rail.toggleAttribute("aria-hidden", !shouldRenderRail);
2842
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
2843
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
2844
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
3740
+ syncDiffUnchangedRailNode(entry.rail, showTopHandle, showBottomHandle);
2845
3741
  if (entry.topButton && entry.topButton.parentElement !== entry.rail) entry.rail.append(entry.topButton);
2846
3742
  if (entry.bottomButton && entry.bottomButton.parentElement !== entry.rail) entry.rail.append(entry.bottomButton);
2847
3743
  }
@@ -2851,203 +3747,53 @@ var DiffEditorManager = class DiffEditorManager {
2851
3747
  this.releaseDiffUnchangedBridgeEntry(entry);
2852
3748
  }
2853
3749
  }
2854
- dispatchSyntheticMouseDown(node) {
2855
- const view = node.ownerDocument.defaultView;
2856
- if (!view) return;
2857
- const rect = node.getBoundingClientRect();
2858
- node.dispatchEvent(new view.MouseEvent("mousedown", {
2859
- bubbles: true,
2860
- cancelable: true,
2861
- button: 0,
2862
- clientX: rect.left + rect.width / 2,
2863
- clientY: rect.top + rect.height / 2
2864
- }));
2865
- }
2866
- dispatchSyntheticMouseTap(node) {
2867
- const view = node.ownerDocument.defaultView;
2868
- if (!view) return;
2869
- const rect = node.getBoundingClientRect();
2870
- const clientX = rect.left + rect.width / 2;
2871
- const clientY = rect.top + rect.height / 2;
2872
- node.dispatchEvent(new view.MouseEvent("mousedown", {
2873
- bubbles: true,
2874
- cancelable: true,
2875
- button: 0,
2876
- clientX,
2877
- clientY
2878
- }));
2879
- node.dispatchEvent(new view.MouseEvent("mouseup", {
2880
- bubbles: true,
2881
- cancelable: true,
2882
- button: 0,
2883
- clientX,
2884
- clientY
2885
- }));
2886
- }
2887
- formatDiffUnchangedCountLabel(text) {
2888
- const match = text.match(/\d+/);
2889
- const count = match ? Number.parseInt(match[0], 10) : NaN;
2890
- if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
2891
- return text.replace(/hidden/gi, "unmodified");
2892
- }
2893
- countDiffLines(startLineNumber, endLineNumber) {
2894
- return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
2895
- }
2896
- measureDiffUnchangedSurroundingLines(primaryNode) {
2897
- const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
2898
- if (!editorRoot) return {
2899
- previousVisibleLine: null,
2900
- nextVisibleLine: null
2901
- };
2902
- const widgetRect = primaryNode.getBoundingClientRect();
2903
- let previousVisibleLine = null;
2904
- let nextVisibleLine = null;
2905
- const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
2906
- lineNumberNodes.forEach((node) => {
2907
- var _node$textContent3;
2908
- const lineNumber = Number.parseInt(((_node$textContent3 = node.textContent) === null || _node$textContent3 === void 0 ? void 0 : _node$textContent3.trim()) || "", 10);
2909
- if (!Number.isFinite(lineNumber)) return;
2910
- const top = node.getBoundingClientRect().top;
2911
- if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
2912
- else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
2913
- });
2914
- return {
2915
- previousVisibleLine,
2916
- nextVisibleLine
2917
- };
2918
- }
2919
- formatDiffMetadataRange(startLineNumber, lineCount) {
2920
- return `${startLineNumber},${Math.max(0, lineCount)}`;
2921
- }
2922
- buildDiffHunkMetadataLabel(change) {
2923
- var _this$originalModel, _this$modifiedModel2;
2924
- const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
2925
- const originalTotalLines = ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0;
2926
- const modifiedTotalLines = ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0;
2927
- const originalChangedCount = this.countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
2928
- const modifiedChangedCount = this.countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
2929
- const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
2930
- const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
2931
- const originalStart = Math.max(1, originalAnchor - contextLineCount);
2932
- const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
2933
- const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
2934
- const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
2935
- const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
2936
- const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
2937
- return {
2938
- modifiedStart,
2939
- originalStart,
2940
- label: `@@ -${this.formatDiffMetadataRange(originalStart, originalDisplayCount)} +${this.formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
2941
- };
2942
- }
2943
- resolveDiffMetadataLabel(primaryNode, pairIndex) {
2944
- var _metadataEntries$Math;
2945
- const lineChanges = this.getEffectiveLineChanges();
2946
- if (lineChanges.length === 0) return null;
2947
- const metadataEntries = lineChanges.map((change) => this.buildDiffHunkMetadataLabel(change));
2948
- const { nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
2949
- if (nextVisibleLine != null) {
2950
- const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
2951
- for (const candidateStart of candidateStarts) {
2952
- const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
2953
- if (matching) return matching.label;
2954
- }
2955
- }
2956
- return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
2957
- }
2958
3750
  activateDiffUnchangedHandle(node) {
2959
3751
  if (!(node instanceof HTMLElement)) return;
2960
- this.dispatchSyntheticMouseTap(node);
3752
+ dispatchSyntheticPrimaryMouseTap(node);
2961
3753
  this.scheduleCapturePersistedDiffUnchangedState(1);
2962
3754
  }
2963
- resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount) {
2964
- var _this$diffEditorView17, _this$diffEditorView18;
2965
- let showTopHandle = pairCount === 1 || pairIndex > 0;
2966
- let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
2967
- const countMatch = countText.match(/\d+/);
2968
- const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
2969
- if (!Number.isFinite(hiddenCount)) return {
2970
- showTopHandle,
2971
- showBottomHandle
2972
- };
2973
- const { previousVisibleLine, nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
2974
- if (previousVisibleLine == null && nextVisibleLine != null) {
2975
- showTopHandle = false;
2976
- showBottomHandle = true;
2977
- return {
2978
- showTopHandle,
2979
- showBottomHandle
2980
- };
2981
- }
2982
- if (nextVisibleLine == null && previousVisibleLine != null) {
2983
- showTopHandle = true;
2984
- showBottomHandle = false;
2985
- return {
2986
- showTopHandle,
2987
- showBottomHandle
2988
- };
2989
- }
2990
- if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
2991
- showTopHandle = false;
2992
- showBottomHandle = true;
2993
- }
2994
- const modelLineCount = ((_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView17 = _this$diffEditorView17.getModifiedEditor().getModel()) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView18 = _this$diffEditorView17.getLineCount) === null || _this$diffEditorView18 === void 0 ? void 0 : _this$diffEditorView18.call(_this$diffEditorView17)) ?? null;
2995
- if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
2996
- showTopHandle = true;
2997
- showBottomHandle = false;
2998
- }
2999
- return {
3000
- showTopHandle,
3001
- showBottomHandle
3002
- };
3003
- }
3004
- resolveDiffUnchangedMergeRole(node) {
3005
- var _this$diffEditorView19, _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24;
3006
- const diffRoot = node.closest(".monaco-diff-editor.side-by-side");
3007
- if (!(diffRoot instanceof HTMLElement)) return "none";
3008
- const nodeRect = node.getBoundingClientRect();
3009
- const nodeCenter = nodeRect.left + nodeRect.width / 2;
3010
- const originalHost = (_this$diffEditorView19 = this.diffEditorView) === null || _this$diffEditorView19 === void 0 || (_this$diffEditorView21 = (_this$diffEditorView20 = _this$diffEditorView19.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView21 === void 0 ? void 0 : _this$diffEditorView21.call(_this$diffEditorView20);
3011
- const modifiedHost = (_this$diffEditorView22 = this.diffEditorView) === null || _this$diffEditorView22 === void 0 || (_this$diffEditorView24 = (_this$diffEditorView23 = _this$diffEditorView22.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView24 === void 0 ? void 0 : _this$diffEditorView24.call(_this$diffEditorView23);
3012
- if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
3013
- const originalRect = originalHost.getBoundingClientRect();
3014
- const modifiedRect = modifiedHost.getBoundingClientRect();
3015
- const originalCenter = originalRect.left + originalRect.width / 2;
3016
- const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
3017
- return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
3018
- }
3019
- const diffRect = diffRoot.getBoundingClientRect();
3020
- return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
3021
- }
3022
3755
  patchDiffUnchangedCenter(node, pairIndex = 0) {
3023
- node.classList.add("stream-monaco-clickable");
3024
- node.title = "Click to expand all unmodified lines";
3025
- const mergeRole = this.resolveDiffUnchangedMergeRole(node);
3756
+ var _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10, _this$diffEditorView11, _this$diffEditorView12, _this$diffEditorView13;
3757
+ const mergeRole = resolveDiffUnchangedMergeRole({
3758
+ node,
3759
+ diffRoot: node.closest(".monaco-diff-editor.side-by-side"),
3760
+ originalHost: (_this$diffEditorView8 = this.diffEditorView) === null || _this$diffEditorView8 === void 0 || (_this$diffEditorView10 = (_this$diffEditorView9 = _this$diffEditorView8.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView10 === void 0 ? void 0 : _this$diffEditorView10.call(_this$diffEditorView9),
3761
+ modifiedHost: (_this$diffEditorView11 = this.diffEditorView) === null || _this$diffEditorView11 === void 0 || (_this$diffEditorView13 = (_this$diffEditorView12 = _this$diffEditorView11.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView13 === void 0 ? void 0 : _this$diffEditorView13.call(_this$diffEditorView12)
3762
+ });
3026
3763
  const shouldUseMergedSecondary = mergeRole === "secondary";
3027
3764
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3028
- node.classList.toggle("stream-monaco-unchanged-merged-secondary", shouldUseMergedSecondary);
3029
- node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
3765
+ syncDiffUnchangedCenterNode(node, mergeRole);
3030
3766
  const primary = node.children.item(0);
3031
3767
  const meta = node.children.item(1);
3032
3768
  if (primary instanceof HTMLElement) primary.classList.add("stream-monaco-unchanged-primary");
3033
3769
  if (meta instanceof HTMLElement) {
3034
- var _countSource$textCont;
3770
+ var _countSource$textCont, _this$originalModel, _this$modifiedModel2;
3035
3771
  meta.classList.add("stream-monaco-unchanged-meta");
3036
3772
  const countSource = meta.querySelector(".count") ?? meta.firstElementChild;
3037
- const countText = this.formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont = countSource.textContent) === null || _countSource$textCont === void 0 ? void 0 : _countSource$textCont.trim()) || "Unmodified lines");
3038
- const summaryLabel = unchangedRegionStyle === "metadata" ? this.resolveDiffMetadataLabel(node, pairIndex) ?? countText : countText;
3039
- this.updateDiffUnchangedMetaNode(meta, unchangedRegionStyle, summaryLabel);
3773
+ const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont = countSource.textContent) === null || _countSource$textCont === void 0 ? void 0 : _countSource$textCont.trim()) || "Unmodified lines");
3774
+ const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3775
+ const summaryLabel = resolveDiffUnchangedSummaryLabel({
3776
+ countText,
3777
+ unchangedRegionStyle,
3778
+ lineChanges: this.getEffectiveLineChanges(),
3779
+ pairIndex,
3780
+ primaryNode: node,
3781
+ contextLineCount,
3782
+ originalTotalLines: ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0,
3783
+ modifiedTotalLines: ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0
3784
+ });
3785
+ syncDiffUnchangedMetaNode(meta, unchangedRegionStyle, summaryLabel);
3040
3786
  }
3041
- const action = node.querySelector("a");
3787
+ const action = findDiffUnchangedExpandAction(node);
3042
3788
  if (action instanceof HTMLElement) {
3043
- action.classList.add("stream-monaco-unchanged-expand");
3044
- action.dataset.streamMonacoLabel = "Expand all";
3045
- action.title = "Expand all unmodified lines";
3046
- action.setAttribute("aria-label", "Expand all unmodified lines");
3047
- action.toggleAttribute("aria-hidden", shouldUseMergedSecondary);
3048
- action.tabIndex = shouldUseMergedSecondary ? -1 : 0;
3789
+ syncDiffUnchangedExpandAction(action, shouldUseMergedSecondary);
3049
3790
  if (action.dataset.streamMonacoExpandPatched !== "true") {
3050
3791
  action.dataset.streamMonacoExpandPatched = "true";
3792
+ const handleCaptureExpand = () => {
3793
+ this.capturePreviousDiffUnchangedState();
3794
+ };
3795
+ action.addEventListener("click", handleCaptureExpand, { capture: true });
3796
+ this.diffUnchangedRegionDisposables.push({ dispose: () => action.removeEventListener("click", handleCaptureExpand, true) });
3051
3797
  this.createDomDisposable(this.diffUnchangedRegionDisposables, action, "click", () => {
3052
3798
  this.hideAllDiffUnchangedBridgeEntries();
3053
3799
  this.scheduleCapturePersistedDiffUnchangedState(1);
@@ -3058,25 +3804,21 @@ var DiffEditorManager = class DiffEditorManager {
3058
3804
  if (node.dataset.streamMonacoCenterPatched !== "true") {
3059
3805
  node.dataset.streamMonacoCenterPatched = "true";
3060
3806
  this.bindFocusWithinClass(this.diffUnchangedRegionDisposables, node, "stream-monaco-focus-within");
3061
- const activate = () => {
3062
- const action$1 = node.querySelector("a");
3063
- if (action$1 instanceof HTMLElement) action$1.click();
3064
- };
3065
3807
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "click", (event) => {
3066
3808
  const mouseEvent = event;
3067
- if (mouseEvent.button !== 0) return;
3068
- const target = event.target instanceof HTMLElement ? event.target : null;
3069
- if (target === null || target === void 0 ? void 0 : target.closest("a, .breadcrumb-item")) return;
3809
+ if (!shouldHandleDiffUnchangedCenterClick(mouseEvent)) return;
3070
3810
  event.preventDefault();
3071
3811
  this.hideAllDiffUnchangedBridgeEntries();
3072
- activate();
3812
+ if (!activateDiffUnchangedExpandAction(node, () => {
3813
+ this.capturePreviousDiffUnchangedState();
3814
+ })) return;
3073
3815
  this.scheduleCapturePersistedDiffUnchangedState(1);
3074
3816
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3075
3817
  });
3076
3818
  }
3077
3819
  }
3078
3820
  renderMergedDiffUnchangedBridge(secondaryNode, primaryNode, pairIndex, pairCount) {
3079
- var _countSource$textCont2, _secondaryNode$closes;
3821
+ var _countSource$textCont2, _this$originalModel2, _this$modifiedModel3, _this$diffEditorView14, _this$diffEditorView15, _secondaryNode$closes;
3080
3822
  if (!this.lastContainer) return null;
3081
3823
  const overlay = this.ensureDiffUnchangedBridgeOverlay();
3082
3824
  if (!overlay) return null;
@@ -3085,9 +3827,19 @@ var DiffEditorManager = class DiffEditorManager {
3085
3827
  const primaryRect = primaryNode.getBoundingClientRect();
3086
3828
  const primaryStyle = globalThis.getComputedStyle(primaryNode);
3087
3829
  const countSource = primaryNode.querySelector(".stream-monaco-unchanged-count") ?? secondaryNode.querySelector(".stream-monaco-unchanged-count");
3088
- const countText = this.formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont2 = countSource.textContent) === null || _countSource$textCont2 === void 0 ? void 0 : _countSource$textCont2.trim()) || "Unmodified lines");
3830
+ const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont2 = countSource.textContent) === null || _countSource$textCont2 === void 0 ? void 0 : _countSource$textCont2.trim()) || "Unmodified lines");
3089
3831
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3090
- const metadataLabel = unchangedRegionStyle === "metadata" ? this.resolveDiffMetadataLabel(primaryNode, pairIndex) : null;
3832
+ const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3833
+ const summaryLabel = resolveDiffUnchangedSummaryLabel({
3834
+ countText,
3835
+ unchangedRegionStyle,
3836
+ lineChanges: this.getEffectiveLineChanges(),
3837
+ pairIndex,
3838
+ primaryNode,
3839
+ contextLineCount,
3840
+ originalTotalLines: ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getLineCount()) ?? 0,
3841
+ modifiedTotalLines: ((_this$modifiedModel3 = this.modifiedModel) === null || _this$modifiedModel3 === void 0 ? void 0 : _this$modifiedModel3.getLineCount()) ?? 0
3842
+ });
3091
3843
  const editorSurface = primaryNode.closest(".monaco-editor") ?? primaryNode;
3092
3844
  const editorSurfaceStyle = globalThis.getComputedStyle(editorSurface);
3093
3845
  const primaryHidden = primaryNode.parentElement;
@@ -3096,7 +3848,13 @@ var DiffEditorManager = class DiffEditorManager {
3096
3848
  const secondaryWidget = secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.parentElement;
3097
3849
  const topHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".top")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".top"));
3098
3850
  const bottomHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".bottom")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".bottom"));
3099
- const { showTopHandle, showBottomHandle } = this.resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount);
3851
+ const { showTopHandle, showBottomHandle } = resolveDiffUnchangedRevealLayout({
3852
+ primaryNode,
3853
+ countText,
3854
+ pairIndex,
3855
+ pairCount,
3856
+ modelLineCount: ((_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || (_this$diffEditorView14 = _this$diffEditorView14.getModifiedEditor().getModel()) === null || _this$diffEditorView14 === void 0 || (_this$diffEditorView15 = _this$diffEditorView14.getLineCount) === null || _this$diffEditorView15 === void 0 ? void 0 : _this$diffEditorView15.call(_this$diffEditorView14)) ?? null
3857
+ });
3100
3858
  const key = this.getDiffUnchangedBridgeKey(secondaryNode, primaryNode);
3101
3859
  secondaryNode.classList.add("stream-monaco-unchanged-bridge-source");
3102
3860
  primaryNode.classList.add("stream-monaco-unchanged-bridge-source");
@@ -3108,42 +3866,24 @@ var DiffEditorManager = class DiffEditorManager {
3108
3866
  const primaryAnchorRect = (primaryWidget === null || primaryWidget === void 0 ? void 0 : primaryWidget.getBoundingClientRect()) ?? primaryRect;
3109
3867
  const secondaryMargin = (_secondaryNode$closes = secondaryNode.closest(".monaco-editor")) === null || _secondaryNode$closes === void 0 ? void 0 : _secondaryNode$closes.querySelector(".margin");
3110
3868
  const secondaryMarginRect = secondaryMargin === null || secondaryMargin === void 0 ? void 0 : secondaryMargin.getBoundingClientRect();
3111
- const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? this.resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3869
+ const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3112
3870
  const bridgeLeftInset = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.leftInset) ?? 0;
3113
3871
  const bridgeRailWidth = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.width) ?? (secondaryMarginRect === null || secondaryMarginRect === void 0 ? void 0 : secondaryMarginRect.width) ?? null;
3114
- bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + this.lastContainer.scrollLeft + bridgeLeftInset}px`;
3115
- bridge.style.top = `${primaryAnchorRect.top - containerRect.top + this.lastContainer.scrollTop}px`;
3116
- bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
3117
- bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
3118
- bridge.style.color = primaryStyle.color;
3119
- bridge.style.fontFamily = primaryStyle.fontFamily;
3120
- bridge.style.fontSize = primaryStyle.fontSize;
3121
- bridge.style.lineHeight = primaryStyle.lineHeight;
3122
- bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
3123
- bridge.style.setProperty("--stream-monaco-editor-bg", editorSurfaceStyle.backgroundColor);
3124
- bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
3125
- if (bridgeRailWidth) bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
3126
- else bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
3127
- summary.classList.remove("stream-monaco-unchanged-summary-line-info", "stream-monaco-unchanged-summary-line-info-basic", "stream-monaco-unchanged-summary-metadata", "stream-monaco-unchanged-summary-simple");
3128
- summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
3129
- const summaryLabel = metadataLabel || countText;
3130
- const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
3131
- summary.disabled = !summaryInteractive;
3132
- summary.tabIndex = summaryInteractive ? 0 : -1;
3133
- if (summaryInteractive) {
3134
- summary.removeAttribute("aria-hidden");
3135
- summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
3136
- summary.title = "Expand all unmodified lines";
3137
- } else if (unchangedRegionStyle === "simple") {
3138
- summary.setAttribute("aria-hidden", "true");
3139
- summary.removeAttribute("aria-label");
3140
- summary.title = "";
3141
- } else {
3142
- summary.removeAttribute("aria-hidden");
3143
- summary.removeAttribute("aria-label");
3144
- summary.title = "";
3145
- }
3146
- this.updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel);
3872
+ syncDiffUnchangedBridgeNode({
3873
+ bridge,
3874
+ unchangedRegionStyle,
3875
+ containerRect,
3876
+ containerScrollLeft: this.lastContainer.scrollLeft,
3877
+ containerScrollTop: this.lastContainer.scrollTop,
3878
+ secondaryAnchorRect,
3879
+ primaryAnchorRect,
3880
+ bridgeLeftInset,
3881
+ bridgeRailWidth,
3882
+ primaryStyle,
3883
+ editorBackgroundColor: editorSurfaceStyle.backgroundColor
3884
+ });
3885
+ syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel);
3886
+ syncDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
3147
3887
  if (unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic") {
3148
3888
  this.syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle ?? null, showBottomHandle, bottomHandle ?? null);
3149
3889
  if (entry.rail && entry.rail.parentElement !== bridge) bridge.prepend(entry.rail);
@@ -3152,8 +3892,9 @@ var DiffEditorManager = class DiffEditorManager {
3152
3892
  entry.rail.setAttribute("aria-hidden", "true");
3153
3893
  }
3154
3894
  entry.activate = () => {
3155
- const action = primaryNode.querySelector("a, button") ?? secondaryNode.querySelector("a, button");
3895
+ const action = findDiffUnchangedActivationAction(primaryNode, secondaryNode);
3156
3896
  if (action instanceof HTMLElement) {
3897
+ this.capturePreviousDiffUnchangedState();
3157
3898
  action.click();
3158
3899
  this.scheduleCapturePersistedDiffUnchangedState(1);
3159
3900
  }
@@ -3172,11 +3913,23 @@ var DiffEditorManager = class DiffEditorManager {
3172
3913
  node.title = node.title || "Collapse unchanged lines";
3173
3914
  this.bindFocusVisibleClass(this.diffUnchangedRegionDisposables, node);
3174
3915
  this.bindPersistOnMouseRelease(this.diffUnchangedRegionDisposables, node);
3916
+ this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "mouseup", (event) => {
3917
+ const mouseEvent = event;
3918
+ if (mouseEvent.button !== 0) return;
3919
+ if (!this.restorePreviousDiffUnchangedState()) return;
3920
+ event.preventDefault();
3921
+ event.stopPropagation();
3922
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3923
+ });
3175
3924
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "keydown", (event) => {
3176
3925
  const keyboardEvent = event;
3177
3926
  if (keyboardEvent.key !== "Enter" && keyboardEvent.key !== " ") return;
3178
3927
  keyboardEvent.preventDefault();
3179
- this.dispatchSyntheticMouseDown(node);
3928
+ if (this.restorePreviousDiffUnchangedState()) {
3929
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3930
+ return;
3931
+ }
3932
+ dispatchSyntheticPrimaryMouseDown(node);
3180
3933
  this.scheduleCapturePersistedDiffUnchangedState(1);
3181
3934
  });
3182
3935
  }
@@ -3185,6 +3938,11 @@ var DiffEditorManager = class DiffEditorManager {
3185
3938
  this.applyDiffRootAppearanceClass();
3186
3939
  const viewZoneHeightsChanged = this.syncDiffUnchangedViewZoneHeights();
3187
3940
  const centers = this.lastContainer.querySelectorAll(".diff-hidden-lines .center");
3941
+ const modifiedHiddenSummaryMidpoints = Array.from(this.lastContainer.querySelectorAll(".editor.modified .diff-hidden-lines .center")).map((node) => {
3942
+ const rect = node.getBoundingClientRect();
3943
+ if (rect.width <= 0 || rect.height <= 0) return null;
3944
+ return rect.top + rect.height / 2;
3945
+ }).filter((value) => value !== null);
3188
3946
  Array.from(centers).sort((a, b) => a.getBoundingClientRect().top - b.getBoundingClientRect().top).forEach((node, index) => this.patchDiffUnchangedCenter(node, index));
3189
3947
  const partialRevealHandles = this.lastContainer.querySelectorAll(".diff-hidden-lines .top, .diff-hidden-lines .bottom");
3190
3948
  partialRevealHandles.forEach((node) => {
@@ -3209,7 +3967,13 @@ var DiffEditorManager = class DiffEditorManager {
3209
3967
  this.pruneDiffUnchangedBridgeEntries(visibleKeys);
3210
3968
  this.syncDiffUnchangedOverlayScrollBaseline();
3211
3969
  const foldGlyphs = this.lastContainer.querySelectorAll(".fold-unchanged");
3212
- foldGlyphs.forEach((node) => this.patchDiffUnchangedFoldGlyph(node));
3970
+ foldGlyphs.forEach((node) => {
3971
+ const rect = node.getBoundingClientRect();
3972
+ const midpoint = rect.top + rect.height / 2;
3973
+ const overlapsHiddenSummary = modifiedHiddenSummaryMidpoints.some((summaryMidpoint) => Math.abs(summaryMidpoint - midpoint) <= 8);
3974
+ node.classList.toggle("stream-monaco-fold-unchanged-hidden", overlapsHiddenSummary);
3975
+ this.patchDiffUnchangedFoldGlyph(node);
3976
+ });
3213
3977
  if (viewZoneHeightsChanged) this.schedulePatchDiffUnchangedRegions();
3214
3978
  }
3215
3979
  schedulePatchDiffUnchangedRegions() {
@@ -3222,12 +3986,12 @@ var DiffEditorManager = class DiffEditorManager {
3222
3986
  this.schedulePatchDiffUnchangedRegions();
3223
3987
  }
3224
3988
  setupDiffUnchangedRegionEnhancements() {
3225
- var _globalThis$getComput, _globalThis;
3989
+ var _globalThis$getComput2, _globalThis2;
3226
3990
  this.disposeDiffUnchangedRegionEnhancements();
3227
3991
  if (!this.diffEditorView || !this.lastContainer) return;
3228
3992
  if (typeof document === "undefined") return;
3229
3993
  this.ensureDiffUiStyle();
3230
- const containerStyle = (_globalThis$getComput = (_globalThis = globalThis).getComputedStyle) === null || _globalThis$getComput === void 0 ? void 0 : _globalThis$getComput.call(_globalThis, this.lastContainer);
3994
+ const containerStyle = (_globalThis$getComput2 = (_globalThis2 = globalThis).getComputedStyle) === null || _globalThis$getComput2 === void 0 ? void 0 : _globalThis$getComput2.call(_globalThis2, this.lastContainer);
3231
3995
  if (!containerStyle || containerStyle.position === "static") this.lastContainer.style.position = "relative";
3232
3996
  this.applyDiffRootAppearanceClass();
3233
3997
  this.schedulePatchDiffUnchangedRegions();
@@ -3255,6 +4019,20 @@ var DiffEditorManager = class DiffEditorManager {
3255
4019
  this.applyDiffRootAppearanceClass();
3256
4020
  this.schedulePatchDiffUnchangedRegions();
3257
4021
  };
4022
+ const handleFoldMouseUp = (event) => {
4023
+ var _event$event, _event$target, _event$event2, _event$event2$prevent, _event$event3, _event$event3$stopPro;
4024
+ if (event === null || event === void 0 || (_event$event = event.event) === null || _event$event === void 0 ? void 0 : _event$event.rightButton) return;
4025
+ const targetElement = event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.element;
4026
+ const className = typeof (targetElement === null || targetElement === void 0 ? void 0 : targetElement.className) === "string" ? targetElement.className : "";
4027
+ if (!className.includes("fold-unchanged")) return;
4028
+ if (!this.diffPreviousUnchangedModelState) return;
4029
+ event === null || event === void 0 || (_event$event2 = event.event) === null || _event$event2 === void 0 || (_event$event2$prevent = _event$event2.preventDefault) === null || _event$event2$prevent === void 0 || _event$event2$prevent.call(_event$event2);
4030
+ event === null || event === void 0 || (_event$event3 = event.event) === null || _event$event3 === void 0 || (_event$event3$stopPro = _event$event3.stopPropagation) === null || _event$event3$stopPro === void 0 || _event$event3$stopPro.call(_event$event3);
4031
+ requestAnimationFrame(() => {
4032
+ if (!this.restorePreviousDiffUnchangedState()) return;
4033
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
4034
+ });
4035
+ };
3258
4036
  this.diffUnchangedRegionDisposables.push(this.diffEditorView.onDidUpdateDiff(() => {
3259
4037
  repatch();
3260
4038
  this.scheduleRestorePersistedDiffUnchangedState();
@@ -3263,23 +4041,29 @@ var DiffEditorManager = class DiffEditorManager {
3263
4041
  this.diffUnchangedRegionDisposables.push(modifiedEditor.onDidLayoutChange(repatch));
3264
4042
  this.diffUnchangedRegionDisposables.push(originalEditor.onDidScrollChange(() => this.schedulePatchDiffUnchangedRegionsAfterScroll()));
3265
4043
  this.diffUnchangedRegionDisposables.push(modifiedEditor.onDidScrollChange(() => this.schedulePatchDiffUnchangedRegionsAfterScroll()));
4044
+ this.diffUnchangedRegionDisposables.push(originalEditor.onMouseUp(handleFoldMouseUp));
4045
+ this.diffUnchangedRegionDisposables.push(modifiedEditor.onMouseUp(handleFoldMouseUp));
3266
4046
  this.createDomDisposable(this.diffUnchangedRegionDisposables, this.lastContainer, "scroll", () => this.schedulePatchDiffUnchangedRegionsAfterScroll());
3267
4047
  }
3268
4048
  setupDiffHunkInteractions() {
3269
- var _globalThis$getComput2, _globalThis2;
4049
+ var _globalThis$getComput3, _globalThis3;
3270
4050
  this.disposeDiffHunkInteractions();
3271
4051
  if (!this.diffEditorView || !this.lastContainer) return;
3272
4052
  if (this.options.diffHunkActionsOnHover !== true) return;
3273
4053
  if (typeof document === "undefined") return;
3274
4054
  this.ensureDiffUiStyle();
3275
- const containerStyle = (_globalThis$getComput2 = (_globalThis2 = globalThis).getComputedStyle) === null || _globalThis$getComput2 === void 0 ? void 0 : _globalThis$getComput2.call(_globalThis2, this.lastContainer);
4055
+ const containerStyle = (_globalThis$getComput3 = (_globalThis3 = globalThis).getComputedStyle) === null || _globalThis$getComput3 === void 0 ? void 0 : _globalThis$getComput3.call(_globalThis3, this.lastContainer);
3276
4056
  if (!containerStyle || containerStyle.position === "static") this.lastContainer.style.position = "relative";
3277
4057
  const overlay = document.createElement("div");
3278
4058
  overlay.className = "stream-monaco-diff-hunk-overlay";
3279
4059
  this.diffHunkOverlay = overlay;
3280
4060
  this.lastContainer.append(overlay);
3281
- this.diffHunkUpperNode = this.createDiffHunkActionNode("upper");
3282
- this.diffHunkLowerNode = this.createDiffHunkActionNode("lower");
4061
+ this.diffHunkUpperNode = createDiffHunkActionNode("upper", (side, action) => this.applyDiffHunkAction(side, action));
4062
+ this.diffHunkLowerNode = createDiffHunkActionNode("lower", (side, action) => this.applyDiffHunkAction(side, action));
4063
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
4064
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
4065
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
4066
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
3283
4067
  overlay.append(this.diffHunkUpperNode, this.diffHunkLowerNode);
3284
4068
  const originalEditor = this.diffEditorView.getOriginalEditor();
3285
4069
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
@@ -3322,113 +4106,35 @@ var DiffEditorManager = class DiffEditorManager {
3322
4106
  if (this.diffHunkUpperNode) this.diffHunkUpperNode.style.display = "none";
3323
4107
  if (this.diffHunkLowerNode) this.diffHunkLowerNode.style.display = "none";
3324
4108
  }
3325
- inferInlineDiffHunkHoverSide(change, event) {
3326
- var _event$target$positio;
3327
- const targetElement = event.target.element instanceof HTMLElement ? event.target.element : null;
3328
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
3329
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
3330
- if (!this.hasModifiedLines(change)) return "upper";
3331
- if (!this.hasOriginalLines(change)) return "lower";
3332
- const hoverLine = ((_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber) ?? 0;
3333
- const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
3334
- return hoverLine < modifiedAnchor ? "upper" : "lower";
3335
- }
3336
- hasOriginalLines(change) {
3337
- return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
3338
- }
3339
- hasModifiedLines(change) {
3340
- return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
3341
- }
3342
- distanceToLineChange(side, change, line) {
3343
- const hasRange = side === "original" ? this.hasOriginalLines(change) : this.hasModifiedLines(change);
3344
- const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
3345
- const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
3346
- if (hasRange) {
3347
- if (line < start) return start - line;
3348
- if (line > end) return line - end;
3349
- return 0;
3350
- }
3351
- const fallbackAnchor = Math.max(1, start || end || 1);
3352
- return Math.abs(line - fallbackAnchor);
3353
- }
3354
- findLineChangeByHoverLine(side, line) {
3355
- if (this.diffHunkLineChanges.length === 0) return null;
3356
- let best = null;
3357
- let bestDistance = Number.POSITIVE_INFINITY;
3358
- for (const change of this.diffHunkLineChanges) {
3359
- const distance = this.distanceToLineChange(side, change, line);
3360
- if (distance < bestDistance) {
3361
- bestDistance = distance;
3362
- best = change;
3363
- if (distance === 0) break;
3364
- }
3365
- }
3366
- if (bestDistance > 2) return null;
3367
- return best;
3368
- }
3369
4109
  handleDiffHunkMouseMove(side, event) {
3370
- var _event$target$positio2;
3371
- const line = (_event$target$positio2 = event.target.position) === null || _event$target$positio2 === void 0 ? void 0 : _event$target$positio2.lineNumber;
4110
+ var _event$target$positio, _event$target$positio2;
4111
+ const line = (_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber;
3372
4112
  if (!line) {
3373
4113
  this.scheduleHideDiffHunkActions(120);
3374
4114
  return;
3375
4115
  }
3376
- const change = this.findLineChangeByHoverLine(side, line);
4116
+ const change = findLineChangeByHoverLine(this.diffHunkLineChanges, side, line);
3377
4117
  if (!change) {
3378
4118
  this.scheduleHideDiffHunkActions(120);
3379
4119
  return;
3380
4120
  }
3381
4121
  this.cancelScheduledHideDiffHunkActions();
3382
4122
  this.diffHunkActiveChange = change;
3383
- this.diffHunkActiveHoverSide = this.isDiffInlineMode() ? this.inferInlineDiffHunkHoverSide(change, event) : null;
4123
+ this.diffHunkActiveHoverSide = this.isDiffInlineMode() ? inferInlineDiffHunkHoverSide(change, ((_event$target$positio2 = event.target.position) === null || _event$target$positio2 === void 0 ? void 0 : _event$target$positio2.lineNumber) ?? 0, event.target.element instanceof HTMLElement ? event.target.element : null) : null;
3384
4124
  this.repositionDiffHunkNodes();
3385
4125
  }
3386
4126
  isOriginalEditorCollapsed() {
3387
- var _this$diffEditorView$4, _this$diffEditorView$5;
4127
+ var _this$diffEditorView$2, _this$diffEditorView$3;
3388
4128
  if (!this.diffEditorView) return true;
3389
- const info = (_this$diffEditorView$4 = (_this$diffEditorView$5 = this.diffEditorView.getOriginalEditor()).getLayoutInfo) === null || _this$diffEditorView$4 === void 0 ? void 0 : _this$diffEditorView$4.call(_this$diffEditorView$5);
4129
+ const info = (_this$diffEditorView$2 = (_this$diffEditorView$3 = this.diffEditorView.getOriginalEditor()).getLayoutInfo) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$3);
3390
4130
  return !info || info.width < 24;
3391
4131
  }
3392
4132
  isDiffInlineMode() {
3393
- var _this$lastContainer2;
3394
- const diffRoot = (_this$lastContainer2 = this.lastContainer) === null || _this$lastContainer2 === void 0 ? void 0 : _this$lastContainer2.querySelector(".monaco-diff-editor");
3395
- if (diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
4133
+ var _this$lastContainer8, _this$lastContainer9;
4134
+ const diffRoot = typeof ((_this$lastContainer8 = this.lastContainer) === null || _this$lastContainer8 === void 0 ? void 0 : _this$lastContainer8.querySelector) === "function" ? (_this$lastContainer9 = this.lastContainer) === null || _this$lastContainer9 === void 0 ? void 0 : _this$lastContainer9.querySelector(".monaco-diff-editor") : null;
4135
+ if (typeof HTMLElement !== "undefined" && diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
3396
4136
  return this.isOriginalEditorCollapsed();
3397
4137
  }
3398
- getEditorBySide(side) {
3399
- if (!this.diffEditorView) return null;
3400
- return side === "original" ? this.diffEditorView.getOriginalEditor() : this.diffEditorView.getModifiedEditor();
3401
- }
3402
- getFullLineRange(model, startLine, endLine) {
3403
- if (endLine < startLine) return null;
3404
- const lineCount = model.getLineCount();
3405
- if (lineCount < 1) return null;
3406
- const start = Math.max(1, Math.min(startLine, lineCount));
3407
- const end = Math.max(start, Math.min(endLine, lineCount));
3408
- if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
3409
- return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
3410
- }
3411
- getLinesText(model, startLine, endLine) {
3412
- const range = this.getFullLineRange(model, startLine, endLine);
3413
- if (!range) return "";
3414
- return model.getValueInRange(range);
3415
- }
3416
- getInsertRangeBeforeLine(model, lineNumber) {
3417
- const lineCount = model.getLineCount();
3418
- if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3419
- if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
3420
- const lastLine = lineCount;
3421
- const lastColumn = model.getLineMaxColumn(lastLine);
3422
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3423
- }
3424
- getInsertRangeAfterLine(model, lineNumber) {
3425
- const lineCount = model.getLineCount();
3426
- if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3427
- if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
3428
- const lastLine = lineCount;
3429
- const lastColumn = model.getLineMaxColumn(lastLine);
3430
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3431
- }
3432
4138
  applyDiffModelLanguage(models, codeLanguage) {
3433
4139
  if (!codeLanguage) return;
3434
4140
  const lang = processedLanguage(codeLanguage);
@@ -3440,8 +4146,8 @@ var DiffEditorManager = class DiffEditorManager {
3440
4146
  if (!this.diffEditorView || !viewState) return;
3441
4147
  const restore = () => {
3442
4148
  try {
3443
- var _this$diffEditorView25;
3444
- (_this$diffEditorView25 = this.diffEditorView) === null || _this$diffEditorView25 === void 0 || _this$diffEditorView25.restoreViewState(viewState);
4149
+ var _this$diffEditorView16;
4150
+ (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.restoreViewState(viewState);
3445
4151
  } catch {}
3446
4152
  };
3447
4153
  restore();
@@ -3459,7 +4165,7 @@ var DiffEditorManager = class DiffEditorManager {
3459
4165
  this.pendingPreparedDiffViewModel = null;
3460
4166
  }
3461
4167
  syncDiffKnownValues() {
3462
- var _this$diffEditorView26, _this$diffEditorView27, _this$diffEditorView28, _this$diffHeightManag2;
4168
+ var _this$diffEditorView17, _this$diffEditorView18, _this$diffEditorView19, _this$diffHeightManag4;
3463
4169
  if (this.originalModel) this.lastKnownOriginalCode = this.originalModel.getValue();
3464
4170
  if (this.modifiedModel) {
3465
4171
  this.lastKnownModifiedCode = this.modifiedModel.getValue();
@@ -3468,67 +4174,15 @@ var DiffEditorManager = class DiffEditorManager {
3468
4174
  this.lastKnownModifiedDirty = false;
3469
4175
  this._hasScrollBar = false;
3470
4176
  this.cachedComputedHeightDiff = this.computedHeight();
3471
- this.cachedScrollHeightDiff = ((_this$diffEditorView26 = this.diffEditorView) === null || _this$diffEditorView26 === void 0 || (_this$diffEditorView28 = (_this$diffEditorView27 = _this$diffEditorView26.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView28 === void 0 ? void 0 : _this$diffEditorView28.call(_this$diffEditorView27)) ?? this.cachedScrollHeightDiff;
3472
- (_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
3473
- }
3474
- applyDefaultDiffHunkAction(context) {
3475
- const { action, side, lineChange } = context;
3476
- if (!this.originalModel || !this.modifiedModel) return;
3477
- const hasOriginal = this.hasOriginalLines(lineChange);
3478
- const hasModified = this.hasModifiedLines(lineChange);
3479
- if (action === "revert" && side === "upper") {
3480
- if (!hasOriginal) return;
3481
- const text = this.getLinesText(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3482
- if (!text) return;
3483
- const range = hasModified ? this.getInsertRangeBeforeLine(this.modifiedModel, lineChange.modifiedStartLineNumber) : this.getInsertRangeAfterLine(this.modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
3484
- this.modifiedModel.applyEdits([{
3485
- range,
3486
- text,
3487
- forceMoveMarkers: true
3488
- }]);
3489
- return;
3490
- }
3491
- if (action === "revert" && side === "lower") {
3492
- if (!hasModified) return;
3493
- const range = this.getFullLineRange(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3494
- if (!range) return;
3495
- this.modifiedModel.applyEdits([{
3496
- range,
3497
- text: "",
3498
- forceMoveMarkers: true
3499
- }]);
3500
- return;
3501
- }
3502
- if (action === "stage" && side === "upper") {
3503
- if (!hasOriginal) return;
3504
- const range = this.getFullLineRange(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3505
- if (!range) return;
3506
- this.originalModel.applyEdits([{
3507
- range,
3508
- text: "",
3509
- forceMoveMarkers: true
3510
- }]);
3511
- return;
3512
- }
3513
- if (action === "stage" && side === "lower") {
3514
- if (!hasModified) return;
3515
- const text = this.getLinesText(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3516
- if (!text) return;
3517
- const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
3518
- const range = this.getInsertRangeAfterLine(this.originalModel, anchor);
3519
- this.originalModel.applyEdits([{
3520
- range,
3521
- text,
3522
- forceMoveMarkers: true
3523
- }]);
3524
- }
4177
+ this.cachedScrollHeightDiff = ((_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView19 = (_this$diffEditorView18 = _this$diffEditorView17.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView19 === void 0 ? void 0 : _this$diffEditorView19.call(_this$diffEditorView18)) ?? this.cachedScrollHeightDiff;
4178
+ (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3525
4179
  }
3526
4180
  async applyDiffHunkAction(side, action) {
3527
4181
  if (!this.diffHunkActiveChange || !this.originalModel || !this.modifiedModel) return;
3528
4182
  if (this.diffHunkActionInFlight) return;
3529
4183
  this.diffHunkActionInFlight = true;
3530
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
3531
- this.setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
4184
+ setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
4185
+ setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
3532
4186
  try {
3533
4187
  this.flushOriginalAppendBufferSync();
3534
4188
  this.flushModifiedAppendBufferSync();
@@ -3545,39 +4199,13 @@ var DiffEditorManager = class DiffEditorManager {
3545
4199
  } catch (error$1) {
3546
4200
  console.warn("onDiffHunkAction callback threw an error:", error$1);
3547
4201
  }
3548
- if (allowDefault) this.applyDefaultDiffHunkAction(context);
4202
+ if (allowDefault) applyDefaultDiffHunkAction(context);
3549
4203
  this.syncDiffKnownValues();
3550
4204
  this.hideDiffHunkActions();
3551
4205
  } finally {
3552
4206
  this.diffHunkActionInFlight = false;
3553
4207
  }
3554
4208
  }
3555
- setDiffHunkNodeEnabled(node, enabled) {
3556
- if (!node) return;
3557
- const buttons = node.querySelectorAll("button");
3558
- buttons.forEach((button) => {
3559
- button.disabled = !enabled;
3560
- });
3561
- }
3562
- positionDiffHunkNode(node, side, anchorLine, extraOffsetY = 0) {
3563
- var _editor$getScrollTop2;
3564
- if (!this.diffHunkOverlay) return;
3565
- const editor = this.getEditorBySide(side);
3566
- if (!editor) return;
3567
- const host = editor.getContainerDomNode();
3568
- const line = Math.max(1, anchorLine);
3569
- const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop2 = editor.getScrollTop) === null || _editor$getScrollTop2 === void 0 ? void 0 : _editor$getScrollTop2.call(editor)) ?? 0);
3570
- const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
3571
- const nodeWidth = node.offsetWidth || 130;
3572
- const nodeHeight = node.offsetHeight || 30;
3573
- const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
3574
- const hostTop = host.offsetTop;
3575
- const minTop = hostTop + 4;
3576
- const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
3577
- const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
3578
- node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
3579
- node.style.display = "flex";
3580
- }
3581
4209
  repositionDiffHunkNodes() {
3582
4210
  if (!this.diffHunkActiveChange) {
3583
4211
  this.hideDiffHunkActions();
@@ -3586,22 +4214,22 @@ var DiffEditorManager = class DiffEditorManager {
3586
4214
  if (!this.diffHunkUpperNode || !this.diffHunkLowerNode) return;
3587
4215
  if (!this.diffEditorView) return;
3588
4216
  const change = this.diffHunkActiveChange;
3589
- const hasOriginal = this.hasOriginalLines(change);
3590
- const hasModified = this.hasModifiedLines(change);
3591
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
3592
- this.setDiffHunkNodeEnabled(this.diffHunkLowerNode, hasModified);
4217
+ const hasOriginal = hasOriginalLines(change);
4218
+ const hasModified = hasModifiedLines(change);
4219
+ setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
4220
+ setDiffHunkNodeEnabled(this.diffHunkLowerNode, hasModified);
3593
4221
  const inlineMode = this.isDiffInlineMode();
3594
4222
  if (inlineMode) {
3595
4223
  const inlineHoverSide = this.diffHunkActiveHoverSide ?? (hasOriginal && !hasModified ? "upper" : "lower");
3596
4224
  if (inlineHoverSide === "upper" && hasOriginal) {
3597
4225
  const upperAnchor = Math.max(1, change.modifiedStartLineNumber - 1 || change.modifiedEndLineNumber || 1);
3598
- this.positionDiffHunkNode(this.diffHunkUpperNode, "modified", upperAnchor);
4226
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getModifiedEditor(), upperAnchor);
3599
4227
  this.diffHunkLowerNode.style.display = "none";
3600
4228
  return;
3601
4229
  }
3602
4230
  if (hasModified) {
3603
4231
  const lowerAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
3604
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4232
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
3605
4233
  this.diffHunkUpperNode.style.display = "none";
3606
4234
  return;
3607
4235
  }
@@ -3609,13 +4237,12 @@ var DiffEditorManager = class DiffEditorManager {
3609
4237
  return;
3610
4238
  }
3611
4239
  if (hasOriginal) {
3612
- const upperSide = "original";
3613
4240
  const upperAnchor = change.originalStartLineNumber;
3614
- this.positionDiffHunkNode(this.diffHunkUpperNode, upperSide, upperAnchor);
4241
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getOriginalEditor(), upperAnchor);
3615
4242
  } else this.diffHunkUpperNode.style.display = "none";
3616
4243
  if (hasModified) {
3617
4244
  const lowerAnchor = change.modifiedStartLineNumber;
3618
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4245
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
3619
4246
  } else this.diffHunkLowerNode.style.display = "none";
3620
4247
  }
3621
4248
  scheduleFlushAppendBufferDiff() {
@@ -3653,24 +4280,43 @@ var DiffEditorManager = class DiffEditorManager {
3653
4280
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
3654
4281
  this.appendToModel(this.originalModel, text);
3655
4282
  }
4283
+ computeRawHeight() {
4284
+ return computeDiffRawHeight({
4285
+ diffEditorView: this.diffEditorView,
4286
+ maxHeightValue: this.maxHeightValue
4287
+ });
4288
+ }
3656
4289
  computedHeight() {
3657
- var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc5, _modifiedEditor$getSc10;
3658
- if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
3659
- const modifiedEditor = this.diffEditorView.getModifiedEditor();
3660
- const originalEditor = this.diffEditorView.getOriginalEditor();
3661
- const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
3662
- const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
3663
- const mCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
3664
- const lineCount = Math.max(oCount, mCount);
3665
- const fromLines = lineCount * lineHeight + padding;
3666
- const scrollH = Math.max(((_originalEditor$getSc5 = originalEditor.getScrollHeight) === null || _originalEditor$getSc5 === void 0 ? void 0 : _originalEditor$getSc5.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc10 = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc10 === void 0 ? void 0 : _modifiedEditor$getSc10.call(modifiedEditor)) ?? 0);
3667
- const desired = Math.max(fromLines, scrollH);
3668
- return Math.min(desired, this.maxHeightValue);
4290
+ const { height, nextInlineDiffStreamingHeightFloor } = computeDiffHeight({
4291
+ rawHeight: this.computeRawHeight(),
4292
+ isInlineMode: this.isDiffInlineMode(),
4293
+ inlineDiffStreamingPresentationActive: this.inlineDiffStreamingPresentationActive,
4294
+ inlineDiffStreamingHeightFloor: this.inlineDiffStreamingHeightFloor
4295
+ });
4296
+ this.inlineDiffStreamingHeightFloor = nextInlineDiffStreamingHeightFloor;
4297
+ return height;
4298
+ }
4299
+ eagerlyGrowDiffContainerHeight() {
4300
+ var _this$lastContainer$g, _this$lastContainer10;
4301
+ if (!this.lastContainer) return;
4302
+ const next = this.computedHeight();
4303
+ if (!Number.isFinite(next) || next <= 0) return;
4304
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4305
+ const measured = ((_this$lastContainer$g = (_this$lastContainer10 = this.lastContainer).getBoundingClientRect) === null || _this$lastContainer$g === void 0 ? void 0 : _this$lastContainer$g.call(_this$lastContainer10).height) ?? this.lastContainer.clientHeight ?? 0;
4306
+ const baseline = Math.max(applied, measured);
4307
+ if (next <= baseline + 1) return;
4308
+ this.lastContainer.style.height = `${next}px`;
4309
+ this.cachedComputedHeightDiff = next;
4310
+ this.scheduleSyncDiffEditorLayoutToContainer();
3669
4311
  }
3670
4312
  isOverflowAutoDiff() {
3671
4313
  if (!this.lastContainer) return false;
3672
4314
  return this.computedHeight() >= this.maxHeightValue - 1;
3673
4315
  }
4316
+ shouldAvoidOptimisticMaxHeightWriteDiff() {
4317
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved;
4318
+ return this.isDiffInlineMode() && (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) === true && !this.diffHideUnchangedRegionsDeferred;
4319
+ }
3674
4320
  shouldPerformImmediateRevealDiff() {
3675
4321
  return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
3676
4322
  }
@@ -3693,17 +4339,22 @@ var DiffEditorManager = class DiffEditorManager {
3693
4339
  if (this._hasScrollBar) return true;
3694
4340
  const m = this.measureViewportDiff();
3695
4341
  if (!m) return false;
3696
- const epsilon = Math.max(2, Math.round(m.lineHeight / 8));
3697
- return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
4342
+ return this._hasScrollBar = hasVerticalScrollbar(m);
3698
4343
  }
3699
4344
  userIsNearBottomDiff() {
3700
4345
  if (!this.diffEditorView) return true;
3701
4346
  const m = this.measureViewportDiff();
3702
4347
  if (!m || !m.li) return true;
3703
- const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
3704
- const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
3705
- const distance = m.scrollHeight - (m.scrollTop + m.li.height);
3706
- return distance <= threshold;
4348
+ return isUserNearBottom({
4349
+ computedHeight: m.computedHeight,
4350
+ lineHeight: m.lineHeight,
4351
+ scrollHeight: m.scrollHeight,
4352
+ scrollTop: m.scrollTop,
4353
+ viewportHeight: m.li.height
4354
+ }, {
4355
+ autoScrollThresholdLines: this.autoScrollThresholdLines ?? 0,
4356
+ autoScrollThresholdPx: this.autoScrollThresholdPx || 0
4357
+ });
3707
4358
  }
3708
4359
  maybeScrollDiffToBottom(targetLine, prevLineOverride) {
3709
4360
  this.rafScheduler.schedule("maybe-scroll-diff", () => {
@@ -3779,7 +4430,7 @@ var DiffEditorManager = class DiffEditorManager {
3779
4430
  }
3780
4431
  performRevealDiffTicketed(line, ticket) {
3781
4432
  this.rafScheduler.schedule("revealDiff", () => {
3782
- var _editor;
4433
+ var _editor$1;
3783
4434
  if (this.diffScrollWatcher) {
3784
4435
  log("diff", "performRevealDiffTicketed - suppressing watcher", {
3785
4436
  ticket,
@@ -3794,16 +4445,11 @@ var DiffEditorManager = class DiffEditorManager {
3794
4445
  line
3795
4446
  });
3796
4447
  const strategy = this.diffHideUnchangedRegionsDeferred ? "bottom" : this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
3797
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
3798
- const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
4448
+ const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
4449
+ const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
3799
4450
  try {
3800
4451
  const me = this.diffEditorView.getModifiedEditor();
3801
- if (strategy === "bottom") if (typeof smooth !== "undefined") me.revealLine(line, smooth);
3802
- else me.revealLine(line);
3803
- else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
3804
- else me.revealLineInCenter(line);
3805
- else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
3806
- else me.revealLineInCenterIfOutsideViewport(line);
4452
+ revealEditorLine(me, line, strategy, smooth);
3807
4453
  } catch {
3808
4454
  try {
3809
4455
  this.diffEditorView.getModifiedEditor().revealLine(line);
@@ -3815,8 +4461,8 @@ var DiffEditorManager = class DiffEditorManager {
3815
4461
  lastRevealLineDiff: this.lastRevealLineDiff
3816
4462
  });
3817
4463
  try {
3818
- var _this$diffEditorView29, _this$diffEditorView30, _this$diffEditorView31;
3819
- this.lastScrollTopDiff = ((_this$diffEditorView29 = this.diffEditorView) === null || _this$diffEditorView29 === void 0 || (_this$diffEditorView31 = (_this$diffEditorView30 = _this$diffEditorView29.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView31 === void 0 ? void 0 : _this$diffEditorView31.call(_this$diffEditorView30)) ?? this.lastScrollTopDiff;
4464
+ var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22;
4465
+ this.lastScrollTopDiff = ((_this$diffEditorView20 = this.diffEditorView) === null || _this$diffEditorView20 === void 0 || (_this$diffEditorView22 = (_this$diffEditorView21 = _this$diffEditorView20.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView22 === void 0 ? void 0 : _this$diffEditorView22.call(_this$diffEditorView21)) ?? this.lastScrollTopDiff;
3820
4466
  } catch {}
3821
4467
  });
3822
4468
  }
@@ -3824,11 +4470,10 @@ var DiffEditorManager = class DiffEditorManager {
3824
4470
  var _editor2;
3825
4471
  if (!this.diffEditorView) return;
3826
4472
  if (ticket !== this.revealTicketDiff) return;
3827
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
3828
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
4473
+ const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
4474
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
3829
4475
  const me = this.diffEditorView.getModifiedEditor();
3830
- if (typeof immediate !== "undefined") me.revealLine(line, immediate);
3831
- else me.revealLine(line);
4476
+ revealEditorLine(me, line, "bottom", immediate);
3832
4477
  this.measureViewportDiff();
3833
4478
  log("diff", "performImmediateRevealDiff", {
3834
4479
  line,
@@ -3842,34 +4487,28 @@ var DiffEditorManager = class DiffEditorManager {
3842
4487
  if (target !== -1 && this.diffHeightManager) {
3843
4488
  if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
3844
4489
  await this.waitForHeightAppliedDiff(target);
4490
+ this.syncDiffEditorLayoutToContainer();
3845
4491
  }
3846
4492
  this.performImmediateRevealDiff(line, ticket);
3847
4493
  });
3848
4494
  }
3849
4495
  waitForHeightAppliedDiff(target, timeoutMs = 500) {
3850
- return new Promise((resolve) => {
3851
- const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
3852
- const check = () => {
3853
- const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
3854
- if (applied >= target - 1) {
3855
- resolve();
3856
- return;
3857
- }
3858
- if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
3859
- resolve();
3860
- return;
3861
- }
3862
- requestAnimationFrame(check);
3863
- };
3864
- check();
3865
- });
4496
+ return waitForElementHeightApplied(this.lastContainer, target, timeoutMs);
3866
4497
  }
3867
4498
  async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
3868
- var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
4499
+ var _me$getScrollHeight2, _me$getOption, _oEditor$onDidLayoutC, _mEditor$onDidLayoutC, _oEditor$onDidContent, _mEditor$onDidContent;
3869
4500
  this.cleanup();
3870
4501
  this.lastContainer = container;
3871
4502
  container.style.overflow = "hidden";
3872
4503
  container.style.maxHeight = this.maxHeightCSS;
4504
+ container.innerHTML = "";
4505
+ const editorMount = typeof document !== "undefined" ? document.createElement("div") : container;
4506
+ if (editorMount !== container) {
4507
+ editorMount.style.width = "100%";
4508
+ editorMount.style.height = "100%";
4509
+ editorMount.style.overflow = "hidden";
4510
+ container.append(editorMount);
4511
+ }
3873
4512
  const lang = processedLanguage(language) || language;
3874
4513
  this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
3875
4514
  this.modifiedModel = monaco_shim_exports.editor.createModel(modifiedCode, lang);
@@ -3878,7 +4517,7 @@ var DiffEditorManager = class DiffEditorManager {
3878
4517
  const hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption();
3879
4518
  this.diffHideUnchangedRegionsResolved = hideUnchangedRegions;
3880
4519
  this.diffHideUnchangedRegionsDeferred = false;
3881
- this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(container, {
4520
+ this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(editorMount, {
3882
4521
  automaticLayout: true,
3883
4522
  scrollBeyondLastLine: false,
3884
4523
  renderSideBySide: true,
@@ -3892,6 +4531,7 @@ var DiffEditorManager = class DiffEditorManager {
3892
4531
  ...this.options.scrollbar || {}
3893
4532
  },
3894
4533
  ...this.options,
4534
+ glyphMargin: this.resolveDiffGlyphMarginOption(hideUnchangedRegions),
3895
4535
  hideUnchangedRegions
3896
4536
  });
3897
4537
  monaco_shim_exports.editor.setTheme(currentTheme);
@@ -3928,8 +4568,10 @@ var DiffEditorManager = class DiffEditorManager {
3928
4568
  autoScrollInitial: this.autoScrollInitial,
3929
4569
  diffAutoScroll: this.diffAutoScroll
3930
4570
  });
3931
- const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
3932
- container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
4571
+ const minVisibleHeight = this.shouldDeferTailAppendForInlineStreaming() ? 0 : Math.min(120, this.maxHeightValue);
4572
+ if (minVisibleHeight > 0) container.style.minHeight = `${minVisibleHeight}px`;
4573
+ else if (typeof container.style.removeProperty === "function") container.style.removeProperty("min-height");
4574
+ else delete container.style.minHeight;
3933
4575
  if (this.diffHeightManager) {
3934
4576
  this.diffHeightManager.dispose();
3935
4577
  this.diffHeightManager = null;
@@ -3948,6 +4590,7 @@ var DiffEditorManager = class DiffEditorManager {
3948
4590
  this.diffComputedVersions = null;
3949
4591
  this.diffPresentationDisposables.push(this.diffEditorView.onDidUpdateDiff(() => {
3950
4592
  this.diffComputedVersions = this.captureCurrentDiffVersions();
4593
+ this.syncDiffEditorLayoutToContainer();
3951
4594
  this.scheduleSyncDiffPresentationDecorations();
3952
4595
  }));
3953
4596
  this.diffPresentationDisposables.push(oEditor.onDidChangeModelContent(() => {
@@ -3956,21 +4599,51 @@ var DiffEditorManager = class DiffEditorManager {
3956
4599
  this.diffPresentationDisposables.push(mEditor.onDidChangeModelContent(() => {
3957
4600
  this.scheduleSyncDiffPresentationDecorations();
3958
4601
  }));
4602
+ const originalLayoutDisposable = (_oEditor$onDidLayoutC = oEditor.onDidLayoutChange) === null || _oEditor$onDidLayoutC === void 0 ? void 0 : _oEditor$onDidLayoutC.call(oEditor, () => {
4603
+ this.scheduleSyncDiffPresentationDecorations();
4604
+ });
4605
+ if (originalLayoutDisposable) this.diffPresentationDisposables.push(originalLayoutDisposable);
4606
+ const modifiedLayoutDisposable = (_mEditor$onDidLayoutC = mEditor.onDidLayoutChange) === null || _mEditor$onDidLayoutC === void 0 ? void 0 : _mEditor$onDidLayoutC.call(mEditor, () => {
4607
+ this.scheduleSyncDiffPresentationDecorations();
4608
+ });
4609
+ if (modifiedLayoutDisposable) this.diffPresentationDisposables.push(modifiedLayoutDisposable);
4610
+ if (typeof MutationObserver !== "undefined" && this.lastContainer) {
4611
+ this.diffPresentationObserver = new MutationObserver((mutations) => {
4612
+ const shouldSync = mutations.some((mutation) => {
4613
+ if (mutation.type !== "childList") return false;
4614
+ const nodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes));
4615
+ return nodes.some((node) => {
4616
+ if (!(node instanceof HTMLElement)) return false;
4617
+ return node.matches(".line-delete, .inline-deleted-text, .inline-deleted-margin-view-zone") || !!node.querySelector(".line-delete, .inline-deleted-text, .inline-deleted-margin-view-zone") || !!node.closest(".editor.modified .view-zones, .editor.modified .margin-view-zones");
4618
+ });
4619
+ });
4620
+ if (shouldSync) this.scheduleSyncDiffPresentationDecorations();
4621
+ });
4622
+ this.diffPresentationObserver.observe(this.lastContainer, {
4623
+ childList: true,
4624
+ subtree: true
4625
+ });
4626
+ }
3959
4627
  (_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
3960
4628
  this._hasScrollBar = false;
3961
4629
  this.rafScheduler.schedule("content-size-change-diff", () => {
3962
- var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
4630
+ var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag5, _this$diffHeightManag6;
3963
4631
  this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
3964
4632
  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;
3965
4633
  this.cachedComputedHeightDiff = this.computedHeight();
3966
- if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
3967
- (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3968
- const computed$1 = this.computedHeight();
4634
+ if (this.lastContainer) {
4635
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4636
+ if (this.cachedComputedHeightDiff > applied + 1 && (this.cachedComputedHeightDiff < this.maxHeightValue - 1 || !this.shouldAvoidOptimisticMaxHeightWriteDiff())) this.lastContainer.style.height = `${this.cachedComputedHeightDiff}px`;
4637
+ }
4638
+ if ((_this$diffHeightManag5 = this.diffHeightManager) === null || _this$diffHeightManag5 === void 0 ? void 0 : _this$diffHeightManag5.isSuppressed()) return;
4639
+ (_this$diffHeightManag6 = this.diffHeightManager) === null || _this$diffHeightManag6 === void 0 || _this$diffHeightManag6.update();
4640
+ this.scheduleSyncDiffEditorLayoutToContainer();
4641
+ const computed$1 = this.cachedComputedHeightDiff;
3969
4642
  if (this.lastContainer) {
3970
4643
  this.lastContainer.style.overflow = "hidden";
3971
4644
  if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
3972
- var _this$modifiedModel3;
3973
- this.maybeScrollDiffToBottom((_this$modifiedModel3 = this.modifiedModel) === null || _this$modifiedModel3 === void 0 ? void 0 : _this$modifiedModel3.getLineCount());
4645
+ var _this$modifiedModel4;
4646
+ this.maybeScrollDiffToBottom((_this$modifiedModel4 = this.modifiedModel) === null || _this$modifiedModel4 === void 0 ? void 0 : _this$modifiedModel4.getLineCount());
3974
4647
  }
3975
4648
  }
3976
4649
  });
@@ -3978,23 +4651,29 @@ var DiffEditorManager = class DiffEditorManager {
3978
4651
  (_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
3979
4652
  this._hasScrollBar = false;
3980
4653
  this.rafScheduler.schedule("content-size-change-diff", () => {
3981
- var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag5, _this$diffHeightManag6;
4654
+ var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag7, _this$diffHeightManag8;
3982
4655
  this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
3983
4656
  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;
3984
4657
  this.cachedComputedHeightDiff = this.computedHeight();
3985
- if ((_this$diffHeightManag5 = this.diffHeightManager) === null || _this$diffHeightManag5 === void 0 ? void 0 : _this$diffHeightManag5.isSuppressed()) return;
3986
- (_this$diffHeightManag6 = this.diffHeightManager) === null || _this$diffHeightManag6 === void 0 || _this$diffHeightManag6.update();
3987
- const computed$1 = this.computedHeight();
4658
+ if (this.lastContainer) {
4659
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4660
+ if (this.cachedComputedHeightDiff > applied + 1 && (this.cachedComputedHeightDiff < this.maxHeightValue - 1 || !this.shouldAvoidOptimisticMaxHeightWriteDiff())) this.lastContainer.style.height = `${this.cachedComputedHeightDiff}px`;
4661
+ }
4662
+ if ((_this$diffHeightManag7 = this.diffHeightManager) === null || _this$diffHeightManag7 === void 0 ? void 0 : _this$diffHeightManag7.isSuppressed()) return;
4663
+ (_this$diffHeightManag8 = this.diffHeightManager) === null || _this$diffHeightManag8 === void 0 || _this$diffHeightManag8.update();
4664
+ this.scheduleSyncDiffEditorLayoutToContainer();
4665
+ const computed$1 = this.cachedComputedHeightDiff;
3988
4666
  if (this.lastContainer) {
3989
4667
  this.lastContainer.style.overflow = "hidden";
3990
4668
  if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
3991
- var _this$modifiedModel4;
3992
- this.maybeScrollDiffToBottom((_this$modifiedModel4 = this.modifiedModel) === null || _this$modifiedModel4 === void 0 ? void 0 : _this$modifiedModel4.getLineCount());
4669
+ var _this$modifiedModel5;
4670
+ this.maybeScrollDiffToBottom((_this$modifiedModel5 = this.modifiedModel) === null || _this$modifiedModel5 === void 0 ? void 0 : _this$modifiedModel5.getLineCount());
3993
4671
  }
3994
4672
  }
3995
4673
  });
3996
4674
  });
3997
4675
  mEditor.onDidChangeModelContent(() => {
4676
+ if (this.programmaticModifiedContentChangeDepth > 0) return;
3998
4677
  this.lastKnownModifiedDirty = true;
3999
4678
  this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
4000
4679
  });
@@ -4025,13 +4704,14 @@ var DiffEditorManager = class DiffEditorManager {
4025
4704
  const modifiedTailAppend = modifiedCode !== prevM && modifiedCode.startsWith(prevM) && prevM.length < modifiedCode.length;
4026
4705
  const hasContentChange = originalCode !== prevO || modifiedCode !== prevM;
4027
4706
  if (originalCode !== prevO || modifiedCode !== prevM) this.markDiffStreamingActivity();
4707
+ const deferTailAppendForInline = this.shouldDeferTailAppendForInlineStreaming();
4028
4708
  let didImmediate = false;
4029
- if (originalTailAppend) {
4709
+ if (originalTailAppend && !deferTailAppendForInline) {
4030
4710
  this.appendOriginal(originalCode.slice(prevO.length));
4031
4711
  this.lastKnownOriginalCode = originalCode;
4032
4712
  didImmediate = true;
4033
4713
  }
4034
- if (modifiedTailAppend) {
4714
+ if (modifiedTailAppend && !deferTailAppendForInline) {
4035
4715
  this.appendModified(modifiedCode.slice(prevM.length));
4036
4716
  this.lastKnownModifiedCode = modifiedCode;
4037
4717
  didImmediate = true;
@@ -4045,6 +4725,16 @@ var DiffEditorManager = class DiffEditorManager {
4045
4725
  this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
4046
4726
  } else if (didImmediate) {}
4047
4727
  }
4728
+ shouldDeferTailAppendForInlineStreaming() {
4729
+ var _this$lastContainer11, _this$lastContainer12, _this$lastContainer13;
4730
+ const renderSideBySide = this.options.renderSideBySide ?? true;
4731
+ if (renderSideBySide === false) return true;
4732
+ const useInlineViewWhenSpaceIsLimited = this.options.useInlineViewWhenSpaceIsLimited ?? true;
4733
+ if (!useInlineViewWhenSpaceIsLimited) return false;
4734
+ const breakpoint = this.options.renderSideBySideInlineBreakpoint ?? 900;
4735
+ const width = ((_this$lastContainer11 = this.lastContainer) === null || _this$lastContainer11 === void 0 || (_this$lastContainer12 = _this$lastContainer11.getBoundingClientRect) === null || _this$lastContainer12 === void 0 ? void 0 : _this$lastContainer12.call(_this$lastContainer11).width) ?? ((_this$lastContainer13 = this.lastContainer) === null || _this$lastContainer13 === void 0 ? void 0 : _this$lastContainer13.clientWidth) ?? 0;
4736
+ return width > 0 && width <= breakpoint;
4737
+ }
4048
4738
  updateOriginal(newCode, codeLanguage) {
4049
4739
  if (!this.diffEditorView || !this.originalModel) return;
4050
4740
  if (codeLanguage) {
@@ -4082,10 +4772,11 @@ var DiffEditorManager = class DiffEditorManager {
4082
4772
  this.applyMinimalEditToModel(this.modifiedModel, prevAfterFlush, newCode);
4083
4773
  const newLine = this.modifiedModel.getLineCount();
4084
4774
  if (newLine !== prevLine) {
4775
+ this.eagerlyGrowDiffContainerHeight();
4085
4776
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4086
4777
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4087
4778
  const computed$1 = this.computedHeight();
4088
- if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) {
4779
+ if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4089
4780
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4090
4781
  this.lastContainer.style.overflow = "hidden";
4091
4782
  }
@@ -4126,7 +4817,7 @@ var DiffEditorManager = class DiffEditorManager {
4126
4817
  if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
4127
4818
  }
4128
4819
  async setDiffModels(models, options = {}) {
4129
- var _this$originalModel2, _this$modifiedModel5, _this$diffEditorView$6, _this$diffEditorView$7, _this$diffEditorView$8, _this$diffEditorView$9;
4820
+ var _this$originalModel3, _this$modifiedModel6, _this$diffEditorView$4, _this$diffEditorView$5, _this$diffEditorView$6, _this$diffEditorView$7;
4130
4821
  if (!this.diffEditorView) return;
4131
4822
  const transitionRequestId = ++this.diffModelTransitionRequestId;
4132
4823
  this.preserveNativeDiffDecorationsOnStaleAppend = false;
@@ -4134,8 +4825,8 @@ var DiffEditorManager = class DiffEditorManager {
4134
4825
  const nextOriginal = models.original;
4135
4826
  const nextModified = models.modified;
4136
4827
  this.applyDiffModelLanguage(models, options.codeLanguage);
4137
- const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getValue()) ?? null;
4138
- const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$modifiedModel5 = this.modifiedModel) === null || _this$modifiedModel5 === void 0 ? void 0 : _this$modifiedModel5.getValue()) ?? null;
4828
+ const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel3 = this.originalModel) === null || _this$originalModel3 === void 0 ? void 0 : _this$originalModel3.getValue()) ?? null;
4829
+ const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$modifiedModel6 = this.modifiedModel) === null || _this$modifiedModel6 === void 0 ? void 0 : _this$modifiedModel6.getValue()) ?? null;
4139
4830
  const nextOriginalValue = nextOriginal.getValue();
4140
4831
  const nextModifiedValue = nextModified.getValue();
4141
4832
  const sameContent = currentOriginalValue === nextOriginalValue && currentModifiedValue === nextModifiedValue;
@@ -4184,14 +4875,15 @@ var DiffEditorManager = class DiffEditorManager {
4184
4875
  const currentOriginal = this.originalModel;
4185
4876
  const currentModified = this.modifiedModel;
4186
4877
  const shouldRestorePersistedUnchangedState = preserveViewState && !sameContent;
4878
+ const shouldRestoreSavedModelState = options.preserveModelState ?? true;
4187
4879
  const preservedScrollPosition = preserveViewState ? this.captureDiffScrollPosition() : null;
4188
4880
  const preservedViewportAnchor = preserveViewState && sameContent ? this.captureModifiedViewportAnchor() : null;
4189
- const viewState = preserveViewState ? this.diffEditorView.saveViewState() : null;
4881
+ const viewState = preserveViewState && shouldRestoreSavedModelState ? this.diffEditorView.saveViewState() : null;
4190
4882
  this.queuePendingDiffScrollRestore(preservedScrollPosition, shouldRestorePersistedUnchangedState ? 2 : 0);
4191
4883
  if (shouldRestorePersistedUnchangedState) this.capturePersistedDiffUnchangedState();
4192
4884
  const applyModelSwap = () => {
4193
- var _this$diffEditorView32;
4194
- (_this$diffEditorView32 = this.diffEditorView) === null || _this$diffEditorView32 === void 0 || _this$diffEditorView32.setModel(nextModelTarget);
4885
+ var _this$diffEditorView23;
4886
+ (_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || _this$diffEditorView23.setModel(nextModelTarget);
4195
4887
  };
4196
4888
  if (preserveViewState) this.withLockedDiffScrollPosition(applyModelSwap);
4197
4889
  else applyModelSwap();
@@ -4206,8 +4898,8 @@ var DiffEditorManager = class DiffEditorManager {
4206
4898
  this.lastKnownModifiedLineCount = nextModified.getLineCount();
4207
4899
  this.lastKnownModifiedDirty = false;
4208
4900
  this._hasScrollBar = false;
4209
- this.cachedScrollHeightDiff = ((_this$diffEditorView$6 = (_this$diffEditorView$7 = this.diffEditorView.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView$6 === void 0 ? void 0 : _this$diffEditorView$6.call(_this$diffEditorView$7)) ?? null;
4210
- this.cachedLineHeightDiff = ((_this$diffEditorView$8 = (_this$diffEditorView$9 = this.diffEditorView.getModifiedEditor()).getOption) === null || _this$diffEditorView$8 === void 0 ? void 0 : _this$diffEditorView$8.call(_this$diffEditorView$9, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
4901
+ this.cachedScrollHeightDiff = ((_this$diffEditorView$4 = (_this$diffEditorView$5 = this.diffEditorView.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView$4 === void 0 ? void 0 : _this$diffEditorView$4.call(_this$diffEditorView$5)) ?? null;
4902
+ this.cachedLineHeightDiff = ((_this$diffEditorView$6 = (_this$diffEditorView$7 = this.diffEditorView.getModifiedEditor()).getOption) === null || _this$diffEditorView$6 === void 0 ? void 0 : _this$diffEditorView$6.call(_this$diffEditorView$7, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
4211
4903
  this.cachedComputedHeightDiff = this.computedHeight();
4212
4904
  this.diffHunkLineChanges = this.getEffectiveLineChanges();
4213
4905
  this.hideDiffHunkActions();
@@ -4270,6 +4962,7 @@ var DiffEditorManager = class DiffEditorManager {
4270
4962
  this.revealTicketDiff = 0;
4271
4963
  this.lastRevealLineDiff = null;
4272
4964
  this.diffPersistedUnchangedModelState = null;
4965
+ this.diffPreviousUnchangedModelState = null;
4273
4966
  this.pendingDiffScrollRestorePosition = null;
4274
4967
  this.pendingDiffScrollRestoreBudget = 0;
4275
4968
  this.diffHideUnchangedRegionsResolved = null;
@@ -4297,7 +4990,11 @@ var DiffEditorManager = class DiffEditorManager {
4297
4990
  this.revealTicketDiff = 0;
4298
4991
  this.lastRevealLineDiff = null;
4299
4992
  this.diffPersistedUnchangedModelState = null;
4993
+ this.diffPreviousUnchangedModelState = null;
4300
4994
  this.diffHideUnchangedRegionsDeferred = false;
4995
+ this.clearInlineDiffStreamingPresentationIdleTimer();
4996
+ this.inlineDiffStreamingPresentationActive = false;
4997
+ this.resetInlineDiffStreamingHeightFloor();
4301
4998
  }
4302
4999
  syncLastKnownModified() {
4303
5000
  if (!this.diffEditorView || !this.lastKnownModifiedDirty) return;
@@ -4353,10 +5050,11 @@ var DiffEditorManager = class DiffEditorManager {
4353
5050
  this.lastKnownModifiedCode = modified;
4354
5051
  const newMLineCount = m.getLineCount();
4355
5052
  if (newMLineCount !== prevMLineCount) {
5053
+ this.eagerlyGrowDiffContainerHeight();
4356
5054
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4357
5055
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4358
5056
  const computed$1 = this.computedHeight();
4359
- if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) {
5057
+ if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4360
5058
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4361
5059
  this.lastContainer.style.overflow = "hidden";
4362
5060
  }
@@ -4437,15 +5135,18 @@ var DiffEditorManager = class DiffEditorManager {
4437
5135
  const lastColumn$1 = model.getLineMaxColumn(prevLine);
4438
5136
  const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
4439
5137
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4440
- model.applyEdits([{
4441
- range: range$1,
4442
- text: part,
4443
- forceMoveMarkers: true
4444
- }]);
5138
+ this.runAsProgrammaticModifiedContentChange(() => {
5139
+ model.applyEdits([{
5140
+ range: range$1,
5141
+ text: part,
5142
+ forceMoveMarkers: true
5143
+ }]);
5144
+ });
4445
5145
  this.lastKnownModifiedCode = model.getValue();
4446
5146
  const newLine$1 = model.getLineCount();
4447
5147
  this.lastKnownModifiedLineCount = newLine$1;
4448
5148
  await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
5149
+ this.eagerlyGrowDiffContainerHeight();
4449
5150
  const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
4450
5151
  log("diff", "flushAppendBufferDiff chunk metrics", {
4451
5152
  idx,
@@ -4455,7 +5156,7 @@ var DiffEditorManager = class DiffEditorManager {
4455
5156
  });
4456
5157
  if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4457
5158
  const computed$2 = this.computedHeight();
4458
- if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
5159
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4459
5160
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4460
5161
  this.lastContainer.style.overflow = "hidden";
4461
5162
  }
@@ -4476,33 +5177,38 @@ var DiffEditorManager = class DiffEditorManager {
4476
5177
  const lastColumn = model.getLineMaxColumn(prevLine);
4477
5178
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
4478
5179
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4479
- model.applyEdits([{
4480
- range,
4481
- text,
4482
- forceMoveMarkers: true
4483
- }]);
5180
+ this.runAsProgrammaticModifiedContentChange(() => {
5181
+ model.applyEdits([{
5182
+ range,
5183
+ text,
5184
+ forceMoveMarkers: true
5185
+ }]);
5186
+ });
4484
5187
  this.lastKnownModifiedCode = model.getValue();
4485
5188
  const newLine = model.getLineCount();
4486
5189
  this.lastKnownModifiedLineCount = newLine;
5190
+ this.eagerlyGrowDiffContainerHeight();
4487
5191
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4488
5192
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4489
5193
  const computed$1 = this.computedHeight();
4490
- if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
5194
+ if (computed$1 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) this.lastContainer.style.height = `${this.maxHeightValue}px`;
4491
5195
  if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
4492
5196
  else this.maybeScrollDiffToBottom(newLine, prevLine);
4493
5197
  if (suppressedByFlush) watcherApi.setSuppressed(false);
4494
5198
  try {
4495
- var _this$diffEditorView33, _this$diffEditorView34, _this$diffEditorView35;
4496
- this.lastScrollTopDiff = ((_this$diffEditorView33 = this.diffEditorView) === null || _this$diffEditorView33 === void 0 || (_this$diffEditorView35 = (_this$diffEditorView34 = _this$diffEditorView33.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView35 === void 0 ? void 0 : _this$diffEditorView35.call(_this$diffEditorView34)) ?? this.lastScrollTopDiff;
5199
+ var _this$diffEditorView24, _this$diffEditorView25, _this$diffEditorView26;
5200
+ this.lastScrollTopDiff = ((_this$diffEditorView24 = this.diffEditorView) === null || _this$diffEditorView24 === void 0 || (_this$diffEditorView26 = (_this$diffEditorView25 = _this$diffEditorView24.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView26 === void 0 ? void 0 : _this$diffEditorView26.call(_this$diffEditorView25)) ?? this.lastScrollTopDiff;
4497
5201
  } catch {}
4498
5202
  }
4499
5203
  applyMinimalEditToModel(model, prev, next) {
4500
- const maxChars = minimalEditMaxChars;
4501
- const ratio = minimalEditMaxChangeRatio;
5204
+ const maxChars = this.minimalEditMaxCharsValue;
5205
+ const ratio = this.minimalEditMaxChangeRatioValue;
4502
5206
  const maxLen = Math.max(prev.length, next.length);
4503
5207
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
4504
5208
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
4505
- model.setValue(next);
5209
+ this.applyModelEdit(model, () => {
5210
+ model.setValue(next);
5211
+ });
4506
5212
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
4507
5213
  return;
4508
5214
  }
@@ -4512,11 +5218,13 @@ var DiffEditorManager = class DiffEditorManager {
4512
5218
  const rangeStart = model.getPositionAt(start);
4513
5219
  const rangeEnd = model.getPositionAt(endPrevIncl + 1);
4514
5220
  const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
4515
- model.applyEdits([{
4516
- range,
4517
- text: replaceText,
4518
- forceMoveMarkers: true
4519
- }]);
5221
+ this.applyModelEdit(model, () => {
5222
+ model.applyEdits([{
5223
+ range,
5224
+ text: replaceText,
5225
+ forceMoveMarkers: true
5226
+ }]);
5227
+ });
4520
5228
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
4521
5229
  }
4522
5230
  appendToModel(model, appendText) {
@@ -4524,13 +5232,30 @@ var DiffEditorManager = class DiffEditorManager {
4524
5232
  const lastLine = model.getLineCount();
4525
5233
  const lastColumn = model.getLineMaxColumn(lastLine);
4526
5234
  const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
4527
- model.applyEdits([{
4528
- range,
4529
- text: appendText,
4530
- forceMoveMarkers: true
4531
- }]);
5235
+ this.applyModelEdit(model, () => {
5236
+ model.applyEdits([{
5237
+ range,
5238
+ text: appendText,
5239
+ forceMoveMarkers: true
5240
+ }]);
5241
+ });
4532
5242
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
4533
5243
  }
5244
+ applyModelEdit(model, fn) {
5245
+ if (model === this.modifiedModel) {
5246
+ this.runAsProgrammaticModifiedContentChange(fn);
5247
+ return;
5248
+ }
5249
+ fn();
5250
+ }
5251
+ runAsProgrammaticModifiedContentChange(fn) {
5252
+ this.programmaticModifiedContentChangeDepth += 1;
5253
+ try {
5254
+ fn();
5255
+ } finally {
5256
+ this.programmaticModifiedContentChangeDepth -= 1;
5257
+ }
5258
+ }
4534
5259
  };
4535
5260
 
4536
5261
  //#endregion
@@ -4542,6 +5267,8 @@ var EditorManager = class {
4542
5267
  pendingUpdate = null;
4543
5268
  _hasScrollBar = false;
4544
5269
  updateThrottleMs = 50;
5270
+ minimalEditMaxCharsValue = minimalEditMaxChars;
5271
+ minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
4545
5272
  lastUpdateFlushTime = 0;
4546
5273
  updateThrottleTimer = null;
4547
5274
  shouldAutoScroll = true;
@@ -4597,6 +5324,8 @@ var EditorManager = class {
4597
5324
  this.revealDebounceMsOption = revealDebounceMsOption;
4598
5325
  this.updateThrottleMsOption = updateThrottleMsOption;
4599
5326
  this.updateThrottleMs = this.updateThrottleMsOption ?? this.options.updateThrottleMs ?? 50;
5327
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
5328
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
4600
5329
  }
4601
5330
  cancelRafs() {
4602
5331
  this.rafScheduler.cancel("update");
@@ -4731,7 +5460,7 @@ var EditorManager = class {
4731
5460
  }
4732
5461
  performReveal(line, ticket) {
4733
5462
  this.rafScheduler.schedule("reveal", () => {
4734
- var _editor;
5463
+ var _editor$1;
4735
5464
  if (ticket !== this.revealTicket) {
4736
5465
  this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
4737
5466
  return;
@@ -4739,8 +5468,8 @@ var EditorManager = class {
4739
5468
  this.dlog("performReveal executing, ticket=", ticket, "line=", line);
4740
5469
  const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
4741
5470
  this.dlog("performReveal strategy=", strategy);
4742
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
4743
- const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
5471
+ const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
5472
+ const smooth = ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
4744
5473
  try {
4745
5474
  if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
4746
5475
  else this.editorView.revealLine(line);
@@ -4764,8 +5493,8 @@ var EditorManager = class {
4764
5493
  this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
4765
5494
  return;
4766
5495
  }
4767
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
4768
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
5496
+ const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
5497
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
4769
5498
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
4770
5499
  else this.editorView.revealLine(line);
4771
5500
  } catch {}
@@ -4777,8 +5506,8 @@ var EditorManager = class {
4777
5506
  try {
4778
5507
  var _editor3;
4779
5508
  if (!this.editorView) return;
4780
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
4781
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
5509
+ const ScrollType$1 = ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
5510
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
4782
5511
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
4783
5512
  else this.editorView.revealLine(line);
4784
5513
  } catch {}
@@ -5046,7 +5775,6 @@ var EditorManager = class {
5046
5775
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
5047
5776
  const suffix = newCode.slice(prevCode.length);
5048
5777
  if (suffix) this.appendCode(suffix, codeLanguage);
5049
- this.lastKnownCode = newCode;
5050
5778
  return;
5051
5779
  }
5052
5780
  const prevLineCount = model.getLineCount();
@@ -5079,8 +5807,8 @@ var EditorManager = class {
5079
5807
  if (!this.editorView) return;
5080
5808
  const model = this.editorView.getModel();
5081
5809
  if (!model) return;
5082
- const maxChars = minimalEditMaxChars;
5083
- const ratio = minimalEditMaxChangeRatio;
5810
+ const maxChars = this.minimalEditMaxCharsValue;
5811
+ const ratio = this.minimalEditMaxChangeRatioValue;
5084
5812
  const maxLen = Math.max(prev.length, next.length);
5085
5813
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
5086
5814
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
@@ -5164,6 +5892,10 @@ var EditorManager = class {
5164
5892
  getEditorView() {
5165
5893
  return this.editorView;
5166
5894
  }
5895
+ getCode() {
5896
+ var _this$editorView9;
5897
+ return ((_this$editorView9 = this.editorView) === null || _this$editorView9 === void 0 || (_this$editorView9 = _this$editorView9.getModel()) === null || _this$editorView9 === void 0 ? void 0 : _this$editorView9.getValue()) ?? null;
5898
+ }
5167
5899
  setUpdateThrottleMs(ms) {
5168
5900
  this.updateThrottleMs = ms;
5169
5901
  if (!this.updateThrottleMs && this.updateThrottleTimer != null) {
@@ -5346,6 +6078,14 @@ async function ensureMonacoHighlighter(themes, languages$1) {
5346
6078
  */
5347
6079
  function clearHighlighterCache() {
5348
6080
  highlighterCache.clear();
6081
+ monacoHighlighterPromise = null;
6082
+ lastPatchedHighlighter = null;
6083
+ lastPatchedLanguages = /* @__PURE__ */ new Set();
6084
+ monacoThemeByKey.clear();
6085
+ monacoLanguageSet.clear();
6086
+ themeRegisterPromise = null;
6087
+ languagesRegistered = false;
6088
+ currentLanguages = [];
5349
6089
  }
5350
6090
  function serializeThemes(themes) {
5351
6091
  return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
@@ -5585,15 +6325,13 @@ let globalAppliedThemeName = null;
5585
6325
  function useMonaco(monacoOptions = {}) {
5586
6326
  var _monacoOptions$themes;
5587
6327
  const disposals = [];
5588
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.forEach((d) => d.dispose());
5589
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
6328
+ const pendingCreateDisposables = /* @__PURE__ */ new Map();
5590
6329
  let editorView = null;
5591
6330
  let editorMgr = null;
5592
6331
  let diffEditorView = null;
5593
6332
  let diffMgr = null;
5594
6333
  let originalModel = null;
5595
6334
  let modifiedModel = null;
5596
- let _hasScrollBar = false;
5597
6335
  const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
5598
6336
  if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
5599
6337
  const languages$1 = monacoOptions.languages ?? defaultLanguages;
@@ -5614,22 +6352,12 @@ function useMonaco(monacoOptions = {}) {
5614
6352
  };
5615
6353
  const maxHeightValue = getMaxHeightValue();
5616
6354
  const maxHeightCSS = getMaxHeightCSS();
5617
- let lastContainer = null;
5618
- let lastKnownCode = null;
5619
- const minimalEditMaxCharsLocal = monacoOptions.minimalEditMaxChars ?? minimalEditMaxChars;
5620
- const minimalEditMaxChangeRatioLocal = monacoOptions.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
5621
- let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
5622
- let lastFlushTime = 0;
5623
- let updateThrottleTimer = null;
5624
- let pendingUpdate = null;
5625
- let shouldAutoScroll = true;
5626
- const cachedComputedHeight = null;
5627
- const appendBuffer = [];
5628
- let appendBufferScheduled = false;
6355
+ let createRequestSeq = 0;
6356
+ let activeCreateRequestId = null;
6357
+ let activeCreateKind = null;
6358
+ let queuedEditorUpdateDuringCreate = null;
5629
6359
  const currentTheme = computed(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
5630
6360
  let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
5631
- let themeWatcher = null;
5632
- const rafScheduler = createRafScheduler();
5633
6361
  async function tryLoadAndSetShikiTheme(highlighter, themeName) {
5634
6362
  if (!highlighter || typeof highlighter.setTheme !== "function") return;
5635
6363
  try {
@@ -5700,326 +6428,206 @@ function useMonaco(monacoOptions = {}) {
5700
6428
  const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
5701
6429
  await registerMonacoThemes(list, languages$1);
5702
6430
  }
5703
- function hasVerticalScrollbar() {
5704
- if (!editorView) return false;
5705
- if (_hasScrollBar) return true;
5706
- const ch = cachedComputedHeight ?? computedHeight(editorView);
5707
- return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
5708
- }
5709
- let revealDebounceId = null;
5710
- const revealDebounceMs = 75;
5711
- function maybeScrollToBottom(targetLine) {
5712
- if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
5713
- const model = editorView.getModel();
5714
- const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
5715
- if (revealDebounceId != null) {
5716
- clearTimeout(revealDebounceId);
5717
- revealDebounceId = null;
5718
- }
5719
- revealDebounceId = setTimeout(() => {
5720
- revealDebounceId = null;
5721
- rafScheduler.schedule("reveal", () => {
5722
- try {
5723
- var _editor;
5724
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
5725
- if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
5726
- else editorView.revealLineInCenterIfOutsideViewport(line);
5727
- } catch {}
5728
- });
5729
- }, revealDebounceMs);
5730
- }
6431
+ function resolveRequestedThemeName() {
6432
+ return requestedThemeName ?? globalRequestedThemeName ?? monacoOptions.theme ?? currentTheme.value;
5731
6433
  }
5732
- async function createEditor(container, code, language) {
5733
- cleanupEditor();
5734
- lastContainer = container;
5735
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
5736
- disposals.forEach((d) => d.dispose());
5737
- disposals.length = 0;
5738
- }
5739
- if (monacoOptions.onBeforeCreate) {
5740
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
5741
- if (ds) disposals.push(...ds);
5742
- }
5743
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
5744
- await ensureThemeRegistered(initialThemeName);
5745
- editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, updateThrottleMs);
5746
- editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
5747
- if (pendingUpdate && editorMgr) {
5748
- const { code: queuedCode, lang: queuedLang } = pendingUpdate;
5749
- pendingUpdate = null;
5750
- editorMgr.updateCode(queuedCode, queuedLang);
5751
- }
5752
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
5753
- if (editorView) lastKnownCode = editorView.getValue();
5754
- return editorView;
5755
- }
5756
- function computedHeight(editorView$1) {
5757
- var _getModel;
5758
- const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
5759
- const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
5760
- const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
5761
- return height;
6434
+ function commitAppliedTheme(themeName) {
6435
+ requestedThemeName = themeName;
6436
+ globalRequestedThemeName = themeName;
6437
+ globalAppliedThemeName = themeName;
6438
+ monacoOptions.theme = themeName;
5762
6439
  }
5763
- async function createDiffEditor(container, originalCode, modifiedCode, language) {
5764
- cleanupEditor();
5765
- lastContainer = container;
5766
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
5767
- disposals.forEach((d) => d.dispose());
5768
- disposals.length = 0;
5769
- }
5770
- if (monacoOptions.onBeforeCreate) {
5771
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
5772
- if (ds) disposals.push(...ds);
5773
- }
5774
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
5775
- await ensureThemeRegistered(initialThemeName);
6440
+ async function notifyThemeApplied(themeName) {
6441
+ if (typeof monacoOptions.onThemeChange !== "function") return;
5776
6442
  try {
5777
- monaco_shim_exports.editor.setTheme(initialThemeName);
6443
+ await monacoOptions.onThemeChange(themeName);
6444
+ } catch (err) {
6445
+ console.warn("onThemeChange callback threw an error:", err);
6446
+ }
6447
+ }
6448
+ function disposeDisposables(items) {
6449
+ if (!(items === null || items === void 0 ? void 0 : items.length)) return;
6450
+ for (const item of items) try {
6451
+ item.dispose();
5778
6452
  } catch {}
5779
- diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
5780
- diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
5781
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
5782
- const models = diffMgr.getDiffModels();
5783
- originalModel = models.original;
5784
- modifiedModel = models.modified;
5785
- return diffEditorView;
5786
- }
5787
- function clearFallbackAsyncWork() {
5788
- rafScheduler.cancel("update");
5789
- rafScheduler.cancel("append");
5790
- rafScheduler.cancel("reveal");
5791
- pendingUpdate = null;
5792
- appendBufferScheduled = false;
5793
- appendBuffer.length = 0;
5794
- if (revealDebounceId != null) {
5795
- clearTimeout(revealDebounceId);
5796
- revealDebounceId = null;
5797
- }
5798
- if (updateThrottleTimer != null) {
5799
- clearTimeout(updateThrottleTimer);
5800
- updateThrottleTimer = null;
5801
- }
5802
- lastFlushTime = 0;
5803
6453
  }
5804
- function cleanupEditor() {
6454
+ function takePendingCreateDisposables(requestId) {
6455
+ const items = pendingCreateDisposables.get(requestId) ?? [];
6456
+ pendingCreateDisposables.delete(requestId);
6457
+ return items;
6458
+ }
6459
+ function disposeAllPendingCreateDisposables() {
6460
+ for (const requestId of Array.from(pendingCreateDisposables.keys())) disposeDisposables(takePendingCreateDisposables(requestId));
6461
+ }
6462
+ function cleanupInstances() {
5805
6463
  if (editorMgr) {
5806
6464
  editorMgr.cleanup();
5807
6465
  editorMgr = null;
5808
- }
6466
+ } else if (editorView) try {
6467
+ editorView.dispose();
6468
+ } catch {}
5809
6469
  if (diffMgr) {
5810
6470
  diffMgr.cleanup();
5811
6471
  diffMgr = null;
6472
+ } else {
6473
+ try {
6474
+ diffEditorView === null || diffEditorView === void 0 || diffEditorView.dispose();
6475
+ } catch {}
6476
+ try {
6477
+ originalModel === null || originalModel === void 0 || originalModel.dispose();
6478
+ } catch {}
6479
+ try {
6480
+ modifiedModel === null || modifiedModel === void 0 || modifiedModel.dispose();
6481
+ } catch {}
5812
6482
  }
5813
- clearFallbackAsyncWork();
5814
- if (!editorMgr && editorView) {
5815
- editorView.dispose();
5816
- editorView = null;
5817
- }
5818
- lastKnownCode = null;
5819
- if (lastContainer) {
5820
- lastContainer.innerHTML = "";
5821
- lastContainer = null;
5822
- }
5823
- if (themeWatcher) {
5824
- themeWatcher();
5825
- themeWatcher = null;
5826
- }
6483
+ editorView = null;
5827
6484
  diffEditorView = null;
5828
6485
  originalModel = null;
5829
6486
  modifiedModel = null;
5830
6487
  }
5831
- function appendCode(appendText, codeLanguage) {
5832
- if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
5833
- else {
5834
- if (!editorView) return;
5835
- const model = editorView.getModel();
5836
- if (!model) return;
5837
- const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
5838
- if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
5839
- if (appendText && lastKnownCode != null) lastKnownCode = lastKnownCode + appendText;
5840
- if (appendText) {
5841
- appendBuffer.push(appendText);
5842
- if (!appendBufferScheduled) {
5843
- appendBufferScheduled = true;
5844
- rafScheduler.schedule("append", flushAppendBuffer);
5845
- }
5846
- }
6488
+ function createSupersededError() {
6489
+ const err = new Error("Editor creation was superseded");
6490
+ err.name = "AbortError";
6491
+ err.code = "STREAM_MONACO_CREATE_SUPERSEDED";
6492
+ return err;
6493
+ }
6494
+ function isCreateActive(requestId, kind) {
6495
+ return activeCreateRequestId === requestId && activeCreateKind === kind;
6496
+ }
6497
+ function assertCreateStillActive(requestId, kind) {
6498
+ if (!isCreateActive(requestId, kind)) throw createSupersededError();
6499
+ }
6500
+ function cancelPendingCreates() {
6501
+ activeCreateRequestId = null;
6502
+ activeCreateKind = null;
6503
+ queuedEditorUpdateDuringCreate = null;
6504
+ disposeAllPendingCreateDisposables();
6505
+ }
6506
+ async function resolveCreateThemeName(requestId, kind) {
6507
+ let themeName = resolveRequestedThemeName();
6508
+ while (true) {
6509
+ assertCreateStillActive(requestId, kind);
6510
+ await ensureThemeRegistered(themeName);
6511
+ assertCreateStillActive(requestId, kind);
6512
+ const latestThemeName = resolveRequestedThemeName();
6513
+ if (latestThemeName === themeName) return themeName;
6514
+ themeName = latestThemeName;
5847
6515
  }
5848
6516
  }
5849
- function applyMinimalEdit(prev, next) {
5850
- if (!editorView) return;
5851
- const model = editorView.getModel();
5852
- if (!model) return;
6517
+ async function createEditor(container, code, language) {
6518
+ var _monacoOptions$onBefo;
6519
+ cancelPendingCreates();
6520
+ cleanupInstances();
6521
+ const requestId = ++createRequestSeq;
6522
+ activeCreateRequestId = requestId;
6523
+ activeCreateKind = "editor";
6524
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6525
+ const requestDisposables = ((_monacoOptions$onBefo = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo === void 0 ? void 0 : _monacoOptions$onBefo.call(monacoOptions, monaco_shim_exports)) ?? [];
6526
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6527
+ let nextEditorMgr = null;
5853
6528
  try {
5854
- const maxChars = minimalEditMaxCharsLocal;
5855
- const ratio = minimalEditMaxChangeRatioLocal;
5856
- const maxLen = Math.max(prev.length, next.length);
5857
- const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
5858
- if (prev.length + next.length > maxChars || changeRatio > ratio) {
5859
- const prevLineCount = model.getLineCount();
5860
- model.setValue(next);
5861
- lastKnownCode = next;
5862
- const newLineCount = model.getLineCount();
5863
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
5864
- return;
5865
- }
5866
- } catch {}
5867
- const res = computeMinimalEdit(prev, next);
5868
- if (!res) return;
5869
- const { start, endPrevIncl, replaceText } = res;
5870
- const rangeStart = model.getPositionAt(start);
5871
- const rangeEnd = model.getPositionAt(endPrevIncl + 1);
5872
- const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
5873
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
5874
- const edit = [{
5875
- range,
5876
- text: replaceText,
5877
- forceMoveMarkers: true
5878
- }];
5879
- if (isReadOnly) model.applyEdits(edit);
5880
- else editorView.executeEdits("minimal-replace", edit);
5881
- }
5882
- function flushPendingUpdate() {
5883
- if (!pendingUpdate) return;
5884
- lastFlushTime = Date.now();
5885
- if (!editorView) return;
5886
- const model = editorView.getModel();
5887
- if (!model) return;
5888
- const { code: newCode, lang: codeLanguage } = pendingUpdate;
5889
- pendingUpdate = null;
5890
- const processedCodeLanguage = processedLanguage(codeLanguage);
5891
- let prevCode = null;
5892
- if (appendBuffer.length > 0) {
5893
- appendBuffer.length = 0;
5894
- appendBufferScheduled = false;
5895
- rafScheduler.cancel("append");
5896
- try {
5897
- prevCode = model.getValue();
5898
- lastKnownCode = prevCode;
5899
- } catch {
5900
- prevCode = lastKnownCode ?? "";
6529
+ const initialThemeName = await resolveCreateThemeName(requestId, "editor");
6530
+ nextEditorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, monacoOptions.updateThrottleMs);
6531
+ const nextEditorView = await nextEditorMgr.createEditor(container, code, language, initialThemeName);
6532
+ assertCreateStillActive(requestId, "editor");
6533
+ editorMgr = nextEditorMgr;
6534
+ editorView = nextEditorView;
6535
+ diffMgr = null;
6536
+ diffEditorView = null;
6537
+ originalModel = null;
6538
+ modifiedModel = null;
6539
+ commitAppliedTheme(initialThemeName);
6540
+ const committedDisposables = takePendingCreateDisposables(requestId);
6541
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6542
+ activeCreateRequestId = null;
6543
+ activeCreateKind = null;
6544
+ const queuedUpdate = queuedEditorUpdateDuringCreate;
6545
+ if ((queuedUpdate === null || queuedUpdate === void 0 ? void 0 : queuedUpdate.requestId) === requestId) {
6546
+ queuedEditorUpdateDuringCreate = null;
6547
+ editorMgr.updateCode(queuedUpdate.code, queuedUpdate.lang);
5901
6548
  }
5902
- } else {
5903
- prevCode = lastKnownCode;
5904
- if (prevCode == null) try {
5905
- prevCode = model.getValue();
5906
- lastKnownCode = prevCode;
5907
- } catch {
5908
- prevCode = "";
6549
+ await notifyThemeApplied(initialThemeName);
6550
+ return nextEditorView;
6551
+ } catch (error$1) {
6552
+ if (nextEditorMgr) try {
6553
+ nextEditorMgr.cleanup();
6554
+ } catch {}
6555
+ disposeDisposables(takePendingCreateDisposables(requestId));
6556
+ if (activeCreateRequestId === requestId) {
6557
+ activeCreateRequestId = null;
6558
+ activeCreateKind = null;
6559
+ queuedEditorUpdateDuringCreate = null;
5909
6560
  }
6561
+ throw error$1;
5910
6562
  }
5911
- if (prevCode === newCode) return;
5912
- const languageId = model.getLanguageId();
5913
- if (languageId !== processedCodeLanguage) {
5914
- if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
5915
- const prevLineCount = model.getLineCount();
5916
- model.setValue(newCode);
5917
- lastKnownCode = newCode;
5918
- const newLineCount = model.getLineCount();
5919
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
5920
- return;
5921
- }
5922
- if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
5923
- const suffix = newCode.slice(prevCode.length);
5924
- if (suffix) appendCode(suffix, codeLanguage);
5925
- lastKnownCode = newCode;
5926
- return;
5927
- }
5928
- try {
5929
- const maxChars = minimalEditMaxCharsLocal;
5930
- const ratio = minimalEditMaxChangeRatioLocal;
5931
- const maxLen = Math.max(prevCode.length, newCode.length);
5932
- const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
5933
- if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
5934
- const prevLineCount = model.getLineCount();
5935
- model.setValue(newCode);
5936
- lastKnownCode = newCode;
5937
- const newLineCount = model.getLineCount();
5938
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
5939
- return;
5940
- }
5941
- } catch {}
6563
+ }
6564
+ async function createDiffEditor(container, originalCode, modifiedCode, language) {
6565
+ var _monacoOptions$onBefo2;
6566
+ cancelPendingCreates();
6567
+ cleanupInstances();
6568
+ const requestId = ++createRequestSeq;
6569
+ activeCreateRequestId = requestId;
6570
+ activeCreateKind = "diff";
6571
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6572
+ const requestDisposables = ((_monacoOptions$onBefo2 = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo2 === void 0 ? void 0 : _monacoOptions$onBefo2.call(monacoOptions, monaco_shim_exports)) ?? [];
6573
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6574
+ let nextDiffMgr = null;
5942
6575
  try {
5943
- applyMinimalEdit(prevCode, newCode);
5944
- lastKnownCode = newCode;
5945
- const newLineCount = model.getLineCount();
5946
- const prevLineCount = (prevCode ? prevCode.split("\n").length : 0) || model.getLineCount();
5947
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
5948
- } catch {
5949
- try {
5950
- const prevLineCount = model.getLineCount();
5951
- model.setValue(newCode);
5952
- lastKnownCode = newCode;
5953
- const newLineCount = model.getLineCount();
5954
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6576
+ const initialThemeName = await resolveCreateThemeName(requestId, "diff");
6577
+ nextDiffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
6578
+ const nextDiffEditorView = await nextDiffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
6579
+ assertCreateStillActive(requestId, "diff");
6580
+ diffMgr = nextDiffMgr;
6581
+ diffEditorView = nextDiffEditorView;
6582
+ editorMgr = null;
6583
+ editorView = null;
6584
+ const models = diffMgr.getDiffModels();
6585
+ originalModel = models.original;
6586
+ modifiedModel = models.modified;
6587
+ commitAppliedTheme(initialThemeName);
6588
+ const committedDisposables = takePendingCreateDisposables(requestId);
6589
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6590
+ activeCreateRequestId = null;
6591
+ activeCreateKind = null;
6592
+ await notifyThemeApplied(initialThemeName);
6593
+ return nextDiffEditorView;
6594
+ } catch (error$1) {
6595
+ if (nextDiffMgr) try {
6596
+ nextDiffMgr.cleanup();
5955
6597
  } catch {}
6598
+ disposeDisposables(takePendingCreateDisposables(requestId));
6599
+ if (activeCreateRequestId === requestId) {
6600
+ activeCreateRequestId = null;
6601
+ activeCreateKind = null;
6602
+ }
6603
+ throw error$1;
5956
6604
  }
5957
6605
  }
5958
- function flushAppendBuffer() {
5959
- if (!editorView) return;
5960
- if (appendBuffer.length === 0) return;
5961
- appendBufferScheduled = false;
5962
- const model = editorView.getModel();
5963
- if (!model) {
5964
- appendBuffer.length = 0;
5965
- return;
5966
- }
5967
- const text = appendBuffer.join("");
5968
- appendBuffer.length = 0;
5969
- try {
5970
- const lastLine = model.getLineCount();
5971
- const lastColumn = model.getLineMaxColumn(lastLine);
5972
- const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
5973
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
5974
- if (isReadOnly) model.applyEdits([{
5975
- range,
5976
- text,
5977
- forceMoveMarkers: true
5978
- }]);
5979
- else editorView.executeEdits("append", [{
5980
- range,
5981
- text,
5982
- forceMoveMarkers: true
5983
- }]);
5984
- if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
5985
- try {
5986
- if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
5987
- } catch {}
5988
- } catch {}
6606
+ function cleanupEditor() {
6607
+ cancelPendingCreates();
6608
+ cleanupInstances();
6609
+ disposeDisposables(disposals.splice(0));
6610
+ }
6611
+ function appendCode(appendText, codeLanguage) {
6612
+ if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
5989
6613
  }
5990
6614
  function updateCode(newCode, codeLanguage) {
5991
- if (editorMgr) editorMgr.updateCode(newCode, codeLanguage);
5992
- else {
5993
- pendingUpdate = {
5994
- code: newCode,
5995
- lang: codeLanguage
5996
- };
5997
- rafScheduler.schedule("update", () => {
5998
- if (!updateThrottleMs) {
5999
- flushPendingUpdate();
6000
- return;
6001
- }
6002
- const now = Date.now();
6003
- const since = now - lastFlushTime;
6004
- if (since >= updateThrottleMs) {
6005
- flushPendingUpdate();
6006
- return;
6007
- }
6008
- if (updateThrottleTimer != null) return;
6009
- const wait = updateThrottleMs - since;
6010
- updateThrottleTimer = setTimeout(() => {
6011
- updateThrottleTimer = null;
6012
- rafScheduler.schedule("update", () => flushPendingUpdate());
6013
- }, wait);
6014
- });
6615
+ if (editorMgr) {
6616
+ editorMgr.updateCode(newCode, codeLanguage);
6617
+ return;
6015
6618
  }
6619
+ if (activeCreateRequestId != null && activeCreateKind === "editor") queuedEditorUpdateDuringCreate = {
6620
+ requestId: activeCreateRequestId,
6621
+ code: newCode,
6622
+ lang: codeLanguage
6623
+ };
6016
6624
  }
6017
6625
  function setUpdateThrottleMs(ms) {
6018
- updateThrottleMs = ms;
6626
+ monacoOptions.updateThrottleMs = ms;
6019
6627
  editorMgr === null || editorMgr === void 0 || editorMgr.setUpdateThrottleMs(ms);
6020
6628
  }
6021
6629
  function getUpdateThrottleMs() {
6022
- return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? updateThrottleMs;
6630
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? monacoOptions.updateThrottleMs ?? 50;
6023
6631
  }
6024
6632
  function updateDiff(originalCode, modifiedCode, codeLanguage) {
6025
6633
  if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
@@ -6051,15 +6659,12 @@ function useMonaco(monacoOptions = {}) {
6051
6659
  createDiffEditor,
6052
6660
  cleanupEditor,
6053
6661
  safeClean() {
6054
- clearFallbackAsyncWork();
6055
6662
  if (editorMgr) try {
6056
6663
  editorMgr.safeClean();
6057
6664
  } catch {}
6058
6665
  if (diffMgr) try {
6059
6666
  diffMgr.safeClean();
6060
6667
  } catch {}
6061
- _hasScrollBar = false;
6062
- shouldAutoScroll = !!autoScrollInitial;
6063
6668
  },
6064
6669
  updateCode,
6065
6670
  appendCode,
@@ -6096,10 +6701,10 @@ function useMonaco(monacoOptions = {}) {
6096
6701
  return monaco_shim_exports.editor;
6097
6702
  },
6098
6703
  getEditorView() {
6099
- return editorView;
6704
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getEditorView()) ?? editorView;
6100
6705
  },
6101
6706
  getDiffEditorView() {
6102
- return diffEditorView;
6707
+ return (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffEditorView()) ?? diffEditorView;
6103
6708
  },
6104
6709
  getDiffModels() {
6105
6710
  if (diffMgr) return diffMgr.getDiffModels();
@@ -6114,18 +6719,22 @@ function useMonaco(monacoOptions = {}) {
6114
6719
  setUpdateThrottleMs,
6115
6720
  getUpdateThrottleMs,
6116
6721
  getCode() {
6722
+ if (editorMgr) return editorMgr.getCode();
6117
6723
  if (editorView) try {
6118
6724
  var _editorView$getModel;
6119
6725
  return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
6120
6726
  } catch {
6121
6727
  return null;
6122
6728
  }
6123
- if (diffEditorView || originalModel && modifiedModel) try {
6124
- const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
6125
- const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
6729
+ const diffModels = (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffModels()) ?? {
6730
+ original: originalModel,
6731
+ modified: modifiedModel
6732
+ };
6733
+ if (diffEditorView || diffModels.original && diffModels.modified) try {
6734
+ var _diffModels$original, _diffModels$modified;
6126
6735
  return {
6127
- original,
6128
- modified
6736
+ original: ((_diffModels$original = diffModels.original) === null || _diffModels$original === void 0 ? void 0 : _diffModels$original.getValue()) ?? "",
6737
+ modified: ((_diffModels$modified = diffModels.modified) === null || _diffModels$modified === void 0 ? void 0 : _diffModels$modified.getValue()) ?? ""
6129
6738
  };
6130
6739
  } catch {
6131
6740
  return null;