stream-monaco 0.0.22 → 0.0.37

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;
@@ -642,6 +1453,8 @@ var DiffEditorManager = class DiffEditorManager {
642
1453
  this.diffAutoScroll = diffAutoScroll;
643
1454
  this.revealDebounceMsOption = revealDebounceMsOption;
644
1455
  this.diffUpdateThrottleMsOption = diffUpdateThrottleMsOption;
1456
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
1457
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
645
1458
  }
646
1459
  resolveDiffHideUnchangedRegionsOption() {
647
1460
  const normalize = (value) => {
@@ -682,188 +1495,21 @@ var DiffEditorManager = class DiffEditorManager {
682
1495
  if (typeof explicitThrottle === "number") return explicitThrottle;
683
1496
  return 50;
684
1497
  }
685
- parseCssColorRgb(color) {
686
- const normalized = color.trim().toLowerCase();
687
- const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
688
- if (rgbMatch) return [
689
- Number.parseFloat(rgbMatch[1]),
690
- Number.parseFloat(rgbMatch[2]),
691
- Number.parseFloat(rgbMatch[3])
692
- ];
693
- const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
694
- if (!hexMatch) return null;
695
- const hex = hexMatch[1];
696
- if (hex.length === 3 || hex.length === 4) return [
697
- Number.parseInt(`${hex[0]}${hex[0]}`, 16),
698
- Number.parseInt(`${hex[1]}${hex[1]}`, 16),
699
- Number.parseInt(`${hex[2]}${hex[2]}`, 16)
700
- ];
701
- if (hex.length === 6 || hex.length === 8) return [
702
- Number.parseInt(hex.slice(0, 2), 16),
703
- Number.parseInt(hex.slice(2, 4), 16),
704
- Number.parseInt(hex.slice(4, 6), 16)
705
- ];
706
- return null;
707
- }
708
- resolveCssColorLuminance(color) {
709
- const rgb = this.parseCssColorRgb(color);
710
- if (!rgb) return null;
711
- const channel = (value) => {
712
- const normalized = Math.max(0, Math.min(255, value)) / 255;
713
- return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
714
- };
715
- const [r, g, b] = rgb;
716
- return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
717
- }
718
- resolveDiffUnchangedLineInfoRailMetrics(node) {
719
- const editorRoot = node.closest(".monaco-editor");
720
- if (!editorRoot) return {
721
- leftInset: 0,
722
- width: null
723
- };
724
- const editorRect = editorRoot.getBoundingClientRect();
725
- const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
726
- const rect = candidate.getBoundingClientRect();
727
- return rect.width > 0 && rect.height > 0;
728
- });
729
- if (!lineNumberNode) return {
730
- leftInset: 0,
731
- width: null
732
- };
733
- const lineNumberRect = lineNumberNode.getBoundingClientRect();
734
- return {
735
- leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
736
- width: Math.max(0, lineNumberRect.width) || null
737
- };
738
- }
739
- looksLikeDarkThemeName(themeName) {
740
- if (!themeName) return false;
741
- const normalized = themeName.toLowerCase();
742
- return [
743
- "dark",
744
- "night",
745
- "moon",
746
- "black",
747
- "dracula",
748
- "mocha",
749
- "frappe",
750
- "macchiato",
751
- "palenight",
752
- "ocean",
753
- "poimandres",
754
- "monokai",
755
- "laserwave",
756
- "tokyo",
757
- "slack-dark",
758
- "rose-pine",
759
- "github-dark",
760
- "material-theme",
761
- "one-dark",
762
- "catppuccin-mocha",
763
- "catppuccin-frappe",
764
- "catppuccin-macchiato"
765
- ].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
766
- }
767
- looksLikeLightThemeName(themeName) {
768
- if (!themeName) return false;
769
- const normalized = themeName.toLowerCase();
770
- return [
771
- "light",
772
- "day",
773
- "dawn",
774
- "latte",
775
- "solarized-light",
776
- "github-light",
777
- "rose-pine-dawn",
778
- "catppuccin-latte",
779
- "one-light",
780
- "vitesse-light",
781
- "snazzy-light",
782
- "material-lighter",
783
- "material-theme-lighter",
784
- "lotus"
785
- ].some((token) => normalized.includes(token));
786
- }
787
- resolveDiffAppearanceOption() {
788
- var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2, _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
789
- if (this.options.diffAppearance === "light") return "light";
790
- if (this.options.diffAppearance === "dark") return "dark";
791
- if (this.looksLikeDarkThemeName(this.options.theme)) return "dark";
792
- if (this.looksLikeLightThemeName(this.options.theme)) return "light";
793
- const appearanceProbeNodes = [
794
- (_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$),
795
- (_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),
796
- this.lastContainer
797
- ];
798
- for (const node of appearanceProbeNodes) {
799
- if (!(node instanceof HTMLElement)) continue;
800
- const style = globalThis.getComputedStyle(node);
801
- const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
802
- const candidates = [
803
- style.getPropertyValue("--stream-monaco-editor-bg"),
804
- style.getPropertyValue("--vscode-editor-background"),
805
- editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
806
- style.backgroundColor
807
- ];
808
- for (const color of candidates) {
809
- const luminance = this.resolveCssColorLuminance(color);
810
- if (luminance == null) continue;
811
- return luminance <= .42 ? "dark" : "light";
812
- }
813
- }
814
- return this.looksLikeDarkThemeName(this.options.theme) ? "dark" : "light";
815
- }
816
- syncDiffRootThemeVariables(appearance) {
817
- var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7, _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10;
818
- if (!(this.lastContainer instanceof HTMLElement)) return;
819
- const probeNodes = [
820
- (_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),
821
- (_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),
822
- this.lastContainer
823
- ];
824
- const containerStyle = globalThis.getComputedStyle(this.lastContainer);
825
- const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
826
- let backgroundColor = null;
827
- let foregroundColor = null;
828
- for (const node of probeNodes) {
829
- if (!(node instanceof HTMLElement)) continue;
830
- const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
831
- const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
832
- const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
833
- if (!backgroundColor && this.resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
834
- const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
835
- if (!foregroundColor && this.resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
836
- if (backgroundColor && foregroundColor) break;
837
- }
838
- const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
839
- if (resolvedBackgroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
840
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-bg");
841
- if (foregroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
842
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
843
- }
844
1498
  applyDiffRootAppearanceClass() {
845
- if (!this.lastContainer) return;
846
- const resolvedAppearance = this.resolveDiffAppearanceOption();
847
- this.syncDiffRootThemeVariables(resolvedAppearance);
848
- const containerClassList = this.lastContainer.classList;
849
- const activeLineStyleClass = `stream-monaco-diff-style-${this.resolveDiffLineStyleOption()}`;
850
- const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${this.resolveDiffUnchangedRegionStyleOption()}`;
851
- const sideBySide = !this.isDiffInlineMode();
852
- const activeLayoutModeClass = sideBySide ? "stream-monaco-diff-side-by-side" : "stream-monaco-diff-inline";
853
- const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
854
- const nextSignature = [
855
- activeLineStyleClass,
856
- activeUnchangedRegionStyleClass,
857
- activeLayoutModeClass,
858
- activeAppearanceClass
859
- ].join("|");
860
- if (this.diffRootAppearanceSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return;
861
- containerClassList.add("stream-monaco-diff-root");
862
- for (const className of DiffEditorManager.diffLineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
863
- for (const className of DiffEditorManager.diffUnchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
864
- for (const className of DiffEditorManager.diffLayoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
865
- for (const className of DiffEditorManager.diffAppearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
866
- 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
+ });
867
1513
  }
868
1514
  disposeDiffHunkInteractions() {
869
1515
  if (this.diffHunkHideTimer != null) {
@@ -991,9 +1637,9 @@ var DiffEditorManager = class DiffEditorManager {
991
1637
  });
992
1638
  }
993
1639
  clearFallbackDiffDecorations() {
994
- var _this$diffEditorView11, _this$diffEditorView12;
995
- const originalEditor = (_this$diffEditorView11 = this.diffEditorView) === null || _this$diffEditorView11 === void 0 ? void 0 : _this$diffEditorView11.getOriginalEditor();
996
- 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();
997
1643
  if (originalEditor && this.fallbackOriginalDecorationIds.length > 0) this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, []);
998
1644
  else this.fallbackOriginalDecorationIds = [];
999
1645
  if (modifiedEditor && this.fallbackModifiedDecorationIds.length > 0) this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, []);
@@ -1001,8 +1647,8 @@ var DiffEditorManager = class DiffEditorManager {
1001
1647
  this.clearFallbackInlineDeletedZones();
1002
1648
  }
1003
1649
  clearFallbackInlineDeletedZones() {
1004
- var _this$diffEditorView13;
1005
- const modifiedEditor = (_this$diffEditorView13 = this.diffEditorView) === null || _this$diffEditorView13 === void 0 ? void 0 : _this$diffEditorView13.getModifiedEditor();
1650
+ var _this$diffEditorView3;
1651
+ const modifiedEditor = (_this$diffEditorView3 = this.diffEditorView) === null || _this$diffEditorView3 === void 0 ? void 0 : _this$diffEditorView3.getModifiedEditor();
1006
1652
  if (modifiedEditor && this.fallbackInlineDeletedZoneIds.length > 0) try {
1007
1653
  var _modifiedEditor$chang;
1008
1654
  (_modifiedEditor$chang = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang === void 0 || _modifiedEditor$chang.call(modifiedEditor, (accessor) => {
@@ -1031,8 +1677,7 @@ var DiffEditorManager = class DiffEditorManager {
1031
1677
  }
1032
1678
  syncDiffEditorLayoutToContainer() {
1033
1679
  if (!this.diffEditorView || !this.lastContainer) return;
1034
- const width = this.lastContainer.clientWidth || this.lastContainer.getBoundingClientRect().width;
1035
- const height = this.lastContainer.clientHeight || this.lastContainer.getBoundingClientRect().height;
1680
+ const { width, height } = readContainerLayoutSize(this.lastContainer);
1036
1681
  if (!(width > 0) || !(height > 0)) return;
1037
1682
  try {
1038
1683
  var _layout, _ref;
@@ -1095,7 +1740,7 @@ var DiffEditorManager = class DiffEditorManager {
1095
1740
  }
1096
1741
  const lineHeightOption = (_EditorOption = monaco_shim_exports.editor.EditorOption) === null || _EditorOption === void 0 ? void 0 : _EditorOption.lineHeight;
1097
1742
  const lineHeight = ((_modifiedEditor$getOp = modifiedEditor.getOption) === null || _modifiedEditor$getOp === void 0 ? void 0 : _modifiedEditor$getOp.call(modifiedEditor, lineHeightOption)) ?? 20;
1098
- const relevantChanges = lineChanges.filter((change) => this.hasOriginalLines(change));
1743
+ const relevantChanges = lineChanges.filter((change) => hasOriginalLines(change));
1099
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) => {
1100
1745
  return node instanceof HTMLElement && !!node.querySelector(".view-lines.line-delete");
1101
1746
  });
@@ -1229,7 +1874,7 @@ var DiffEditorManager = class DiffEditorManager {
1229
1874
  };
1230
1875
  }
1231
1876
  syncDiffPresentationDecorations() {
1232
- var _this$diffEditorView$3, _this$lastContainer$q, _this$lastContainer5;
1877
+ var _this$diffEditorView$, _this$lastContainer$q, _this$lastContainer5;
1233
1878
  if (!this.diffEditorView || !this.lastContainer) return;
1234
1879
  const nativeFresh = this.hasFreshNativeDiffResult();
1235
1880
  const useInlineMode = this.isDiffInlineMode();
@@ -1237,10 +1882,10 @@ var DiffEditorManager = class DiffEditorManager {
1237
1882
  const nativeInlineDeleteZoneCount = useInlineMode ? this.countNativeInlineDeleteZoneNodes() : 0;
1238
1883
  const hasNativeInlineDeleteZoneNodes = nativeInlineDeleteZoneCount > 0;
1239
1884
  const hasNativeInlineDeleteNodes = useInlineMode && this.hasVisibleNativeInlineDeleteNodes();
1240
- const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => this.hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1885
+ const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1241
1886
  const useInlineStaleFallback = shouldKeepInlineFallback;
1242
1887
  this.lastContainer.classList.toggle("stream-monaco-diff-inline-native-ready", useInlineMode && !shouldKeepInlineFallback && (nativeFresh || hasNativeInlineDeleteNodes || hasNativeInlineDeleteZoneNodes));
1243
- const keepNativeDecorationsWhileStale = !useInlineStaleFallback && !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$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")));
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")));
1244
1889
  this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh && !keepNativeDecorationsWhileStale);
1245
1890
  if (nativeFresh && !shouldKeepInlineFallback) {
1246
1891
  this.clearFallbackDiffDecorations();
@@ -2515,27 +3160,6 @@ var DiffEditorManager = class DiffEditorManager {
2515
3160
  el.addEventListener(eventName, listener);
2516
3161
  bucket.push({ dispose: () => el.removeEventListener(eventName, listener) });
2517
3162
  }
2518
- createDiffHunkActionNode(side) {
2519
- const node = document.createElement("div");
2520
- node.className = "stream-monaco-diff-hunk-actions";
2521
- node.dataset.side = side;
2522
- const createButton = (action, label) => {
2523
- const button = document.createElement("button");
2524
- button.type = "button";
2525
- button.textContent = label;
2526
- button.dataset.action = action;
2527
- button.addEventListener("click", (event) => {
2528
- event.preventDefault();
2529
- event.stopPropagation();
2530
- this.applyDiffHunkAction(side, action);
2531
- });
2532
- return button;
2533
- };
2534
- node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
2535
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
2536
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseleave", () => this.scheduleHideDiffHunkActions());
2537
- return node;
2538
- }
2539
3163
  cloneSerializableValue(value) {
2540
3164
  if (typeof structuredClone === "function") return structuredClone(value);
2541
3165
  return JSON.parse(JSON.stringify(value));
@@ -2794,8 +3418,8 @@ var DiffEditorManager = class DiffEditorManager {
2794
3418
  this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
2795
3419
  }
2796
3420
  this.withLockedDiffScrollPosition(() => {
2797
- var _this$diffEditorView14;
2798
- (_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || _this$diffEditorView14.updateOptions(presentationOptions);
3421
+ var _this$diffEditorView4;
3422
+ (_this$diffEditorView4 = this.diffEditorView) === null || _this$diffEditorView4 === void 0 || _this$diffEditorView4.updateOptions(presentationOptions);
2799
3423
  });
2800
3424
  (_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 || _this$diffHeightManag.update();
2801
3425
  this.applyDiffRootAppearanceClass();
@@ -2817,8 +3441,8 @@ var DiffEditorManager = class DiffEditorManager {
2817
3441
  if (!this.diffHideUnchangedRegionsDeferred) return;
2818
3442
  this.diffHideUnchangedRegionsDeferred = false;
2819
3443
  this.withLockedDiffScrollPosition(() => {
2820
- var _this$diffEditorView15;
2821
- (_this$diffEditorView15 = this.diffEditorView) === null || _this$diffEditorView15 === void 0 || _this$diffEditorView15.updateOptions({ hideUnchangedRegions });
3444
+ var _this$diffEditorView5;
3445
+ (_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || _this$diffEditorView5.updateOptions({ hideUnchangedRegions });
2822
3446
  });
2823
3447
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2824
3448
  if (this.shouldAutoScrollDiff) {
@@ -2828,7 +3452,7 @@ var DiffEditorManager = class DiffEditorManager {
2828
3452
  }
2829
3453
  markDiffStreamingActivity() {
2830
3454
  var _this$lastContainer6;
2831
- (_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.classList.remove("stream-monaco-diff-inline-native-ready");
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");
2832
3456
  if (this.isDiffInlineMode()) {
2833
3457
  var _this$diffHeightManag2, _this$lastContainer7, _this$lastContainer7$;
2834
3458
  this.inlineDiffStreamingPresentationActive = true;
@@ -2854,8 +3478,8 @@ var DiffEditorManager = class DiffEditorManager {
2854
3478
  this.diffHideUnchangedRegionsDeferred = true;
2855
3479
  this.hideAllDiffUnchangedBridgeEntries();
2856
3480
  this.withLockedDiffScrollPosition(() => {
2857
- var _this$diffEditorView16;
2858
- (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.updateOptions({ hideUnchangedRegions: {
3481
+ var _this$diffEditorView6;
3482
+ (_this$diffEditorView6 = this.diffEditorView) === null || _this$diffEditorView6 === void 0 || _this$diffEditorView6.updateOptions({ hideUnchangedRegions: {
2859
3483
  ...hideUnchangedRegions,
2860
3484
  enabled: false
2861
3485
  } });
@@ -2929,7 +3553,7 @@ var DiffEditorManager = class DiffEditorManager {
2929
3553
  var _this$diffUnchangedBr;
2930
3554
  this.clearDiffUnchangedBridgeSources();
2931
3555
  if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.replaceChildren();
2932
- if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.style.transform = "translate3d(0px, 0px, 0px)";
3556
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2933
3557
  this.diffUnchangedBridgeEntries.clear();
2934
3558
  this.diffUnchangedBridgePool.length = 0;
2935
3559
  this.diffUnchangedOverlayScrollTop = 0;
@@ -2939,30 +3563,27 @@ var DiffEditorManager = class DiffEditorManager {
2939
3563
  }
2940
3564
  clearDiffUnchangedBridgeSources() {
2941
3565
  if (!this.lastContainer) return;
2942
- const bridgedCenters = this.lastContainer.querySelectorAll(".stream-monaco-unchanged-bridge-source");
2943
- bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
3566
+ clearDiffUnchangedBridgeSourceClasses(this.lastContainer);
2944
3567
  }
2945
3568
  ensureDiffUnchangedBridgeOverlay() {
2946
3569
  if (!this.lastContainer) return null;
2947
3570
  if (!this.diffUnchangedBridgeOverlay) {
2948
- const overlay = document.createElement("div");
2949
- overlay.className = "stream-monaco-diff-unchanged-overlay";
3571
+ const overlay = createDiffUnchangedBridgeOverlay();
2950
3572
  this.lastContainer.append(overlay);
2951
3573
  this.diffUnchangedBridgeOverlay = overlay;
2952
3574
  }
2953
3575
  return this.diffUnchangedBridgeOverlay;
2954
3576
  }
2955
3577
  readDiffUnchangedOverlayScrollState() {
2956
- var _this$diffEditorView17, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
2957
- const modifiedEditor = (_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 ? void 0 : _this$diffEditorView17.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();
2958
3580
  return {
2959
3581
  top: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc6 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc6 === void 0 ? void 0 : _modifiedEditor$getSc6.call(modifiedEditor)) ?? 0,
2960
3582
  left: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc7 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc7 === void 0 ? void 0 : _modifiedEditor$getSc7.call(modifiedEditor)) ?? 0
2961
3583
  };
2962
3584
  }
2963
3585
  syncDiffUnchangedOverlayScrollBaseline() {
2964
- const overlay = this.diffUnchangedBridgeOverlay;
2965
- if (overlay) overlay.style.transform = "translate3d(0px, 0px, 0px)";
3586
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2966
3587
  const { top, left } = this.readDiffUnchangedOverlayScrollState();
2967
3588
  this.diffUnchangedOverlayScrollTop = top;
2968
3589
  this.diffUnchangedOverlayScrollLeft = left;
@@ -2976,28 +3597,10 @@ var DiffEditorManager = class DiffEditorManager {
2976
3597
  if (Math.abs(deltaY) < .5 && Math.abs(deltaX) < .5) return;
2977
3598
  overlay.style.transform = `translate3d(${deltaX}px, ${deltaY}px, 0px)`;
2978
3599
  }
2979
- resolveDiffUnchangedViewZoneHeight() {
2980
- switch (this.resolveDiffUnchangedRegionStyleOption()) {
2981
- case "line-info":
2982
- case "line-info-basic":
2983
- case "metadata": return 32;
2984
- case "simple": return 28;
2985
- default: return 32;
2986
- }
2987
- }
2988
- collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
2989
- 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);
2990
- if (widgetTopValues.length === 0) return [];
2991
- return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
2992
- const zoneTop = Number.parseFloat(node.style.top || "NaN");
2993
- const currentHeight = Number.parseFloat(node.style.height || "0");
2994
- return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
2995
- }).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
2996
- }
2997
3600
  syncDiffUnchangedViewZoneHeightsForEditor(editor, editorRoot, targetHeight) {
2998
3601
  var _editor$getScrollTop, _editorInternal$_mode;
2999
3602
  if (!editor || !(editorRoot instanceof HTMLElement)) return false;
3000
- 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);
3001
3604
  if (zoneIds.length === 0) return false;
3002
3605
  const editorInternal = editor;
3003
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;
@@ -3022,7 +3625,7 @@ var DiffEditorManager = class DiffEditorManager {
3022
3625
  syncDiffUnchangedViewZoneHeights() {
3023
3626
  var _originalEditor$getCo, _modifiedEditor$getCo3;
3024
3627
  if (!this.diffEditorView) return false;
3025
- const targetHeight = this.resolveDiffUnchangedViewZoneHeight();
3628
+ const targetHeight = resolveDiffUnchangedViewZoneHeight(this.resolveDiffUnchangedRegionStyleOption());
3026
3629
  const originalEditor = this.diffEditorView.getOriginalEditor();
3027
3630
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
3028
3631
  const originalChanged = this.syncDiffUnchangedViewZoneHeightsForEditor(originalEditor, (_originalEditor$getCo = originalEditor.getContainerDomNode) === null || _originalEditor$getCo === void 0 ? void 0 : _originalEditor$getCo.call(originalEditor), targetHeight);
@@ -3040,19 +3643,7 @@ var DiffEditorManager = class DiffEditorManager {
3040
3643
  return `${this.getDiffUnchangedNodeId(secondaryNode)}:${this.getDiffUnchangedNodeId(primaryNode)}`;
3041
3644
  }
3042
3645
  createDiffUnchangedBridgeEntry(key) {
3043
- const bridge = document.createElement("div");
3044
- bridge.className = "stream-monaco-diff-unchanged-bridge";
3045
- bridge.setAttribute("role", "group");
3046
- bridge.hidden = true;
3047
- const summary = document.createElement("button");
3048
- summary.type = "button";
3049
- summary.className = "stream-monaco-unchanged-summary";
3050
- const visualMeta = document.createElement("div");
3051
- visualMeta.className = "stream-monaco-unchanged-meta";
3052
- summary.append(visualMeta);
3053
- const divider = document.createElement("span");
3054
- divider.className = "stream-monaco-unchanged-pane-divider";
3055
- divider.setAttribute("aria-hidden", "true");
3646
+ const { bridge, summary, visualMeta, divider } = createDiffUnchangedBridgeScaffold();
3056
3647
  const entry = {
3057
3648
  key,
3058
3649
  bridge,
@@ -3071,16 +3662,15 @@ var DiffEditorManager = class DiffEditorManager {
3071
3662
  const onWheel = (event) => {
3072
3663
  var _modifiedEditor$getSc8, _modifiedEditor$getSc9, _originalEditor$setSc6, _modifiedEditor$setSc6;
3073
3664
  if (!this.diffEditorView) return;
3074
- if (Math.abs(event.deltaY) < .5 && Math.abs(event.deltaX) < .5) return;
3665
+ if (!shouldHandleDiffUnchangedWheel(event)) return;
3075
3666
  event.preventDefault();
3076
3667
  event.stopPropagation();
3077
3668
  const originalEditor = this.diffEditorView.getOriginalEditor();
3078
3669
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
3079
- const targetScrollTop = (((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0) + event.deltaY;
3080
- 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);
3081
3671
  (_originalEditor$setSc6 = originalEditor.setScrollTop) === null || _originalEditor$setSc6 === void 0 || _originalEditor$setSc6.call(originalEditor, targetScrollTop);
3082
3672
  (_modifiedEditor$setSc6 = modifiedEditor.setScrollTop) === null || _modifiedEditor$setSc6 === void 0 || _modifiedEditor$setSc6.call(modifiedEditor, targetScrollTop);
3083
- if (Math.abs(event.deltaX) >= .5) {
3673
+ if (syncHorizontal) {
3084
3674
  var _originalEditor$setSc7, _modifiedEditor$setSc7;
3085
3675
  (_originalEditor$setSc7 = originalEditor.setScrollLeft) === null || _originalEditor$setSc7 === void 0 || _originalEditor$setSc7.call(originalEditor, targetScrollLeft);
3086
3676
  (_modifiedEditor$setSc7 = modifiedEditor.setScrollLeft) === null || _modifiedEditor$setSc7 === void 0 || _modifiedEditor$setSc7.call(modifiedEditor, targetScrollLeft);
@@ -3089,7 +3679,6 @@ var DiffEditorManager = class DiffEditorManager {
3089
3679
  };
3090
3680
  bridge.addEventListener("wheel", onWheel, { passive: false });
3091
3681
  this.diffUnchangedRegionDisposables.push({ dispose: () => bridge.removeEventListener("wheel", onWheel) });
3092
- bridge.append(summary, divider);
3093
3682
  return entry;
3094
3683
  }
3095
3684
  acquireDiffUnchangedBridgeEntry(key) {
@@ -3097,16 +3686,14 @@ var DiffEditorManager = class DiffEditorManager {
3097
3686
  if (existing) return existing;
3098
3687
  const entry = this.diffUnchangedBridgePool.pop() ?? this.createDiffUnchangedBridgeEntry(key);
3099
3688
  entry.key = key;
3100
- entry.bridge.hidden = false;
3101
- entry.bridge.removeAttribute("aria-hidden");
3689
+ syncDiffUnchangedBridgeVisibility(entry.bridge, true);
3102
3690
  this.diffUnchangedBridgeEntries.set(key, entry);
3103
3691
  return entry;
3104
3692
  }
3105
3693
  releaseDiffUnchangedBridgeEntry(entry) {
3106
3694
  if (entry.key) this.diffUnchangedBridgeEntries.delete(entry.key);
3107
3695
  entry.key = null;
3108
- entry.bridge.hidden = true;
3109
- entry.bridge.setAttribute("aria-hidden", "true");
3696
+ syncDiffUnchangedBridgeVisibility(entry.bridge, false);
3110
3697
  this.diffUnchangedBridgePool.push(entry);
3111
3698
  }
3112
3699
  hideAllDiffUnchangedBridgeEntries() {
@@ -3132,51 +3719,15 @@ var DiffEditorManager = class DiffEditorManager {
3132
3719
  entry.activate();
3133
3720
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3134
3721
  }
3135
- updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel) {
3136
- this.updateDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
3137
- }
3138
- updateDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
3139
- const lastStyle = metaNode.dataset.style;
3140
- const lastLabel = metaNode.dataset.label;
3141
- if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
3142
- metaNode.dataset.style = unchangedRegionStyle;
3143
- metaNode.dataset.label = summaryLabel;
3144
- metaNode.replaceChildren();
3145
- metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
3146
- if (unchangedRegionStyle === "simple") {
3147
- const simpleBar = document.createElement("span");
3148
- simpleBar.className = "stream-monaco-unchanged-simple-bar";
3149
- simpleBar.setAttribute("aria-hidden", "true");
3150
- metaNode.append(simpleBar);
3151
- return;
3152
- }
3153
- const label = document.createElement("span");
3154
- if (unchangedRegionStyle === "metadata") label.className = "stream-monaco-unchanged-metadata-label";
3155
- else label.className = "stream-monaco-unchanged-count";
3156
- label.textContent = summaryLabel;
3157
- metaNode.append(label);
3158
- }
3159
3722
  syncDiffUnchangedRevealButton(entry, slot, handle, direction, label) {
3160
3723
  const existingButton = entry[slot];
3161
- const button = existingButton ?? document.createElement("button");
3162
- if (!existingButton) {
3163
- button.type = "button";
3164
- button.className = "stream-monaco-unchanged-reveal";
3165
- button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
3166
- }
3167
- button.dataset.direction = direction;
3168
- button.hidden = !handle;
3169
- button.disabled = !handle;
3170
- button.toggleAttribute("aria-hidden", !handle);
3171
- button.title = handle ? label : "";
3172
- button.setAttribute("aria-label", handle ? label : "");
3173
- button.onclick = handle ? (event) => {
3174
- event.preventDefault();
3175
- event.stopPropagation();
3724
+ const button = existingButton ?? createDiffUnchangedRevealButton(direction);
3725
+ syncDiffUnchangedRevealButtonNode(button, handle, label);
3726
+ bindDiffUnchangedRevealButtonAction(button, handle, (nextHandle) => {
3176
3727
  this.hideAllDiffUnchangedBridgeEntries();
3177
- this.activateDiffUnchangedHandle(handle);
3728
+ this.activateDiffUnchangedHandle(nextHandle);
3178
3729
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3179
- } : null;
3730
+ });
3180
3731
  entry[slot] = button;
3181
3732
  }
3182
3733
  syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle, showBottomHandle, bottomHandle) {
@@ -3184,14 +3735,9 @@ var DiffEditorManager = class DiffEditorManager {
3184
3735
  entry.rail = document.createElement("div");
3185
3736
  entry.rail.className = "stream-monaco-unchanged-rail";
3186
3737
  }
3187
- const shouldRenderRail = showTopHandle || showBottomHandle;
3188
3738
  this.syncDiffUnchangedRevealButton(entry, "topButton", showTopHandle ? topHandle : null, "down", "Reveal more unmodified lines below");
3189
3739
  this.syncDiffUnchangedRevealButton(entry, "bottomButton", showBottomHandle ? bottomHandle : null, "up", "Reveal more unmodified lines above");
3190
- entry.rail.hidden = !shouldRenderRail;
3191
- entry.rail.toggleAttribute("aria-hidden", !shouldRenderRail);
3192
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
3193
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
3194
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
3740
+ syncDiffUnchangedRailNode(entry.rail, showTopHandle, showBottomHandle);
3195
3741
  if (entry.topButton && entry.topButton.parentElement !== entry.rail) entry.rail.append(entry.topButton);
3196
3742
  if (entry.bottomButton && entry.bottomButton.parentElement !== entry.rail) entry.rail.append(entry.bottomButton);
3197
3743
  }
@@ -3201,201 +3747,46 @@ var DiffEditorManager = class DiffEditorManager {
3201
3747
  this.releaseDiffUnchangedBridgeEntry(entry);
3202
3748
  }
3203
3749
  }
3204
- dispatchSyntheticMouseDown(node) {
3205
- const view = node.ownerDocument.defaultView;
3206
- if (!view) return;
3207
- const rect = node.getBoundingClientRect();
3208
- node.dispatchEvent(new view.MouseEvent("mousedown", {
3209
- bubbles: true,
3210
- cancelable: true,
3211
- button: 0,
3212
- clientX: rect.left + rect.width / 2,
3213
- clientY: rect.top + rect.height / 2
3214
- }));
3215
- }
3216
- dispatchSyntheticMouseTap(node) {
3217
- const view = node.ownerDocument.defaultView;
3218
- if (!view) return;
3219
- const rect = node.getBoundingClientRect();
3220
- const clientX = rect.left + rect.width / 2;
3221
- const clientY = rect.top + rect.height / 2;
3222
- node.dispatchEvent(new view.MouseEvent("mousedown", {
3223
- bubbles: true,
3224
- cancelable: true,
3225
- button: 0,
3226
- clientX,
3227
- clientY
3228
- }));
3229
- node.dispatchEvent(new view.MouseEvent("mouseup", {
3230
- bubbles: true,
3231
- cancelable: true,
3232
- button: 0,
3233
- clientX,
3234
- clientY
3235
- }));
3236
- }
3237
- formatDiffUnchangedCountLabel(text) {
3238
- const match = text.match(/\d+/);
3239
- const count = match ? Number.parseInt(match[0], 10) : NaN;
3240
- if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
3241
- return text.replace(/hidden/gi, "unmodified");
3242
- }
3243
- countDiffLines(startLineNumber, endLineNumber) {
3244
- return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
3245
- }
3246
- measureDiffUnchangedSurroundingLines(primaryNode) {
3247
- const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
3248
- if (!editorRoot) return {
3249
- previousVisibleLine: null,
3250
- nextVisibleLine: null
3251
- };
3252
- const widgetRect = primaryNode.getBoundingClientRect();
3253
- let previousVisibleLine = null;
3254
- let nextVisibleLine = null;
3255
- const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
3256
- lineNumberNodes.forEach((node) => {
3257
- var _node$textContent3;
3258
- const lineNumber = Number.parseInt(((_node$textContent3 = node.textContent) === null || _node$textContent3 === void 0 ? void 0 : _node$textContent3.trim()) || "", 10);
3259
- if (!Number.isFinite(lineNumber)) return;
3260
- const top = node.getBoundingClientRect().top;
3261
- if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
3262
- else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
3263
- });
3264
- return {
3265
- previousVisibleLine,
3266
- nextVisibleLine
3267
- };
3268
- }
3269
- formatDiffMetadataRange(startLineNumber, lineCount) {
3270
- return `${startLineNumber},${Math.max(0, lineCount)}`;
3271
- }
3272
- buildDiffHunkMetadataLabel(change) {
3273
- var _this$originalModel, _this$modifiedModel2;
3274
- const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3275
- const originalTotalLines = ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0;
3276
- const modifiedTotalLines = ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0;
3277
- const originalChangedCount = this.countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
3278
- const modifiedChangedCount = this.countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
3279
- const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
3280
- const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
3281
- const originalStart = Math.max(1, originalAnchor - contextLineCount);
3282
- const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
3283
- const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
3284
- const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
3285
- const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
3286
- const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
3287
- return {
3288
- modifiedStart,
3289
- originalStart,
3290
- label: `@@ -${this.formatDiffMetadataRange(originalStart, originalDisplayCount)} +${this.formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
3291
- };
3292
- }
3293
- resolveDiffMetadataLabel(primaryNode, pairIndex) {
3294
- var _metadataEntries$Math;
3295
- const lineChanges = this.getEffectiveLineChanges();
3296
- if (lineChanges.length === 0) return null;
3297
- const metadataEntries = lineChanges.map((change) => this.buildDiffHunkMetadataLabel(change));
3298
- const { nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
3299
- if (nextVisibleLine != null) {
3300
- const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
3301
- for (const candidateStart of candidateStarts) {
3302
- const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
3303
- if (matching) return matching.label;
3304
- }
3305
- }
3306
- return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
3307
- }
3308
3750
  activateDiffUnchangedHandle(node) {
3309
3751
  if (!(node instanceof HTMLElement)) return;
3310
- this.dispatchSyntheticMouseTap(node);
3752
+ dispatchSyntheticPrimaryMouseTap(node);
3311
3753
  this.scheduleCapturePersistedDiffUnchangedState(1);
3312
3754
  }
3313
- resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount) {
3314
- var _this$diffEditorView18, _this$diffEditorView19;
3315
- let showTopHandle = pairCount === 1 || pairIndex > 0;
3316
- let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
3317
- const countMatch = countText.match(/\d+/);
3318
- const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
3319
- if (!Number.isFinite(hiddenCount)) return {
3320
- showTopHandle,
3321
- showBottomHandle
3322
- };
3323
- const { previousVisibleLine, nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
3324
- if (previousVisibleLine == null && nextVisibleLine != null) {
3325
- showTopHandle = false;
3326
- showBottomHandle = true;
3327
- return {
3328
- showTopHandle,
3329
- showBottomHandle
3330
- };
3331
- }
3332
- if (nextVisibleLine == null && previousVisibleLine != null) {
3333
- showTopHandle = true;
3334
- showBottomHandle = false;
3335
- return {
3336
- showTopHandle,
3337
- showBottomHandle
3338
- };
3339
- }
3340
- if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
3341
- showTopHandle = false;
3342
- showBottomHandle = true;
3343
- }
3344
- const modelLineCount = ((_this$diffEditorView18 = this.diffEditorView) === null || _this$diffEditorView18 === void 0 || (_this$diffEditorView18 = _this$diffEditorView18.getModifiedEditor().getModel()) === null || _this$diffEditorView18 === void 0 || (_this$diffEditorView19 = _this$diffEditorView18.getLineCount) === null || _this$diffEditorView19 === void 0 ? void 0 : _this$diffEditorView19.call(_this$diffEditorView18)) ?? null;
3345
- if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
3346
- showTopHandle = true;
3347
- showBottomHandle = false;
3348
- }
3349
- return {
3350
- showTopHandle,
3351
- showBottomHandle
3352
- };
3353
- }
3354
- resolveDiffUnchangedMergeRole(node) {
3355
- var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24, _this$diffEditorView25;
3356
- const diffRoot = node.closest(".monaco-diff-editor.side-by-side");
3357
- if (!(diffRoot instanceof HTMLElement)) return "none";
3358
- const nodeRect = node.getBoundingClientRect();
3359
- const nodeCenter = nodeRect.left + nodeRect.width / 2;
3360
- const originalHost = (_this$diffEditorView20 = this.diffEditorView) === null || _this$diffEditorView20 === void 0 || (_this$diffEditorView22 = (_this$diffEditorView21 = _this$diffEditorView20.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView22 === void 0 ? void 0 : _this$diffEditorView22.call(_this$diffEditorView21);
3361
- const modifiedHost = (_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || (_this$diffEditorView25 = (_this$diffEditorView24 = _this$diffEditorView23.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView25 === void 0 ? void 0 : _this$diffEditorView25.call(_this$diffEditorView24);
3362
- if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
3363
- const originalRect = originalHost.getBoundingClientRect();
3364
- const modifiedRect = modifiedHost.getBoundingClientRect();
3365
- const originalCenter = originalRect.left + originalRect.width / 2;
3366
- const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
3367
- return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
3368
- }
3369
- const diffRect = diffRoot.getBoundingClientRect();
3370
- return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
3371
- }
3372
3755
  patchDiffUnchangedCenter(node, pairIndex = 0) {
3373
- node.classList.add("stream-monaco-clickable");
3374
- node.title = "Click to expand all unmodified lines";
3375
- 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
+ });
3376
3763
  const shouldUseMergedSecondary = mergeRole === "secondary";
3377
3764
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3378
- node.classList.toggle("stream-monaco-unchanged-merged-secondary", shouldUseMergedSecondary);
3379
- node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
3765
+ syncDiffUnchangedCenterNode(node, mergeRole);
3380
3766
  const primary = node.children.item(0);
3381
3767
  const meta = node.children.item(1);
3382
3768
  if (primary instanceof HTMLElement) primary.classList.add("stream-monaco-unchanged-primary");
3383
3769
  if (meta instanceof HTMLElement) {
3384
- var _countSource$textCont;
3770
+ var _countSource$textCont, _this$originalModel, _this$modifiedModel2;
3385
3771
  meta.classList.add("stream-monaco-unchanged-meta");
3386
3772
  const countSource = meta.querySelector(".count") ?? meta.firstElementChild;
3387
- 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");
3388
- const summaryLabel = unchangedRegionStyle === "metadata" ? this.resolveDiffMetadataLabel(node, pairIndex) ?? countText : countText;
3389
- 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);
3390
3786
  }
3391
- const action = node.querySelector("a");
3787
+ const action = findDiffUnchangedExpandAction(node);
3392
3788
  if (action instanceof HTMLElement) {
3393
- action.classList.add("stream-monaco-unchanged-expand");
3394
- action.dataset.streamMonacoLabel = "Expand all";
3395
- action.title = "Expand all unmodified lines";
3396
- action.setAttribute("aria-label", "Expand all unmodified lines");
3397
- action.toggleAttribute("aria-hidden", shouldUseMergedSecondary);
3398
- action.tabIndex = shouldUseMergedSecondary ? -1 : 0;
3789
+ syncDiffUnchangedExpandAction(action, shouldUseMergedSecondary);
3399
3790
  if (action.dataset.streamMonacoExpandPatched !== "true") {
3400
3791
  action.dataset.streamMonacoExpandPatched = "true";
3401
3792
  const handleCaptureExpand = () => {
@@ -3413,28 +3804,21 @@ var DiffEditorManager = class DiffEditorManager {
3413
3804
  if (node.dataset.streamMonacoCenterPatched !== "true") {
3414
3805
  node.dataset.streamMonacoCenterPatched = "true";
3415
3806
  this.bindFocusWithinClass(this.diffUnchangedRegionDisposables, node, "stream-monaco-focus-within");
3416
- const activate = () => {
3417
- const action$1 = node.querySelector("a");
3418
- if (action$1 instanceof HTMLElement) {
3419
- this.capturePreviousDiffUnchangedState();
3420
- action$1.click();
3421
- }
3422
- };
3423
3807
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "click", (event) => {
3424
3808
  const mouseEvent = event;
3425
- if (mouseEvent.button !== 0) return;
3426
- const target = event.target instanceof HTMLElement ? event.target : null;
3427
- if (target === null || target === void 0 ? void 0 : target.closest("a, .breadcrumb-item")) return;
3809
+ if (!shouldHandleDiffUnchangedCenterClick(mouseEvent)) return;
3428
3810
  event.preventDefault();
3429
3811
  this.hideAllDiffUnchangedBridgeEntries();
3430
- activate();
3812
+ if (!activateDiffUnchangedExpandAction(node, () => {
3813
+ this.capturePreviousDiffUnchangedState();
3814
+ })) return;
3431
3815
  this.scheduleCapturePersistedDiffUnchangedState(1);
3432
3816
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3433
3817
  });
3434
3818
  }
3435
3819
  }
3436
3820
  renderMergedDiffUnchangedBridge(secondaryNode, primaryNode, pairIndex, pairCount) {
3437
- var _countSource$textCont2, _secondaryNode$closes;
3821
+ var _countSource$textCont2, _this$originalModel2, _this$modifiedModel3, _this$diffEditorView14, _this$diffEditorView15, _secondaryNode$closes;
3438
3822
  if (!this.lastContainer) return null;
3439
3823
  const overlay = this.ensureDiffUnchangedBridgeOverlay();
3440
3824
  if (!overlay) return null;
@@ -3443,9 +3827,19 @@ var DiffEditorManager = class DiffEditorManager {
3443
3827
  const primaryRect = primaryNode.getBoundingClientRect();
3444
3828
  const primaryStyle = globalThis.getComputedStyle(primaryNode);
3445
3829
  const countSource = primaryNode.querySelector(".stream-monaco-unchanged-count") ?? secondaryNode.querySelector(".stream-monaco-unchanged-count");
3446
- 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");
3447
3831
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3448
- 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
+ });
3449
3843
  const editorSurface = primaryNode.closest(".monaco-editor") ?? primaryNode;
3450
3844
  const editorSurfaceStyle = globalThis.getComputedStyle(editorSurface);
3451
3845
  const primaryHidden = primaryNode.parentElement;
@@ -3454,7 +3848,13 @@ var DiffEditorManager = class DiffEditorManager {
3454
3848
  const secondaryWidget = secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.parentElement;
3455
3849
  const topHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".top")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".top"));
3456
3850
  const bottomHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".bottom")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".bottom"));
3457
- 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
+ });
3458
3858
  const key = this.getDiffUnchangedBridgeKey(secondaryNode, primaryNode);
3459
3859
  secondaryNode.classList.add("stream-monaco-unchanged-bridge-source");
3460
3860
  primaryNode.classList.add("stream-monaco-unchanged-bridge-source");
@@ -3466,42 +3866,24 @@ var DiffEditorManager = class DiffEditorManager {
3466
3866
  const primaryAnchorRect = (primaryWidget === null || primaryWidget === void 0 ? void 0 : primaryWidget.getBoundingClientRect()) ?? primaryRect;
3467
3867
  const secondaryMargin = (_secondaryNode$closes = secondaryNode.closest(".monaco-editor")) === null || _secondaryNode$closes === void 0 ? void 0 : _secondaryNode$closes.querySelector(".margin");
3468
3868
  const secondaryMarginRect = secondaryMargin === null || secondaryMargin === void 0 ? void 0 : secondaryMargin.getBoundingClientRect();
3469
- const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? this.resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3869
+ const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3470
3870
  const bridgeLeftInset = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.leftInset) ?? 0;
3471
3871
  const bridgeRailWidth = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.width) ?? (secondaryMarginRect === null || secondaryMarginRect === void 0 ? void 0 : secondaryMarginRect.width) ?? null;
3472
- bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + this.lastContainer.scrollLeft + bridgeLeftInset}px`;
3473
- bridge.style.top = `${primaryAnchorRect.top - containerRect.top + this.lastContainer.scrollTop}px`;
3474
- bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
3475
- bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
3476
- bridge.style.color = primaryStyle.color;
3477
- bridge.style.fontFamily = primaryStyle.fontFamily;
3478
- bridge.style.fontSize = primaryStyle.fontSize;
3479
- bridge.style.lineHeight = primaryStyle.lineHeight;
3480
- bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
3481
- bridge.style.setProperty("--stream-monaco-editor-bg", editorSurfaceStyle.backgroundColor);
3482
- bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
3483
- if (bridgeRailWidth) bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
3484
- else bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
3485
- 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");
3486
- summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
3487
- const summaryLabel = metadataLabel || countText;
3488
- const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
3489
- summary.disabled = !summaryInteractive;
3490
- summary.tabIndex = summaryInteractive ? 0 : -1;
3491
- if (summaryInteractive) {
3492
- summary.removeAttribute("aria-hidden");
3493
- summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
3494
- summary.title = "Expand all unmodified lines";
3495
- } else if (unchangedRegionStyle === "simple") {
3496
- summary.setAttribute("aria-hidden", "true");
3497
- summary.removeAttribute("aria-label");
3498
- summary.title = "";
3499
- } else {
3500
- summary.removeAttribute("aria-hidden");
3501
- summary.removeAttribute("aria-label");
3502
- summary.title = "";
3503
- }
3504
- 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);
3505
3887
  if (unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic") {
3506
3888
  this.syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle ?? null, showBottomHandle, bottomHandle ?? null);
3507
3889
  if (entry.rail && entry.rail.parentElement !== bridge) bridge.prepend(entry.rail);
@@ -3510,7 +3892,7 @@ var DiffEditorManager = class DiffEditorManager {
3510
3892
  entry.rail.setAttribute("aria-hidden", "true");
3511
3893
  }
3512
3894
  entry.activate = () => {
3513
- const action = primaryNode.querySelector("a, button") ?? secondaryNode.querySelector("a, button");
3895
+ const action = findDiffUnchangedActivationAction(primaryNode, secondaryNode);
3514
3896
  if (action instanceof HTMLElement) {
3515
3897
  this.capturePreviousDiffUnchangedState();
3516
3898
  action.click();
@@ -3547,7 +3929,7 @@ var DiffEditorManager = class DiffEditorManager {
3547
3929
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3548
3930
  return;
3549
3931
  }
3550
- this.dispatchSyntheticMouseDown(node);
3932
+ dispatchSyntheticPrimaryMouseDown(node);
3551
3933
  this.scheduleCapturePersistedDiffUnchangedState(1);
3552
3934
  });
3553
3935
  }
@@ -3676,8 +4058,12 @@ var DiffEditorManager = class DiffEditorManager {
3676
4058
  overlay.className = "stream-monaco-diff-hunk-overlay";
3677
4059
  this.diffHunkOverlay = overlay;
3678
4060
  this.lastContainer.append(overlay);
3679
- this.diffHunkUpperNode = this.createDiffHunkActionNode("upper");
3680
- 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());
3681
4067
  overlay.append(this.diffHunkUpperNode, this.diffHunkLowerNode);
3682
4068
  const originalEditor = this.diffEditorView.getOriginalEditor();
3683
4069
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
@@ -3720,71 +4106,27 @@ var DiffEditorManager = class DiffEditorManager {
3720
4106
  if (this.diffHunkUpperNode) this.diffHunkUpperNode.style.display = "none";
3721
4107
  if (this.diffHunkLowerNode) this.diffHunkLowerNode.style.display = "none";
3722
4108
  }
3723
- inferInlineDiffHunkHoverSide(change, event) {
3724
- var _event$target$positio;
3725
- const targetElement = event.target.element instanceof HTMLElement ? event.target.element : null;
3726
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
3727
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
3728
- if (!this.hasModifiedLines(change)) return "upper";
3729
- if (!this.hasOriginalLines(change)) return "lower";
3730
- const hoverLine = ((_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber) ?? 0;
3731
- const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
3732
- return hoverLine < modifiedAnchor ? "upper" : "lower";
3733
- }
3734
- hasOriginalLines(change) {
3735
- return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
3736
- }
3737
- hasModifiedLines(change) {
3738
- return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
3739
- }
3740
- distanceToLineChange(side, change, line) {
3741
- const hasRange = side === "original" ? this.hasOriginalLines(change) : this.hasModifiedLines(change);
3742
- const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
3743
- const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
3744
- if (hasRange) {
3745
- if (line < start) return start - line;
3746
- if (line > end) return line - end;
3747
- return 0;
3748
- }
3749
- const fallbackAnchor = Math.max(1, start || end || 1);
3750
- return Math.abs(line - fallbackAnchor);
3751
- }
3752
- findLineChangeByHoverLine(side, line) {
3753
- if (this.diffHunkLineChanges.length === 0) return null;
3754
- let best = null;
3755
- let bestDistance = Number.POSITIVE_INFINITY;
3756
- for (const change of this.diffHunkLineChanges) {
3757
- const distance = this.distanceToLineChange(side, change, line);
3758
- if (distance < bestDistance) {
3759
- bestDistance = distance;
3760
- best = change;
3761
- if (distance === 0) break;
3762
- }
3763
- }
3764
- if (bestDistance > 2) return null;
3765
- return best;
3766
- }
3767
4109
  handleDiffHunkMouseMove(side, event) {
3768
- var _event$target$positio2;
3769
- 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;
3770
4112
  if (!line) {
3771
4113
  this.scheduleHideDiffHunkActions(120);
3772
4114
  return;
3773
4115
  }
3774
- const change = this.findLineChangeByHoverLine(side, line);
4116
+ const change = findLineChangeByHoverLine(this.diffHunkLineChanges, side, line);
3775
4117
  if (!change) {
3776
4118
  this.scheduleHideDiffHunkActions(120);
3777
4119
  return;
3778
4120
  }
3779
4121
  this.cancelScheduledHideDiffHunkActions();
3780
4122
  this.diffHunkActiveChange = change;
3781
- 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;
3782
4124
  this.repositionDiffHunkNodes();
3783
4125
  }
3784
4126
  isOriginalEditorCollapsed() {
3785
- var _this$diffEditorView$4, _this$diffEditorView$5;
4127
+ var _this$diffEditorView$2, _this$diffEditorView$3;
3786
4128
  if (!this.diffEditorView) return true;
3787
- 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);
3788
4130
  return !info || info.width < 24;
3789
4131
  }
3790
4132
  isDiffInlineMode() {
@@ -3793,40 +4135,6 @@ var DiffEditorManager = class DiffEditorManager {
3793
4135
  if (typeof HTMLElement !== "undefined" && diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
3794
4136
  return this.isOriginalEditorCollapsed();
3795
4137
  }
3796
- getEditorBySide(side) {
3797
- if (!this.diffEditorView) return null;
3798
- return side === "original" ? this.diffEditorView.getOriginalEditor() : this.diffEditorView.getModifiedEditor();
3799
- }
3800
- getFullLineRange(model, startLine, endLine) {
3801
- if (endLine < startLine) return null;
3802
- const lineCount = model.getLineCount();
3803
- if (lineCount < 1) return null;
3804
- const start = Math.max(1, Math.min(startLine, lineCount));
3805
- const end = Math.max(start, Math.min(endLine, lineCount));
3806
- if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
3807
- return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
3808
- }
3809
- getLinesText(model, startLine, endLine) {
3810
- const range = this.getFullLineRange(model, startLine, endLine);
3811
- if (!range) return "";
3812
- return model.getValueInRange(range);
3813
- }
3814
- getInsertRangeBeforeLine(model, lineNumber) {
3815
- const lineCount = model.getLineCount();
3816
- if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3817
- if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
3818
- const lastLine = lineCount;
3819
- const lastColumn = model.getLineMaxColumn(lastLine);
3820
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3821
- }
3822
- getInsertRangeAfterLine(model, lineNumber) {
3823
- const lineCount = model.getLineCount();
3824
- if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3825
- if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
3826
- const lastLine = lineCount;
3827
- const lastColumn = model.getLineMaxColumn(lastLine);
3828
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3829
- }
3830
4138
  applyDiffModelLanguage(models, codeLanguage) {
3831
4139
  if (!codeLanguage) return;
3832
4140
  const lang = processedLanguage(codeLanguage);
@@ -3838,8 +4146,8 @@ var DiffEditorManager = class DiffEditorManager {
3838
4146
  if (!this.diffEditorView || !viewState) return;
3839
4147
  const restore = () => {
3840
4148
  try {
3841
- var _this$diffEditorView26;
3842
- (_this$diffEditorView26 = this.diffEditorView) === null || _this$diffEditorView26 === void 0 || _this$diffEditorView26.restoreViewState(viewState);
4149
+ var _this$diffEditorView16;
4150
+ (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.restoreViewState(viewState);
3843
4151
  } catch {}
3844
4152
  };
3845
4153
  restore();
@@ -3857,7 +4165,7 @@ var DiffEditorManager = class DiffEditorManager {
3857
4165
  this.pendingPreparedDiffViewModel = null;
3858
4166
  }
3859
4167
  syncDiffKnownValues() {
3860
- var _this$diffEditorView27, _this$diffEditorView28, _this$diffEditorView29, _this$diffHeightManag4;
4168
+ var _this$diffEditorView17, _this$diffEditorView18, _this$diffEditorView19, _this$diffHeightManag4;
3861
4169
  if (this.originalModel) this.lastKnownOriginalCode = this.originalModel.getValue();
3862
4170
  if (this.modifiedModel) {
3863
4171
  this.lastKnownModifiedCode = this.modifiedModel.getValue();
@@ -3866,67 +4174,15 @@ var DiffEditorManager = class DiffEditorManager {
3866
4174
  this.lastKnownModifiedDirty = false;
3867
4175
  this._hasScrollBar = false;
3868
4176
  this.cachedComputedHeightDiff = this.computedHeight();
3869
- this.cachedScrollHeightDiff = ((_this$diffEditorView27 = this.diffEditorView) === null || _this$diffEditorView27 === void 0 || (_this$diffEditorView29 = (_this$diffEditorView28 = _this$diffEditorView27.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView29 === void 0 ? void 0 : _this$diffEditorView29.call(_this$diffEditorView28)) ?? this.cachedScrollHeightDiff;
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;
3870
4178
  (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3871
4179
  }
3872
- applyDefaultDiffHunkAction(context) {
3873
- const { action, side, lineChange } = context;
3874
- if (!this.originalModel || !this.modifiedModel) return;
3875
- const hasOriginal = this.hasOriginalLines(lineChange);
3876
- const hasModified = this.hasModifiedLines(lineChange);
3877
- if (action === "revert" && side === "upper") {
3878
- if (!hasOriginal) return;
3879
- const text = this.getLinesText(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3880
- if (!text) return;
3881
- const range = hasModified ? this.getInsertRangeBeforeLine(this.modifiedModel, lineChange.modifiedStartLineNumber) : this.getInsertRangeAfterLine(this.modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
3882
- this.modifiedModel.applyEdits([{
3883
- range,
3884
- text,
3885
- forceMoveMarkers: true
3886
- }]);
3887
- return;
3888
- }
3889
- if (action === "revert" && side === "lower") {
3890
- if (!hasModified) return;
3891
- const range = this.getFullLineRange(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3892
- if (!range) return;
3893
- this.modifiedModel.applyEdits([{
3894
- range,
3895
- text: "",
3896
- forceMoveMarkers: true
3897
- }]);
3898
- return;
3899
- }
3900
- if (action === "stage" && side === "upper") {
3901
- if (!hasOriginal) return;
3902
- const range = this.getFullLineRange(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3903
- if (!range) return;
3904
- this.originalModel.applyEdits([{
3905
- range,
3906
- text: "",
3907
- forceMoveMarkers: true
3908
- }]);
3909
- return;
3910
- }
3911
- if (action === "stage" && side === "lower") {
3912
- if (!hasModified) return;
3913
- const text = this.getLinesText(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3914
- if (!text) return;
3915
- const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
3916
- const range = this.getInsertRangeAfterLine(this.originalModel, anchor);
3917
- this.originalModel.applyEdits([{
3918
- range,
3919
- text,
3920
- forceMoveMarkers: true
3921
- }]);
3922
- }
3923
- }
3924
4180
  async applyDiffHunkAction(side, action) {
3925
4181
  if (!this.diffHunkActiveChange || !this.originalModel || !this.modifiedModel) return;
3926
4182
  if (this.diffHunkActionInFlight) return;
3927
4183
  this.diffHunkActionInFlight = true;
3928
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
3929
- this.setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
4184
+ setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
4185
+ setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
3930
4186
  try {
3931
4187
  this.flushOriginalAppendBufferSync();
3932
4188
  this.flushModifiedAppendBufferSync();
@@ -3943,39 +4199,13 @@ var DiffEditorManager = class DiffEditorManager {
3943
4199
  } catch (error$1) {
3944
4200
  console.warn("onDiffHunkAction callback threw an error:", error$1);
3945
4201
  }
3946
- if (allowDefault) this.applyDefaultDiffHunkAction(context);
4202
+ if (allowDefault) applyDefaultDiffHunkAction(context);
3947
4203
  this.syncDiffKnownValues();
3948
4204
  this.hideDiffHunkActions();
3949
4205
  } finally {
3950
4206
  this.diffHunkActionInFlight = false;
3951
4207
  }
3952
4208
  }
3953
- setDiffHunkNodeEnabled(node, enabled) {
3954
- if (!node) return;
3955
- const buttons = node.querySelectorAll("button");
3956
- buttons.forEach((button) => {
3957
- button.disabled = !enabled;
3958
- });
3959
- }
3960
- positionDiffHunkNode(node, side, anchorLine, extraOffsetY = 0) {
3961
- var _editor$getScrollTop2;
3962
- if (!this.diffHunkOverlay) return;
3963
- const editor = this.getEditorBySide(side);
3964
- if (!editor) return;
3965
- const host = editor.getContainerDomNode();
3966
- const line = Math.max(1, anchorLine);
3967
- const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop2 = editor.getScrollTop) === null || _editor$getScrollTop2 === void 0 ? void 0 : _editor$getScrollTop2.call(editor)) ?? 0);
3968
- const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
3969
- const nodeWidth = node.offsetWidth || 130;
3970
- const nodeHeight = node.offsetHeight || 30;
3971
- const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
3972
- const hostTop = host.offsetTop;
3973
- const minTop = hostTop + 4;
3974
- const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
3975
- const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
3976
- node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
3977
- node.style.display = "flex";
3978
- }
3979
4209
  repositionDiffHunkNodes() {
3980
4210
  if (!this.diffHunkActiveChange) {
3981
4211
  this.hideDiffHunkActions();
@@ -3984,22 +4214,22 @@ var DiffEditorManager = class DiffEditorManager {
3984
4214
  if (!this.diffHunkUpperNode || !this.diffHunkLowerNode) return;
3985
4215
  if (!this.diffEditorView) return;
3986
4216
  const change = this.diffHunkActiveChange;
3987
- const hasOriginal = this.hasOriginalLines(change);
3988
- const hasModified = this.hasModifiedLines(change);
3989
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
3990
- 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);
3991
4221
  const inlineMode = this.isDiffInlineMode();
3992
4222
  if (inlineMode) {
3993
4223
  const inlineHoverSide = this.diffHunkActiveHoverSide ?? (hasOriginal && !hasModified ? "upper" : "lower");
3994
4224
  if (inlineHoverSide === "upper" && hasOriginal) {
3995
4225
  const upperAnchor = Math.max(1, change.modifiedStartLineNumber - 1 || change.modifiedEndLineNumber || 1);
3996
- this.positionDiffHunkNode(this.diffHunkUpperNode, "modified", upperAnchor);
4226
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getModifiedEditor(), upperAnchor);
3997
4227
  this.diffHunkLowerNode.style.display = "none";
3998
4228
  return;
3999
4229
  }
4000
4230
  if (hasModified) {
4001
4231
  const lowerAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
4002
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4232
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
4003
4233
  this.diffHunkUpperNode.style.display = "none";
4004
4234
  return;
4005
4235
  }
@@ -4007,13 +4237,12 @@ var DiffEditorManager = class DiffEditorManager {
4007
4237
  return;
4008
4238
  }
4009
4239
  if (hasOriginal) {
4010
- const upperSide = "original";
4011
4240
  const upperAnchor = change.originalStartLineNumber;
4012
- this.positionDiffHunkNode(this.diffHunkUpperNode, upperSide, upperAnchor);
4241
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getOriginalEditor(), upperAnchor);
4013
4242
  } else this.diffHunkUpperNode.style.display = "none";
4014
4243
  if (hasModified) {
4015
4244
  const lowerAnchor = change.modifiedStartLineNumber;
4016
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4245
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
4017
4246
  } else this.diffHunkLowerNode.style.display = "none";
4018
4247
  }
4019
4248
  scheduleFlushAppendBufferDiff() {
@@ -4052,26 +4281,20 @@ var DiffEditorManager = class DiffEditorManager {
4052
4281
  this.appendToModel(this.originalModel, text);
4053
4282
  }
4054
4283
  computeRawHeight() {
4055
- var _originalEditor$getMo, _modifiedEditor$getMo2, _originalEditor$getSc5, _modifiedEditor$getSc10;
4056
- if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
4057
- const modifiedEditor = this.diffEditorView.getModifiedEditor();
4058
- const originalEditor = this.diffEditorView.getOriginalEditor();
4059
- const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
4060
- const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
4061
- const mCount = ((_modifiedEditor$getMo2 = modifiedEditor.getModel()) === null || _modifiedEditor$getMo2 === void 0 ? void 0 : _modifiedEditor$getMo2.getLineCount()) ?? 1;
4062
- const lineCount = Math.max(oCount, mCount);
4063
- const fromLines = lineCount * lineHeight + padding;
4064
- 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);
4065
- const desired = Math.max(fromLines, scrollH);
4066
- return Math.min(desired, this.maxHeightValue);
4284
+ return computeDiffRawHeight({
4285
+ diffEditorView: this.diffEditorView,
4286
+ maxHeightValue: this.maxHeightValue
4287
+ });
4067
4288
  }
4068
4289
  computedHeight() {
4069
- const rawHeight = this.computeRawHeight();
4070
- if (!this.isDiffInlineMode()) return rawHeight;
4071
- if (!this.inlineDiffStreamingPresentationActive && this.inlineDiffStreamingHeightFloor <= 0) return rawHeight;
4072
- const lockedHeight = Math.max(rawHeight, this.inlineDiffStreamingHeightFloor);
4073
- this.inlineDiffStreamingHeightFloor = lockedHeight;
4074
- return lockedHeight;
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;
4075
4298
  }
4076
4299
  eagerlyGrowDiffContainerHeight() {
4077
4300
  var _this$lastContainer$g, _this$lastContainer10;
@@ -4116,17 +4339,22 @@ var DiffEditorManager = class DiffEditorManager {
4116
4339
  if (this._hasScrollBar) return true;
4117
4340
  const m = this.measureViewportDiff();
4118
4341
  if (!m) return false;
4119
- const epsilon = Math.max(2, Math.round(m.lineHeight / 8));
4120
- return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
4342
+ return this._hasScrollBar = hasVerticalScrollbar(m);
4121
4343
  }
4122
4344
  userIsNearBottomDiff() {
4123
4345
  if (!this.diffEditorView) return true;
4124
4346
  const m = this.measureViewportDiff();
4125
4347
  if (!m || !m.li) return true;
4126
- const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
4127
- const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
4128
- const distance = m.scrollHeight - (m.scrollTop + m.li.height);
4129
- 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
+ });
4130
4358
  }
4131
4359
  maybeScrollDiffToBottom(targetLine, prevLineOverride) {
4132
4360
  this.rafScheduler.schedule("maybe-scroll-diff", () => {
@@ -4202,7 +4430,7 @@ var DiffEditorManager = class DiffEditorManager {
4202
4430
  }
4203
4431
  performRevealDiffTicketed(line, ticket) {
4204
4432
  this.rafScheduler.schedule("revealDiff", () => {
4205
- var _editor;
4433
+ var _editor$1;
4206
4434
  if (this.diffScrollWatcher) {
4207
4435
  log("diff", "performRevealDiffTicketed - suppressing watcher", {
4208
4436
  ticket,
@@ -4217,16 +4445,11 @@ var DiffEditorManager = class DiffEditorManager {
4217
4445
  line
4218
4446
  });
4219
4447
  const strategy = this.diffHideUnchangedRegionsDeferred ? "bottom" : this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
4220
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
4221
- 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;
4222
4450
  try {
4223
4451
  const me = this.diffEditorView.getModifiedEditor();
4224
- if (strategy === "bottom") if (typeof smooth !== "undefined") me.revealLine(line, smooth);
4225
- else me.revealLine(line);
4226
- else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
4227
- else me.revealLineInCenter(line);
4228
- else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
4229
- else me.revealLineInCenterIfOutsideViewport(line);
4452
+ revealEditorLine(me, line, strategy, smooth);
4230
4453
  } catch {
4231
4454
  try {
4232
4455
  this.diffEditorView.getModifiedEditor().revealLine(line);
@@ -4238,8 +4461,8 @@ var DiffEditorManager = class DiffEditorManager {
4238
4461
  lastRevealLineDiff: this.lastRevealLineDiff
4239
4462
  });
4240
4463
  try {
4241
- var _this$diffEditorView30, _this$diffEditorView31, _this$diffEditorView32;
4242
- this.lastScrollTopDiff = ((_this$diffEditorView30 = this.diffEditorView) === null || _this$diffEditorView30 === void 0 || (_this$diffEditorView32 = (_this$diffEditorView31 = _this$diffEditorView30.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView32 === void 0 ? void 0 : _this$diffEditorView32.call(_this$diffEditorView31)) ?? 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;
4243
4466
  } catch {}
4244
4467
  });
4245
4468
  }
@@ -4247,11 +4470,10 @@ var DiffEditorManager = class DiffEditorManager {
4247
4470
  var _editor2;
4248
4471
  if (!this.diffEditorView) return;
4249
4472
  if (ticket !== this.revealTicketDiff) return;
4250
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
4251
- 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;
4252
4475
  const me = this.diffEditorView.getModifiedEditor();
4253
- if (typeof immediate !== "undefined") me.revealLine(line, immediate);
4254
- else me.revealLine(line);
4476
+ revealEditorLine(me, line, "bottom", immediate);
4255
4477
  this.measureViewportDiff();
4256
4478
  log("diff", "performImmediateRevealDiff", {
4257
4479
  line,
@@ -4271,22 +4493,7 @@ var DiffEditorManager = class DiffEditorManager {
4271
4493
  });
4272
4494
  }
4273
4495
  waitForHeightAppliedDiff(target, timeoutMs = 500) {
4274
- return new Promise((resolve) => {
4275
- const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
4276
- const check = () => {
4277
- const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
4278
- if (applied >= target - 1) {
4279
- resolve();
4280
- return;
4281
- }
4282
- if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
4283
- resolve();
4284
- return;
4285
- }
4286
- requestAnimationFrame(check);
4287
- };
4288
- check();
4289
- });
4496
+ return waitForElementHeightApplied(this.lastContainer, target, timeoutMs);
4290
4497
  }
4291
4498
  async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
4292
4499
  var _me$getScrollHeight2, _me$getOption, _oEditor$onDidLayoutC, _mEditor$onDidLayoutC, _oEditor$onDidContent, _mEditor$onDidContent;
@@ -4435,8 +4642,8 @@ var DiffEditorManager = class DiffEditorManager {
4435
4642
  if (this.lastContainer) {
4436
4643
  this.lastContainer.style.overflow = "hidden";
4437
4644
  if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
4438
- var _this$modifiedModel3;
4439
- 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());
4440
4647
  }
4441
4648
  }
4442
4649
  });
@@ -4459,13 +4666,14 @@ var DiffEditorManager = class DiffEditorManager {
4459
4666
  if (this.lastContainer) {
4460
4667
  this.lastContainer.style.overflow = "hidden";
4461
4668
  if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
4462
- var _this$modifiedModel4;
4463
- 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());
4464
4671
  }
4465
4672
  }
4466
4673
  });
4467
4674
  });
4468
4675
  mEditor.onDidChangeModelContent(() => {
4676
+ if (this.programmaticModifiedContentChangeDepth > 0) return;
4469
4677
  this.lastKnownModifiedDirty = true;
4470
4678
  this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
4471
4679
  });
@@ -4609,7 +4817,7 @@ var DiffEditorManager = class DiffEditorManager {
4609
4817
  if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
4610
4818
  }
4611
4819
  async setDiffModels(models, options = {}) {
4612
- 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;
4613
4821
  if (!this.diffEditorView) return;
4614
4822
  const transitionRequestId = ++this.diffModelTransitionRequestId;
4615
4823
  this.preserveNativeDiffDecorationsOnStaleAppend = false;
@@ -4617,8 +4825,8 @@ var DiffEditorManager = class DiffEditorManager {
4617
4825
  const nextOriginal = models.original;
4618
4826
  const nextModified = models.modified;
4619
4827
  this.applyDiffModelLanguage(models, options.codeLanguage);
4620
- const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getValue()) ?? null;
4621
- 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;
4622
4830
  const nextOriginalValue = nextOriginal.getValue();
4623
4831
  const nextModifiedValue = nextModified.getValue();
4624
4832
  const sameContent = currentOriginalValue === nextOriginalValue && currentModifiedValue === nextModifiedValue;
@@ -4674,8 +4882,8 @@ var DiffEditorManager = class DiffEditorManager {
4674
4882
  this.queuePendingDiffScrollRestore(preservedScrollPosition, shouldRestorePersistedUnchangedState ? 2 : 0);
4675
4883
  if (shouldRestorePersistedUnchangedState) this.capturePersistedDiffUnchangedState();
4676
4884
  const applyModelSwap = () => {
4677
- var _this$diffEditorView33;
4678
- (_this$diffEditorView33 = this.diffEditorView) === null || _this$diffEditorView33 === void 0 || _this$diffEditorView33.setModel(nextModelTarget);
4885
+ var _this$diffEditorView23;
4886
+ (_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || _this$diffEditorView23.setModel(nextModelTarget);
4679
4887
  };
4680
4888
  if (preserveViewState) this.withLockedDiffScrollPosition(applyModelSwap);
4681
4889
  else applyModelSwap();
@@ -4690,8 +4898,8 @@ var DiffEditorManager = class DiffEditorManager {
4690
4898
  this.lastKnownModifiedLineCount = nextModified.getLineCount();
4691
4899
  this.lastKnownModifiedDirty = false;
4692
4900
  this._hasScrollBar = false;
4693
- 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;
4694
- 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;
4695
4903
  this.cachedComputedHeightDiff = this.computedHeight();
4696
4904
  this.diffHunkLineChanges = this.getEffectiveLineChanges();
4697
4905
  this.hideDiffHunkActions();
@@ -4927,11 +5135,13 @@ var DiffEditorManager = class DiffEditorManager {
4927
5135
  const lastColumn$1 = model.getLineMaxColumn(prevLine);
4928
5136
  const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
4929
5137
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4930
- model.applyEdits([{
4931
- range: range$1,
4932
- text: part,
4933
- forceMoveMarkers: true
4934
- }]);
5138
+ this.runAsProgrammaticModifiedContentChange(() => {
5139
+ model.applyEdits([{
5140
+ range: range$1,
5141
+ text: part,
5142
+ forceMoveMarkers: true
5143
+ }]);
5144
+ });
4935
5145
  this.lastKnownModifiedCode = model.getValue();
4936
5146
  const newLine$1 = model.getLineCount();
4937
5147
  this.lastKnownModifiedLineCount = newLine$1;
@@ -4967,11 +5177,13 @@ var DiffEditorManager = class DiffEditorManager {
4967
5177
  const lastColumn = model.getLineMaxColumn(prevLine);
4968
5178
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
4969
5179
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4970
- model.applyEdits([{
4971
- range,
4972
- text,
4973
- forceMoveMarkers: true
4974
- }]);
5180
+ this.runAsProgrammaticModifiedContentChange(() => {
5181
+ model.applyEdits([{
5182
+ range,
5183
+ text,
5184
+ forceMoveMarkers: true
5185
+ }]);
5186
+ });
4975
5187
  this.lastKnownModifiedCode = model.getValue();
4976
5188
  const newLine = model.getLineCount();
4977
5189
  this.lastKnownModifiedLineCount = newLine;
@@ -4984,17 +5196,19 @@ var DiffEditorManager = class DiffEditorManager {
4984
5196
  else this.maybeScrollDiffToBottom(newLine, prevLine);
4985
5197
  if (suppressedByFlush) watcherApi.setSuppressed(false);
4986
5198
  try {
4987
- var _this$diffEditorView34, _this$diffEditorView35, _this$diffEditorView36;
4988
- this.lastScrollTopDiff = ((_this$diffEditorView34 = this.diffEditorView) === null || _this$diffEditorView34 === void 0 || (_this$diffEditorView36 = (_this$diffEditorView35 = _this$diffEditorView34.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView36 === void 0 ? void 0 : _this$diffEditorView36.call(_this$diffEditorView35)) ?? 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;
4989
5201
  } catch {}
4990
5202
  }
4991
5203
  applyMinimalEditToModel(model, prev, next) {
4992
- const maxChars = minimalEditMaxChars;
4993
- const ratio = minimalEditMaxChangeRatio;
5204
+ const maxChars = this.minimalEditMaxCharsValue;
5205
+ const ratio = this.minimalEditMaxChangeRatioValue;
4994
5206
  const maxLen = Math.max(prev.length, next.length);
4995
5207
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
4996
5208
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
4997
- model.setValue(next);
5209
+ this.applyModelEdit(model, () => {
5210
+ model.setValue(next);
5211
+ });
4998
5212
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
4999
5213
  return;
5000
5214
  }
@@ -5004,11 +5218,13 @@ var DiffEditorManager = class DiffEditorManager {
5004
5218
  const rangeStart = model.getPositionAt(start);
5005
5219
  const rangeEnd = model.getPositionAt(endPrevIncl + 1);
5006
5220
  const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
5007
- model.applyEdits([{
5008
- range,
5009
- text: replaceText,
5010
- forceMoveMarkers: true
5011
- }]);
5221
+ this.applyModelEdit(model, () => {
5222
+ model.applyEdits([{
5223
+ range,
5224
+ text: replaceText,
5225
+ forceMoveMarkers: true
5226
+ }]);
5227
+ });
5012
5228
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
5013
5229
  }
5014
5230
  appendToModel(model, appendText) {
@@ -5016,13 +5232,30 @@ var DiffEditorManager = class DiffEditorManager {
5016
5232
  const lastLine = model.getLineCount();
5017
5233
  const lastColumn = model.getLineMaxColumn(lastLine);
5018
5234
  const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
5019
- model.applyEdits([{
5020
- range,
5021
- text: appendText,
5022
- forceMoveMarkers: true
5023
- }]);
5235
+ this.applyModelEdit(model, () => {
5236
+ model.applyEdits([{
5237
+ range,
5238
+ text: appendText,
5239
+ forceMoveMarkers: true
5240
+ }]);
5241
+ });
5024
5242
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
5025
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
+ }
5026
5259
  };
5027
5260
 
5028
5261
  //#endregion
@@ -5034,6 +5267,8 @@ var EditorManager = class {
5034
5267
  pendingUpdate = null;
5035
5268
  _hasScrollBar = false;
5036
5269
  updateThrottleMs = 50;
5270
+ minimalEditMaxCharsValue = minimalEditMaxChars;
5271
+ minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
5037
5272
  lastUpdateFlushTime = 0;
5038
5273
  updateThrottleTimer = null;
5039
5274
  shouldAutoScroll = true;
@@ -5089,6 +5324,8 @@ var EditorManager = class {
5089
5324
  this.revealDebounceMsOption = revealDebounceMsOption;
5090
5325
  this.updateThrottleMsOption = updateThrottleMsOption;
5091
5326
  this.updateThrottleMs = this.updateThrottleMsOption ?? this.options.updateThrottleMs ?? 50;
5327
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
5328
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
5092
5329
  }
5093
5330
  cancelRafs() {
5094
5331
  this.rafScheduler.cancel("update");
@@ -5223,7 +5460,7 @@ var EditorManager = class {
5223
5460
  }
5224
5461
  performReveal(line, ticket) {
5225
5462
  this.rafScheduler.schedule("reveal", () => {
5226
- var _editor;
5463
+ var _editor$1;
5227
5464
  if (ticket !== this.revealTicket) {
5228
5465
  this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
5229
5466
  return;
@@ -5231,8 +5468,8 @@ var EditorManager = class {
5231
5468
  this.dlog("performReveal executing, ticket=", ticket, "line=", line);
5232
5469
  const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
5233
5470
  this.dlog("performReveal strategy=", strategy);
5234
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
5235
- 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;
5236
5473
  try {
5237
5474
  if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
5238
5475
  else this.editorView.revealLine(line);
@@ -5256,8 +5493,8 @@ var EditorManager = class {
5256
5493
  this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
5257
5494
  return;
5258
5495
  }
5259
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
5260
- 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;
5261
5498
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
5262
5499
  else this.editorView.revealLine(line);
5263
5500
  } catch {}
@@ -5269,8 +5506,8 @@ var EditorManager = class {
5269
5506
  try {
5270
5507
  var _editor3;
5271
5508
  if (!this.editorView) return;
5272
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
5273
- 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;
5274
5511
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
5275
5512
  else this.editorView.revealLine(line);
5276
5513
  } catch {}
@@ -5354,9 +5591,10 @@ var EditorManager = class {
5354
5591
  try {
5355
5592
  var _this$editorView8, _this$editorHeightMan, _this$editorHeightMan2;
5356
5593
  this.dlog("content-size-change frame");
5594
+ this.cachedLineCount = ((_this$editorView8 = this.editorView) === null || _this$editorView8 === void 0 || (_this$editorView8 = _this$editorView8.getModel()) === null || _this$editorView8 === void 0 ? void 0 : _this$editorView8.getLineCount()) ?? this.cachedLineCount;
5595
+ this.cachedComputedHeight = null;
5357
5596
  const m = this.measureViewport();
5358
5597
  this.dlog("content-size-change measure", m);
5359
- this.cachedLineCount = ((_this$editorView8 = this.editorView) === null || _this$editorView8 === void 0 || (_this$editorView8 = _this$editorView8.getModel()) === null || _this$editorView8 === void 0 ? void 0 : _this$editorView8.getLineCount()) ?? this.cachedLineCount;
5360
5598
  if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
5361
5599
  this.dlog("content-size-change skipped height update (suppressed)");
5362
5600
  return;
@@ -5410,6 +5648,7 @@ var EditorManager = class {
5410
5648
  if (model) {
5411
5649
  this.lastKnownCode = model.getValue();
5412
5650
  this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
5651
+ this.cachedComputedHeight = null;
5413
5652
  }
5414
5653
  this.lastKnownCodeDirty = false;
5415
5654
  }
@@ -5510,6 +5749,7 @@ var EditorManager = class {
5510
5749
  this.lastKnownCode = newCode;
5511
5750
  const newLineCount$1 = model.getLineCount();
5512
5751
  this.cachedLineCount = newLineCount$1;
5752
+ this.cachedComputedHeight = null;
5513
5753
  if (newLineCount$1 !== prevLineCount$1) {
5514
5754
  const shouldImmediate = this.shouldPerformImmediateReveal();
5515
5755
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
@@ -5538,7 +5778,6 @@ var EditorManager = class {
5538
5778
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
5539
5779
  const suffix = newCode.slice(prevCode.length);
5540
5780
  if (suffix) this.appendCode(suffix, codeLanguage);
5541
- this.lastKnownCode = newCode;
5542
5781
  return;
5543
5782
  }
5544
5783
  const prevLineCount = model.getLineCount();
@@ -5546,6 +5785,7 @@ var EditorManager = class {
5546
5785
  this.lastKnownCode = newCode;
5547
5786
  const newLineCount = model.getLineCount();
5548
5787
  this.cachedLineCount = newLineCount;
5788
+ this.cachedComputedHeight = null;
5549
5789
  if (newLineCount !== prevLineCount) {
5550
5790
  const shouldImmediate = this.shouldPerformImmediateReveal();
5551
5791
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
@@ -5571,8 +5811,8 @@ var EditorManager = class {
5571
5811
  if (!this.editorView) return;
5572
5812
  const model = this.editorView.getModel();
5573
5813
  if (!model) return;
5574
- const maxChars = minimalEditMaxChars;
5575
- const ratio = minimalEditMaxChangeRatio;
5814
+ const maxChars = this.minimalEditMaxCharsValue;
5815
+ const ratio = this.minimalEditMaxChangeRatioValue;
5576
5816
  const maxLen = Math.max(prev.length, next.length);
5577
5817
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
5578
5818
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
@@ -5635,6 +5875,7 @@ var EditorManager = class {
5635
5875
  const newLineCount = model.getLineCount();
5636
5876
  if (lastLine !== newLineCount) {
5637
5877
  this.cachedLineCount = newLineCount;
5878
+ this.cachedComputedHeight = null;
5638
5879
  const shouldImmediate = this.shouldPerformImmediateReveal();
5639
5880
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5640
5881
  const computed$1 = this.computedHeight(this.editorView);
@@ -5656,6 +5897,10 @@ var EditorManager = class {
5656
5897
  getEditorView() {
5657
5898
  return this.editorView;
5658
5899
  }
5900
+ getCode() {
5901
+ var _this$editorView9;
5902
+ 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;
5903
+ }
5659
5904
  setUpdateThrottleMs(ms) {
5660
5905
  this.updateThrottleMs = ms;
5661
5906
  if (!this.updateThrottleMs && this.updateThrottleTimer != null) {
@@ -5838,6 +6083,14 @@ async function ensureMonacoHighlighter(themes, languages$1) {
5838
6083
  */
5839
6084
  function clearHighlighterCache() {
5840
6085
  highlighterCache.clear();
6086
+ monacoHighlighterPromise = null;
6087
+ lastPatchedHighlighter = null;
6088
+ lastPatchedLanguages = /* @__PURE__ */ new Set();
6089
+ monacoThemeByKey.clear();
6090
+ monacoLanguageSet.clear();
6091
+ themeRegisterPromise = null;
6092
+ languagesRegistered = false;
6093
+ currentLanguages = [];
5841
6094
  }
5842
6095
  function serializeThemes(themes) {
5843
6096
  return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
@@ -6077,15 +6330,13 @@ let globalAppliedThemeName = null;
6077
6330
  function useMonaco(monacoOptions = {}) {
6078
6331
  var _monacoOptions$themes;
6079
6332
  const disposals = [];
6080
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.forEach((d) => d.dispose());
6081
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
6333
+ const pendingCreateDisposables = /* @__PURE__ */ new Map();
6082
6334
  let editorView = null;
6083
6335
  let editorMgr = null;
6084
6336
  let diffEditorView = null;
6085
6337
  let diffMgr = null;
6086
6338
  let originalModel = null;
6087
6339
  let modifiedModel = null;
6088
- let _hasScrollBar = false;
6089
6340
  const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
6090
6341
  if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
6091
6342
  const languages$1 = monacoOptions.languages ?? defaultLanguages;
@@ -6106,22 +6357,12 @@ function useMonaco(monacoOptions = {}) {
6106
6357
  };
6107
6358
  const maxHeightValue = getMaxHeightValue();
6108
6359
  const maxHeightCSS = getMaxHeightCSS();
6109
- let lastContainer = null;
6110
- let lastKnownCode = null;
6111
- const minimalEditMaxCharsLocal = monacoOptions.minimalEditMaxChars ?? minimalEditMaxChars;
6112
- const minimalEditMaxChangeRatioLocal = monacoOptions.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
6113
- let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
6114
- let lastFlushTime = 0;
6115
- let updateThrottleTimer = null;
6116
- let pendingUpdate = null;
6117
- let shouldAutoScroll = true;
6118
- const cachedComputedHeight = null;
6119
- const appendBuffer = [];
6120
- let appendBufferScheduled = false;
6360
+ let createRequestSeq = 0;
6361
+ let activeCreateRequestId = null;
6362
+ let activeCreateKind = null;
6363
+ let queuedEditorUpdateDuringCreate = null;
6121
6364
  const currentTheme = computed(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
6122
6365
  let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
6123
- let themeWatcher = null;
6124
- const rafScheduler = createRafScheduler();
6125
6366
  async function tryLoadAndSetShikiTheme(highlighter, themeName) {
6126
6367
  if (!highlighter || typeof highlighter.setTheme !== "function") return;
6127
6368
  try {
@@ -6192,326 +6433,206 @@ function useMonaco(monacoOptions = {}) {
6192
6433
  const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
6193
6434
  await registerMonacoThemes(list, languages$1);
6194
6435
  }
6195
- function hasVerticalScrollbar() {
6196
- if (!editorView) return false;
6197
- if (_hasScrollBar) return true;
6198
- const ch = cachedComputedHeight ?? computedHeight(editorView);
6199
- return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
6200
- }
6201
- let revealDebounceId = null;
6202
- const revealDebounceMs = 75;
6203
- function maybeScrollToBottom(targetLine) {
6204
- if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
6205
- const model = editorView.getModel();
6206
- const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
6207
- if (revealDebounceId != null) {
6208
- clearTimeout(revealDebounceId);
6209
- revealDebounceId = null;
6210
- }
6211
- revealDebounceId = setTimeout(() => {
6212
- revealDebounceId = null;
6213
- rafScheduler.schedule("reveal", () => {
6214
- try {
6215
- var _editor;
6216
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
6217
- if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
6218
- else editorView.revealLineInCenterIfOutsideViewport(line);
6219
- } catch {}
6220
- });
6221
- }, revealDebounceMs);
6222
- }
6436
+ function resolveRequestedThemeName() {
6437
+ return requestedThemeName ?? globalRequestedThemeName ?? monacoOptions.theme ?? currentTheme.value;
6223
6438
  }
6224
- async function createEditor(container, code, language) {
6225
- cleanupEditor();
6226
- lastContainer = container;
6227
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
6228
- disposals.forEach((d) => d.dispose());
6229
- disposals.length = 0;
6230
- }
6231
- if (monacoOptions.onBeforeCreate) {
6232
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
6233
- if (ds) disposals.push(...ds);
6234
- }
6235
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
6236
- await ensureThemeRegistered(initialThemeName);
6237
- editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, updateThrottleMs);
6238
- editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
6239
- if (pendingUpdate && editorMgr) {
6240
- const { code: queuedCode, lang: queuedLang } = pendingUpdate;
6241
- pendingUpdate = null;
6242
- editorMgr.updateCode(queuedCode, queuedLang);
6243
- }
6244
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
6245
- if (editorView) lastKnownCode = editorView.getValue();
6246
- return editorView;
6247
- }
6248
- function computedHeight(editorView$1) {
6249
- var _getModel;
6250
- const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
6251
- const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
6252
- const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
6253
- return height;
6439
+ function commitAppliedTheme(themeName) {
6440
+ requestedThemeName = themeName;
6441
+ globalRequestedThemeName = themeName;
6442
+ globalAppliedThemeName = themeName;
6443
+ monacoOptions.theme = themeName;
6254
6444
  }
6255
- async function createDiffEditor(container, originalCode, modifiedCode, language) {
6256
- cleanupEditor();
6257
- lastContainer = container;
6258
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
6259
- disposals.forEach((d) => d.dispose());
6260
- disposals.length = 0;
6261
- }
6262
- if (monacoOptions.onBeforeCreate) {
6263
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
6264
- if (ds) disposals.push(...ds);
6265
- }
6266
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
6267
- await ensureThemeRegistered(initialThemeName);
6445
+ async function notifyThemeApplied(themeName) {
6446
+ if (typeof monacoOptions.onThemeChange !== "function") return;
6268
6447
  try {
6269
- monaco_shim_exports.editor.setTheme(initialThemeName);
6448
+ await monacoOptions.onThemeChange(themeName);
6449
+ } catch (err) {
6450
+ console.warn("onThemeChange callback threw an error:", err);
6451
+ }
6452
+ }
6453
+ function disposeDisposables(items) {
6454
+ if (!(items === null || items === void 0 ? void 0 : items.length)) return;
6455
+ for (const item of items) try {
6456
+ item.dispose();
6270
6457
  } catch {}
6271
- diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
6272
- diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
6273
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
6274
- const models = diffMgr.getDiffModels();
6275
- originalModel = models.original;
6276
- modifiedModel = models.modified;
6277
- return diffEditorView;
6278
- }
6279
- function clearFallbackAsyncWork() {
6280
- rafScheduler.cancel("update");
6281
- rafScheduler.cancel("append");
6282
- rafScheduler.cancel("reveal");
6283
- pendingUpdate = null;
6284
- appendBufferScheduled = false;
6285
- appendBuffer.length = 0;
6286
- if (revealDebounceId != null) {
6287
- clearTimeout(revealDebounceId);
6288
- revealDebounceId = null;
6289
- }
6290
- if (updateThrottleTimer != null) {
6291
- clearTimeout(updateThrottleTimer);
6292
- updateThrottleTimer = null;
6293
- }
6294
- lastFlushTime = 0;
6295
6458
  }
6296
- function cleanupEditor() {
6459
+ function takePendingCreateDisposables(requestId) {
6460
+ const items = pendingCreateDisposables.get(requestId) ?? [];
6461
+ pendingCreateDisposables.delete(requestId);
6462
+ return items;
6463
+ }
6464
+ function disposeAllPendingCreateDisposables() {
6465
+ for (const requestId of Array.from(pendingCreateDisposables.keys())) disposeDisposables(takePendingCreateDisposables(requestId));
6466
+ }
6467
+ function cleanupInstances() {
6297
6468
  if (editorMgr) {
6298
6469
  editorMgr.cleanup();
6299
6470
  editorMgr = null;
6300
- }
6471
+ } else if (editorView) try {
6472
+ editorView.dispose();
6473
+ } catch {}
6301
6474
  if (diffMgr) {
6302
6475
  diffMgr.cleanup();
6303
6476
  diffMgr = null;
6477
+ } else {
6478
+ try {
6479
+ diffEditorView === null || diffEditorView === void 0 || diffEditorView.dispose();
6480
+ } catch {}
6481
+ try {
6482
+ originalModel === null || originalModel === void 0 || originalModel.dispose();
6483
+ } catch {}
6484
+ try {
6485
+ modifiedModel === null || modifiedModel === void 0 || modifiedModel.dispose();
6486
+ } catch {}
6304
6487
  }
6305
- clearFallbackAsyncWork();
6306
- if (!editorMgr && editorView) {
6307
- editorView.dispose();
6308
- editorView = null;
6309
- }
6310
- lastKnownCode = null;
6311
- if (lastContainer) {
6312
- lastContainer.innerHTML = "";
6313
- lastContainer = null;
6314
- }
6315
- if (themeWatcher) {
6316
- themeWatcher();
6317
- themeWatcher = null;
6318
- }
6488
+ editorView = null;
6319
6489
  diffEditorView = null;
6320
6490
  originalModel = null;
6321
6491
  modifiedModel = null;
6322
6492
  }
6323
- function appendCode(appendText, codeLanguage) {
6324
- if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
6325
- else {
6326
- if (!editorView) return;
6327
- const model = editorView.getModel();
6328
- if (!model) return;
6329
- const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
6330
- if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
6331
- if (appendText && lastKnownCode != null) lastKnownCode = lastKnownCode + appendText;
6332
- if (appendText) {
6333
- appendBuffer.push(appendText);
6334
- if (!appendBufferScheduled) {
6335
- appendBufferScheduled = true;
6336
- rafScheduler.schedule("append", flushAppendBuffer);
6337
- }
6338
- }
6493
+ function createSupersededError() {
6494
+ const err = new Error("Editor creation was superseded");
6495
+ err.name = "AbortError";
6496
+ err.code = "STREAM_MONACO_CREATE_SUPERSEDED";
6497
+ return err;
6498
+ }
6499
+ function isCreateActive(requestId, kind) {
6500
+ return activeCreateRequestId === requestId && activeCreateKind === kind;
6501
+ }
6502
+ function assertCreateStillActive(requestId, kind) {
6503
+ if (!isCreateActive(requestId, kind)) throw createSupersededError();
6504
+ }
6505
+ function cancelPendingCreates() {
6506
+ activeCreateRequestId = null;
6507
+ activeCreateKind = null;
6508
+ queuedEditorUpdateDuringCreate = null;
6509
+ disposeAllPendingCreateDisposables();
6510
+ }
6511
+ async function resolveCreateThemeName(requestId, kind) {
6512
+ let themeName = resolveRequestedThemeName();
6513
+ while (true) {
6514
+ assertCreateStillActive(requestId, kind);
6515
+ await ensureThemeRegistered(themeName);
6516
+ assertCreateStillActive(requestId, kind);
6517
+ const latestThemeName = resolveRequestedThemeName();
6518
+ if (latestThemeName === themeName) return themeName;
6519
+ themeName = latestThemeName;
6339
6520
  }
6340
6521
  }
6341
- function applyMinimalEdit(prev, next) {
6342
- if (!editorView) return;
6343
- const model = editorView.getModel();
6344
- if (!model) return;
6522
+ async function createEditor(container, code, language) {
6523
+ var _monacoOptions$onBefo;
6524
+ cancelPendingCreates();
6525
+ cleanupInstances();
6526
+ const requestId = ++createRequestSeq;
6527
+ activeCreateRequestId = requestId;
6528
+ activeCreateKind = "editor";
6529
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6530
+ const requestDisposables = ((_monacoOptions$onBefo = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo === void 0 ? void 0 : _monacoOptions$onBefo.call(monacoOptions, monaco_shim_exports)) ?? [];
6531
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6532
+ let nextEditorMgr = null;
6345
6533
  try {
6346
- const maxChars = minimalEditMaxCharsLocal;
6347
- const ratio = minimalEditMaxChangeRatioLocal;
6348
- const maxLen = Math.max(prev.length, next.length);
6349
- const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
6350
- if (prev.length + next.length > maxChars || changeRatio > ratio) {
6351
- const prevLineCount = model.getLineCount();
6352
- model.setValue(next);
6353
- lastKnownCode = next;
6354
- const newLineCount = model.getLineCount();
6355
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6356
- return;
6357
- }
6358
- } catch {}
6359
- const res = computeMinimalEdit(prev, next);
6360
- if (!res) return;
6361
- const { start, endPrevIncl, replaceText } = res;
6362
- const rangeStart = model.getPositionAt(start);
6363
- const rangeEnd = model.getPositionAt(endPrevIncl + 1);
6364
- const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
6365
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
6366
- const edit = [{
6367
- range,
6368
- text: replaceText,
6369
- forceMoveMarkers: true
6370
- }];
6371
- if (isReadOnly) model.applyEdits(edit);
6372
- else editorView.executeEdits("minimal-replace", edit);
6373
- }
6374
- function flushPendingUpdate() {
6375
- if (!pendingUpdate) return;
6376
- lastFlushTime = Date.now();
6377
- if (!editorView) return;
6378
- const model = editorView.getModel();
6379
- if (!model) return;
6380
- const { code: newCode, lang: codeLanguage } = pendingUpdate;
6381
- pendingUpdate = null;
6382
- const processedCodeLanguage = processedLanguage(codeLanguage);
6383
- let prevCode = null;
6384
- if (appendBuffer.length > 0) {
6385
- appendBuffer.length = 0;
6386
- appendBufferScheduled = false;
6387
- rafScheduler.cancel("append");
6388
- try {
6389
- prevCode = model.getValue();
6390
- lastKnownCode = prevCode;
6391
- } catch {
6392
- prevCode = lastKnownCode ?? "";
6534
+ const initialThemeName = await resolveCreateThemeName(requestId, "editor");
6535
+ nextEditorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, monacoOptions.updateThrottleMs);
6536
+ const nextEditorView = await nextEditorMgr.createEditor(container, code, language, initialThemeName);
6537
+ assertCreateStillActive(requestId, "editor");
6538
+ editorMgr = nextEditorMgr;
6539
+ editorView = nextEditorView;
6540
+ diffMgr = null;
6541
+ diffEditorView = null;
6542
+ originalModel = null;
6543
+ modifiedModel = null;
6544
+ commitAppliedTheme(initialThemeName);
6545
+ const committedDisposables = takePendingCreateDisposables(requestId);
6546
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6547
+ activeCreateRequestId = null;
6548
+ activeCreateKind = null;
6549
+ const queuedUpdate = queuedEditorUpdateDuringCreate;
6550
+ if ((queuedUpdate === null || queuedUpdate === void 0 ? void 0 : queuedUpdate.requestId) === requestId) {
6551
+ queuedEditorUpdateDuringCreate = null;
6552
+ editorMgr.updateCode(queuedUpdate.code, queuedUpdate.lang);
6393
6553
  }
6394
- } else {
6395
- prevCode = lastKnownCode;
6396
- if (prevCode == null) try {
6397
- prevCode = model.getValue();
6398
- lastKnownCode = prevCode;
6399
- } catch {
6400
- prevCode = "";
6554
+ await notifyThemeApplied(initialThemeName);
6555
+ return nextEditorView;
6556
+ } catch (error$1) {
6557
+ if (nextEditorMgr) try {
6558
+ nextEditorMgr.cleanup();
6559
+ } catch {}
6560
+ disposeDisposables(takePendingCreateDisposables(requestId));
6561
+ if (activeCreateRequestId === requestId) {
6562
+ activeCreateRequestId = null;
6563
+ activeCreateKind = null;
6564
+ queuedEditorUpdateDuringCreate = null;
6401
6565
  }
6566
+ throw error$1;
6402
6567
  }
6403
- if (prevCode === newCode) return;
6404
- const languageId = model.getLanguageId();
6405
- if (languageId !== processedCodeLanguage) {
6406
- if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
6407
- const prevLineCount = model.getLineCount();
6408
- model.setValue(newCode);
6409
- lastKnownCode = newCode;
6410
- const newLineCount = model.getLineCount();
6411
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6412
- return;
6413
- }
6414
- if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
6415
- const suffix = newCode.slice(prevCode.length);
6416
- if (suffix) appendCode(suffix, codeLanguage);
6417
- lastKnownCode = newCode;
6418
- return;
6419
- }
6420
- try {
6421
- const maxChars = minimalEditMaxCharsLocal;
6422
- const ratio = minimalEditMaxChangeRatioLocal;
6423
- const maxLen = Math.max(prevCode.length, newCode.length);
6424
- const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
6425
- if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
6426
- const prevLineCount = model.getLineCount();
6427
- model.setValue(newCode);
6428
- lastKnownCode = newCode;
6429
- const newLineCount = model.getLineCount();
6430
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6431
- return;
6432
- }
6433
- } catch {}
6568
+ }
6569
+ async function createDiffEditor(container, originalCode, modifiedCode, language) {
6570
+ var _monacoOptions$onBefo2;
6571
+ cancelPendingCreates();
6572
+ cleanupInstances();
6573
+ const requestId = ++createRequestSeq;
6574
+ activeCreateRequestId = requestId;
6575
+ activeCreateKind = "diff";
6576
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6577
+ const requestDisposables = ((_monacoOptions$onBefo2 = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo2 === void 0 ? void 0 : _monacoOptions$onBefo2.call(monacoOptions, monaco_shim_exports)) ?? [];
6578
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6579
+ let nextDiffMgr = null;
6434
6580
  try {
6435
- applyMinimalEdit(prevCode, newCode);
6436
- lastKnownCode = newCode;
6437
- const newLineCount = model.getLineCount();
6438
- const prevLineCount = (prevCode ? prevCode.split("\n").length : 0) || model.getLineCount();
6439
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6440
- } catch {
6441
- try {
6442
- const prevLineCount = model.getLineCount();
6443
- model.setValue(newCode);
6444
- lastKnownCode = newCode;
6445
- const newLineCount = model.getLineCount();
6446
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6581
+ const initialThemeName = await resolveCreateThemeName(requestId, "diff");
6582
+ nextDiffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
6583
+ const nextDiffEditorView = await nextDiffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
6584
+ assertCreateStillActive(requestId, "diff");
6585
+ diffMgr = nextDiffMgr;
6586
+ diffEditorView = nextDiffEditorView;
6587
+ editorMgr = null;
6588
+ editorView = null;
6589
+ const models = diffMgr.getDiffModels();
6590
+ originalModel = models.original;
6591
+ modifiedModel = models.modified;
6592
+ commitAppliedTheme(initialThemeName);
6593
+ const committedDisposables = takePendingCreateDisposables(requestId);
6594
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6595
+ activeCreateRequestId = null;
6596
+ activeCreateKind = null;
6597
+ await notifyThemeApplied(initialThemeName);
6598
+ return nextDiffEditorView;
6599
+ } catch (error$1) {
6600
+ if (nextDiffMgr) try {
6601
+ nextDiffMgr.cleanup();
6447
6602
  } catch {}
6603
+ disposeDisposables(takePendingCreateDisposables(requestId));
6604
+ if (activeCreateRequestId === requestId) {
6605
+ activeCreateRequestId = null;
6606
+ activeCreateKind = null;
6607
+ }
6608
+ throw error$1;
6448
6609
  }
6449
6610
  }
6450
- function flushAppendBuffer() {
6451
- if (!editorView) return;
6452
- if (appendBuffer.length === 0) return;
6453
- appendBufferScheduled = false;
6454
- const model = editorView.getModel();
6455
- if (!model) {
6456
- appendBuffer.length = 0;
6457
- return;
6458
- }
6459
- const text = appendBuffer.join("");
6460
- appendBuffer.length = 0;
6461
- try {
6462
- const lastLine = model.getLineCount();
6463
- const lastColumn = model.getLineMaxColumn(lastLine);
6464
- const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
6465
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
6466
- if (isReadOnly) model.applyEdits([{
6467
- range,
6468
- text,
6469
- forceMoveMarkers: true
6470
- }]);
6471
- else editorView.executeEdits("append", [{
6472
- range,
6473
- text,
6474
- forceMoveMarkers: true
6475
- }]);
6476
- if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
6477
- try {
6478
- if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
6479
- } catch {}
6480
- } catch {}
6611
+ function cleanupEditor() {
6612
+ cancelPendingCreates();
6613
+ cleanupInstances();
6614
+ disposeDisposables(disposals.splice(0));
6615
+ }
6616
+ function appendCode(appendText, codeLanguage) {
6617
+ if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
6481
6618
  }
6482
6619
  function updateCode(newCode, codeLanguage) {
6483
- if (editorMgr) editorMgr.updateCode(newCode, codeLanguage);
6484
- else {
6485
- pendingUpdate = {
6486
- code: newCode,
6487
- lang: codeLanguage
6488
- };
6489
- rafScheduler.schedule("update", () => {
6490
- if (!updateThrottleMs) {
6491
- flushPendingUpdate();
6492
- return;
6493
- }
6494
- const now = Date.now();
6495
- const since = now - lastFlushTime;
6496
- if (since >= updateThrottleMs) {
6497
- flushPendingUpdate();
6498
- return;
6499
- }
6500
- if (updateThrottleTimer != null) return;
6501
- const wait = updateThrottleMs - since;
6502
- updateThrottleTimer = setTimeout(() => {
6503
- updateThrottleTimer = null;
6504
- rafScheduler.schedule("update", () => flushPendingUpdate());
6505
- }, wait);
6506
- });
6620
+ if (editorMgr) {
6621
+ editorMgr.updateCode(newCode, codeLanguage);
6622
+ return;
6507
6623
  }
6624
+ if (activeCreateRequestId != null && activeCreateKind === "editor") queuedEditorUpdateDuringCreate = {
6625
+ requestId: activeCreateRequestId,
6626
+ code: newCode,
6627
+ lang: codeLanguage
6628
+ };
6508
6629
  }
6509
6630
  function setUpdateThrottleMs(ms) {
6510
- updateThrottleMs = ms;
6631
+ monacoOptions.updateThrottleMs = ms;
6511
6632
  editorMgr === null || editorMgr === void 0 || editorMgr.setUpdateThrottleMs(ms);
6512
6633
  }
6513
6634
  function getUpdateThrottleMs() {
6514
- return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? updateThrottleMs;
6635
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? monacoOptions.updateThrottleMs ?? 50;
6515
6636
  }
6516
6637
  function updateDiff(originalCode, modifiedCode, codeLanguage) {
6517
6638
  if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
@@ -6543,15 +6664,12 @@ function useMonaco(monacoOptions = {}) {
6543
6664
  createDiffEditor,
6544
6665
  cleanupEditor,
6545
6666
  safeClean() {
6546
- clearFallbackAsyncWork();
6547
6667
  if (editorMgr) try {
6548
6668
  editorMgr.safeClean();
6549
6669
  } catch {}
6550
6670
  if (diffMgr) try {
6551
6671
  diffMgr.safeClean();
6552
6672
  } catch {}
6553
- _hasScrollBar = false;
6554
- shouldAutoScroll = !!autoScrollInitial;
6555
6673
  },
6556
6674
  updateCode,
6557
6675
  appendCode,
@@ -6588,10 +6706,10 @@ function useMonaco(monacoOptions = {}) {
6588
6706
  return monaco_shim_exports.editor;
6589
6707
  },
6590
6708
  getEditorView() {
6591
- return editorView;
6709
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getEditorView()) ?? editorView;
6592
6710
  },
6593
6711
  getDiffEditorView() {
6594
- return diffEditorView;
6712
+ return (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffEditorView()) ?? diffEditorView;
6595
6713
  },
6596
6714
  getDiffModels() {
6597
6715
  if (diffMgr) return diffMgr.getDiffModels();
@@ -6606,18 +6724,22 @@ function useMonaco(monacoOptions = {}) {
6606
6724
  setUpdateThrottleMs,
6607
6725
  getUpdateThrottleMs,
6608
6726
  getCode() {
6727
+ if (editorMgr) return editorMgr.getCode();
6609
6728
  if (editorView) try {
6610
6729
  var _editorView$getModel;
6611
6730
  return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
6612
6731
  } catch {
6613
6732
  return null;
6614
6733
  }
6615
- if (diffEditorView || originalModel && modifiedModel) try {
6616
- const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
6617
- const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
6734
+ const diffModels = (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffModels()) ?? {
6735
+ original: originalModel,
6736
+ modified: modifiedModel
6737
+ };
6738
+ if (diffEditorView || diffModels.original && diffModels.modified) try {
6739
+ var _diffModels$original, _diffModels$modified;
6618
6740
  return {
6619
- original,
6620
- modified
6741
+ original: ((_diffModels$original = diffModels.original) === null || _diffModels$original === void 0 ? void 0 : _diffModels$original.getValue()) ?? "",
6742
+ modified: ((_diffModels$modified = diffModels.modified) === null || _diffModels$modified === void 0 ? void 0 : _diffModels$modified.getValue()) ?? ""
6621
6743
  };
6622
6744
  } catch {
6623
6745
  return null;