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.
@@ -141,10 +141,15 @@ function processedLanguage(language) {
141
141
  //#endregion
142
142
  //#region src/monaco-shim.ts
143
143
  var monaco_shim_exports = {};
144
- __export(monaco_shim_exports, { default: () => monaco });
144
+ __export(monaco_shim_exports, {
145
+ ScrollType: () => ScrollType,
146
+ default: () => monaco
147
+ });
145
148
  import * as import_monaco_editor_esm_vs_editor_editor_api from "monaco-editor/esm/vs/editor/editor.api";
146
149
  __reExport(monaco_shim_exports, import_monaco_editor_esm_vs_editor_editor_api);
150
+ var _editor;
147
151
  const monaco = _monaco;
152
+ const ScrollType = Reflect.get(_monaco, "ScrollType") ?? ((_editor = _monaco.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
148
153
 
149
154
  //#endregion
150
155
  //#region src/constant.ts
@@ -467,6 +472,809 @@ function createScrollWatcherForEditor(ed, opts) {
467
472
  return api;
468
473
  }
469
474
 
475
+ //#endregion
476
+ //#region src/core/diffAppearance.ts
477
+ function parseCssColorRgb(color) {
478
+ const normalized = color.trim().toLowerCase();
479
+ const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
480
+ if (rgbMatch) return [
481
+ Number.parseFloat(rgbMatch[1]),
482
+ Number.parseFloat(rgbMatch[2]),
483
+ Number.parseFloat(rgbMatch[3])
484
+ ];
485
+ const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
486
+ if (!hexMatch) return null;
487
+ const hex = hexMatch[1];
488
+ if (hex.length === 3 || hex.length === 4) return [
489
+ Number.parseInt(`${hex[0]}${hex[0]}`, 16),
490
+ Number.parseInt(`${hex[1]}${hex[1]}`, 16),
491
+ Number.parseInt(`${hex[2]}${hex[2]}`, 16)
492
+ ];
493
+ if (hex.length === 6 || hex.length === 8) return [
494
+ Number.parseInt(hex.slice(0, 2), 16),
495
+ Number.parseInt(hex.slice(2, 4), 16),
496
+ Number.parseInt(hex.slice(4, 6), 16)
497
+ ];
498
+ return null;
499
+ }
500
+ function resolveCssColorLuminance(color) {
501
+ const rgb = parseCssColorRgb(color);
502
+ if (!rgb) return null;
503
+ const channel = (value) => {
504
+ const normalized = Math.max(0, Math.min(255, value)) / 255;
505
+ return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
506
+ };
507
+ const [r, g, b] = rgb;
508
+ return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
509
+ }
510
+ function looksLikeDarkThemeName(themeName) {
511
+ if (!themeName) return false;
512
+ const normalized = themeName.toLowerCase();
513
+ return [
514
+ "dark",
515
+ "night",
516
+ "moon",
517
+ "black",
518
+ "dracula",
519
+ "mocha",
520
+ "frappe",
521
+ "macchiato",
522
+ "palenight",
523
+ "ocean",
524
+ "poimandres",
525
+ "monokai",
526
+ "laserwave",
527
+ "tokyo",
528
+ "slack-dark",
529
+ "rose-pine",
530
+ "github-dark",
531
+ "material-theme",
532
+ "one-dark",
533
+ "catppuccin-mocha",
534
+ "catppuccin-frappe",
535
+ "catppuccin-macchiato"
536
+ ].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
537
+ }
538
+ function looksLikeLightThemeName(themeName) {
539
+ if (!themeName) return false;
540
+ const normalized = themeName.toLowerCase();
541
+ return [
542
+ "light",
543
+ "day",
544
+ "dawn",
545
+ "latte",
546
+ "solarized-light",
547
+ "github-light",
548
+ "rose-pine-dawn",
549
+ "catppuccin-latte",
550
+ "one-light",
551
+ "vitesse-light",
552
+ "snazzy-light",
553
+ "material-lighter",
554
+ "material-theme-lighter",
555
+ "lotus"
556
+ ].some((token) => normalized.includes(token));
557
+ }
558
+ function resolveDiffAppearance({ container, diffAppearance, diffEditorView, themeName }) {
559
+ var _diffEditorView$getMo, _diffEditorView$getMo2, _diffEditorView$getOr, _diffEditorView$getOr2;
560
+ if (diffAppearance === "light") return "light";
561
+ if (diffAppearance === "dark") return "dark";
562
+ if (looksLikeDarkThemeName(themeName)) return "dark";
563
+ if (looksLikeLightThemeName(themeName)) return "light";
564
+ const appearanceProbeNodes = [
565
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo2 = (_diffEditorView$getMo = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo2 === void 0 ? void 0 : _diffEditorView$getMo2.call(_diffEditorView$getMo),
566
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr2 = (_diffEditorView$getOr = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr2 === void 0 ? void 0 : _diffEditorView$getOr2.call(_diffEditorView$getOr),
567
+ container
568
+ ];
569
+ for (const node of appearanceProbeNodes) {
570
+ if (!(node instanceof HTMLElement)) continue;
571
+ const style = globalThis.getComputedStyle(node);
572
+ const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
573
+ const candidates = [
574
+ style.getPropertyValue("--stream-monaco-editor-bg"),
575
+ style.getPropertyValue("--vscode-editor-background"),
576
+ editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
577
+ style.backgroundColor
578
+ ];
579
+ for (const color of candidates) {
580
+ const luminance = resolveCssColorLuminance(color);
581
+ if (luminance == null) continue;
582
+ return luminance <= .42 ? "dark" : "light";
583
+ }
584
+ }
585
+ return looksLikeDarkThemeName(themeName) ? "dark" : "light";
586
+ }
587
+ function syncDiffRootThemeVariables(container, diffEditorView, appearance) {
588
+ var _diffEditorView$getMo3, _diffEditorView$getMo4, _diffEditorView$getOr3, _diffEditorView$getOr4;
589
+ const probeNodes = [
590
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo4 = (_diffEditorView$getMo3 = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo4 === void 0 ? void 0 : _diffEditorView$getMo4.call(_diffEditorView$getMo3),
591
+ diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr4 = (_diffEditorView$getOr3 = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr4 === void 0 ? void 0 : _diffEditorView$getOr4.call(_diffEditorView$getOr3),
592
+ container
593
+ ];
594
+ const containerStyle = globalThis.getComputedStyle(container);
595
+ const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
596
+ let backgroundColor = null;
597
+ let foregroundColor = null;
598
+ for (const node of probeNodes) {
599
+ if (!(node instanceof HTMLElement)) continue;
600
+ const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
601
+ const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
602
+ const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
603
+ if (!backgroundColor && resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
604
+ const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
605
+ if (!foregroundColor && resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
606
+ if (backgroundColor && foregroundColor) break;
607
+ }
608
+ const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
609
+ if (resolvedBackgroundColor) container.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
610
+ else container.style.removeProperty("--stream-monaco-editor-bg");
611
+ if (foregroundColor) container.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
612
+ else container.style.removeProperty("--stream-monaco-editor-fg");
613
+ }
614
+ function resolveDiffUnchangedLineInfoRailMetrics(node) {
615
+ const editorRoot = node.closest(".monaco-editor");
616
+ if (!editorRoot) return {
617
+ leftInset: 0,
618
+ width: null
619
+ };
620
+ const editorRect = editorRoot.getBoundingClientRect();
621
+ const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
622
+ const rect = candidate.getBoundingClientRect();
623
+ return rect.width > 0 && rect.height > 0;
624
+ });
625
+ if (!lineNumberNode) return {
626
+ leftInset: 0,
627
+ width: null
628
+ };
629
+ const lineNumberRect = lineNumberNode.getBoundingClientRect();
630
+ return {
631
+ leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
632
+ width: Math.max(0, lineNumberRect.width) || null
633
+ };
634
+ }
635
+ function applyDiffRootAppearanceClass({ appearanceClasses, container, currentSignature, diffAppearance, diffEditorView, isInlineMode, layoutModeClasses, lineStyle, lineStyleClasses, themeName, unchangedRegionStyle, unchangedRegionStyleClasses }) {
636
+ if (!container) return currentSignature;
637
+ const resolvedAppearance = resolveDiffAppearance({
638
+ container,
639
+ diffAppearance,
640
+ diffEditorView,
641
+ themeName
642
+ });
643
+ syncDiffRootThemeVariables(container, diffEditorView, resolvedAppearance);
644
+ const containerClassList = container.classList;
645
+ const activeLineStyleClass = `stream-monaco-diff-style-${lineStyle}`;
646
+ const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${unchangedRegionStyle}`;
647
+ const activeLayoutModeClass = isInlineMode ? "stream-monaco-diff-inline" : "stream-monaco-diff-side-by-side";
648
+ const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
649
+ const nextSignature = [
650
+ activeLineStyleClass,
651
+ activeUnchangedRegionStyleClass,
652
+ activeLayoutModeClass,
653
+ activeAppearanceClass
654
+ ].join("|");
655
+ if (currentSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return currentSignature;
656
+ containerClassList.add("stream-monaco-diff-root");
657
+ for (const className of lineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
658
+ for (const className of unchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
659
+ for (const className of layoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
660
+ for (const className of appearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
661
+ return nextSignature;
662
+ }
663
+
664
+ //#endregion
665
+ //#region src/core/diffHunk.ts
666
+ function createDiffHunkActionNode(side, onAction) {
667
+ const node = document.createElement("div");
668
+ node.className = "stream-monaco-diff-hunk-actions";
669
+ node.dataset.side = side;
670
+ const createButton = (action, label) => {
671
+ const button = document.createElement("button");
672
+ button.type = "button";
673
+ button.textContent = label;
674
+ button.dataset.action = action;
675
+ button.addEventListener("click", (event) => {
676
+ event.preventDefault();
677
+ event.stopPropagation();
678
+ onAction(side, action);
679
+ });
680
+ return button;
681
+ };
682
+ node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
683
+ return node;
684
+ }
685
+ function hasOriginalLines(change) {
686
+ return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
687
+ }
688
+ function hasModifiedLines(change) {
689
+ return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
690
+ }
691
+ function inferInlineDiffHunkHoverSide(change, hoverLine, targetElement) {
692
+ if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
693
+ if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
694
+ if (!hasModifiedLines(change)) return "upper";
695
+ if (!hasOriginalLines(change)) return "lower";
696
+ const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
697
+ return hoverLine < modifiedAnchor ? "upper" : "lower";
698
+ }
699
+ function distanceToLineChange(side, change, line) {
700
+ const hasRange = side === "original" ? hasOriginalLines(change) : hasModifiedLines(change);
701
+ const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
702
+ const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
703
+ if (hasRange) {
704
+ if (line < start) return start - line;
705
+ if (line > end) return line - end;
706
+ return 0;
707
+ }
708
+ const fallbackAnchor = Math.max(1, start || end || 1);
709
+ return Math.abs(line - fallbackAnchor);
710
+ }
711
+ function findLineChangeByHoverLine(lineChanges, side, line) {
712
+ if (lineChanges.length === 0) return null;
713
+ let best = null;
714
+ let bestDistance = Number.POSITIVE_INFINITY;
715
+ for (const change of lineChanges) {
716
+ const distance = distanceToLineChange(side, change, line);
717
+ if (distance < bestDistance) {
718
+ bestDistance = distance;
719
+ best = change;
720
+ if (distance === 0) break;
721
+ }
722
+ }
723
+ if (bestDistance > 2) return null;
724
+ return best;
725
+ }
726
+ function getFullLineRange(model, startLine, endLine) {
727
+ if (endLine < startLine) return null;
728
+ const lineCount = model.getLineCount();
729
+ if (lineCount < 1) return null;
730
+ const start = Math.max(1, Math.min(startLine, lineCount));
731
+ const end = Math.max(start, Math.min(endLine, lineCount));
732
+ if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
733
+ return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
734
+ }
735
+ function getLinesText(model, startLine, endLine) {
736
+ const range = getFullLineRange(model, startLine, endLine);
737
+ if (!range) return "";
738
+ return model.getValueInRange(range);
739
+ }
740
+ function getInsertRangeBeforeLine(model, lineNumber) {
741
+ const lineCount = model.getLineCount();
742
+ if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
743
+ if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
744
+ const lastLine = lineCount;
745
+ const lastColumn = model.getLineMaxColumn(lastLine);
746
+ return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
747
+ }
748
+ function getInsertRangeAfterLine(model, lineNumber) {
749
+ const lineCount = model.getLineCount();
750
+ if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
751
+ if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
752
+ const lastLine = lineCount;
753
+ const lastColumn = model.getLineMaxColumn(lastLine);
754
+ return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
755
+ }
756
+ function applyDefaultDiffHunkAction(context) {
757
+ const { action, side, lineChange, originalModel, modifiedModel } = context;
758
+ const hasOriginal = hasOriginalLines(lineChange);
759
+ const hasModified = hasModifiedLines(lineChange);
760
+ if (action === "revert" && side === "upper") {
761
+ if (!hasOriginal) return;
762
+ const text = getLinesText(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
763
+ if (!text) return;
764
+ const range = hasModified ? getInsertRangeBeforeLine(modifiedModel, lineChange.modifiedStartLineNumber) : getInsertRangeAfterLine(modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
765
+ modifiedModel.applyEdits([{
766
+ range,
767
+ text,
768
+ forceMoveMarkers: true
769
+ }]);
770
+ return;
771
+ }
772
+ if (action === "revert" && side === "lower") {
773
+ if (!hasModified) return;
774
+ const range = getFullLineRange(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
775
+ if (!range) return;
776
+ modifiedModel.applyEdits([{
777
+ range,
778
+ text: "",
779
+ forceMoveMarkers: true
780
+ }]);
781
+ return;
782
+ }
783
+ if (action === "stage" && side === "upper") {
784
+ if (!hasOriginal) return;
785
+ const range = getFullLineRange(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
786
+ if (!range) return;
787
+ originalModel.applyEdits([{
788
+ range,
789
+ text: "",
790
+ forceMoveMarkers: true
791
+ }]);
792
+ return;
793
+ }
794
+ if (action === "stage" && side === "lower") {
795
+ if (!hasModified) return;
796
+ const text = getLinesText(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
797
+ if (!text) return;
798
+ const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
799
+ const range = getInsertRangeAfterLine(originalModel, anchor);
800
+ originalModel.applyEdits([{
801
+ range,
802
+ text,
803
+ forceMoveMarkers: true
804
+ }]);
805
+ }
806
+ }
807
+ function setDiffHunkNodeEnabled(node, enabled) {
808
+ if (!node) return;
809
+ const buttons = node.querySelectorAll("button");
810
+ buttons.forEach((button) => {
811
+ button.disabled = !enabled;
812
+ });
813
+ }
814
+ function positionDiffHunkNode(node, editor, anchorLine, extraOffsetY = 0) {
815
+ var _editor$getScrollTop;
816
+ const host = editor.getContainerDomNode();
817
+ const line = Math.max(1, anchorLine);
818
+ const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
819
+ const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
820
+ const nodeWidth = node.offsetWidth || 130;
821
+ const nodeHeight = node.offsetHeight || 30;
822
+ const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
823
+ const hostTop = host.offsetTop;
824
+ const minTop = hostTop + 4;
825
+ const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
826
+ const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
827
+ node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
828
+ node.style.display = "flex";
829
+ }
830
+
831
+ //#endregion
832
+ //#region src/core/diffUnchanged.ts
833
+ function formatDiffUnchangedCountLabel(text) {
834
+ const match = text.match(/\d+/);
835
+ const count = match ? Number.parseInt(match[0], 10) : NaN;
836
+ if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
837
+ return text.replace(/hidden/gi, "unmodified");
838
+ }
839
+ function countDiffLines(startLineNumber, endLineNumber) {
840
+ return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
841
+ }
842
+ function measureDiffUnchangedSurroundingLines(primaryNode) {
843
+ const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
844
+ if (!editorRoot) return {
845
+ previousVisibleLine: null,
846
+ nextVisibleLine: null
847
+ };
848
+ const widgetRect = primaryNode.getBoundingClientRect();
849
+ let previousVisibleLine = null;
850
+ let nextVisibleLine = null;
851
+ const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
852
+ lineNumberNodes.forEach((node) => {
853
+ var _node$textContent;
854
+ const lineNumber = Number.parseInt(((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim()) || "", 10);
855
+ if (!Number.isFinite(lineNumber)) return;
856
+ const top = node.getBoundingClientRect().top;
857
+ if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
858
+ else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
859
+ });
860
+ return {
861
+ previousVisibleLine,
862
+ nextVisibleLine
863
+ };
864
+ }
865
+ function formatDiffMetadataRange(startLineNumber, lineCount) {
866
+ return `${startLineNumber},${Math.max(0, lineCount)}`;
867
+ }
868
+ function buildDiffHunkMetadataLabel(change, options) {
869
+ const { contextLineCount, modifiedTotalLines, originalTotalLines } = options;
870
+ const originalChangedCount = countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
871
+ const modifiedChangedCount = countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
872
+ const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
873
+ const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
874
+ const originalStart = Math.max(1, originalAnchor - contextLineCount);
875
+ const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
876
+ const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
877
+ const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
878
+ const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
879
+ const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
880
+ return {
881
+ modifiedStart,
882
+ originalStart,
883
+ label: `@@ -${formatDiffMetadataRange(originalStart, originalDisplayCount)} +${formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
884
+ };
885
+ }
886
+ function resolveDiffMetadataLabel(options) {
887
+ var _metadataEntries$Math;
888
+ const { contextLineCount, lineChanges, modifiedTotalLines, originalTotalLines, pairIndex, primaryNode } = options;
889
+ if (lineChanges.length === 0) return null;
890
+ const metadataEntries = lineChanges.map((change) => buildDiffHunkMetadataLabel(change, {
891
+ contextLineCount,
892
+ modifiedTotalLines,
893
+ originalTotalLines
894
+ }));
895
+ const { nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
896
+ if (nextVisibleLine != null) {
897
+ const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
898
+ for (const candidateStart of candidateStarts) {
899
+ const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
900
+ if (matching) return matching.label;
901
+ }
902
+ }
903
+ return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
904
+ }
905
+ function resolveDiffUnchangedSummaryLabel(options) {
906
+ const { countText, unchangedRegionStyle,...metadataOptions } = options;
907
+ if (unchangedRegionStyle !== "metadata") return countText;
908
+ return resolveDiffMetadataLabel(metadataOptions) ?? countText;
909
+ }
910
+ function resolveDiffUnchangedRevealLayout(options) {
911
+ const { countText, modelLineCount, pairCount, pairIndex, primaryNode } = options;
912
+ let showTopHandle = pairCount === 1 || pairIndex > 0;
913
+ let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
914
+ const countMatch = countText.match(/\d+/);
915
+ const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
916
+ if (!Number.isFinite(hiddenCount)) return {
917
+ showTopHandle,
918
+ showBottomHandle
919
+ };
920
+ const { previousVisibleLine, nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
921
+ if (previousVisibleLine == null && nextVisibleLine != null) {
922
+ showTopHandle = false;
923
+ showBottomHandle = true;
924
+ return {
925
+ showTopHandle,
926
+ showBottomHandle
927
+ };
928
+ }
929
+ if (nextVisibleLine == null && previousVisibleLine != null) {
930
+ showTopHandle = true;
931
+ showBottomHandle = false;
932
+ return {
933
+ showTopHandle,
934
+ showBottomHandle
935
+ };
936
+ }
937
+ if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
938
+ showTopHandle = false;
939
+ showBottomHandle = true;
940
+ }
941
+ if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
942
+ showTopHandle = true;
943
+ showBottomHandle = false;
944
+ }
945
+ return {
946
+ showTopHandle,
947
+ showBottomHandle
948
+ };
949
+ }
950
+ function resolveDiffUnchangedMergeRole(options) {
951
+ const { diffRoot, modifiedHost, node, originalHost } = options;
952
+ if (typeof HTMLElement === "undefined") return "none";
953
+ if (!(diffRoot instanceof HTMLElement)) return "none";
954
+ const nodeRect = node.getBoundingClientRect();
955
+ const nodeCenter = nodeRect.left + nodeRect.width / 2;
956
+ if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
957
+ const originalRect = originalHost.getBoundingClientRect();
958
+ const modifiedRect = modifiedHost.getBoundingClientRect();
959
+ const originalCenter = originalRect.left + originalRect.width / 2;
960
+ const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
961
+ return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
962
+ }
963
+ const diffRect = diffRoot.getBoundingClientRect();
964
+ return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
965
+ }
966
+
967
+ //#endregion
968
+ //#region src/core/diffUnchangedDom.ts
969
+ const diffUnchangedSummaryStyleClasses = [
970
+ "stream-monaco-unchanged-summary-line-info",
971
+ "stream-monaco-unchanged-summary-line-info-basic",
972
+ "stream-monaco-unchanged-summary-metadata",
973
+ "stream-monaco-unchanged-summary-simple"
974
+ ];
975
+ function createDiffUnchangedBridgeScaffold() {
976
+ const bridge = document.createElement("div");
977
+ bridge.className = "stream-monaco-diff-unchanged-bridge";
978
+ bridge.setAttribute("role", "group");
979
+ syncDiffUnchangedBridgeVisibility(bridge, false);
980
+ const summary = document.createElement("button");
981
+ summary.type = "button";
982
+ summary.className = "stream-monaco-unchanged-summary";
983
+ const visualMeta = document.createElement("div");
984
+ visualMeta.className = "stream-monaco-unchanged-meta";
985
+ summary.append(visualMeta);
986
+ const divider = document.createElement("span");
987
+ divider.className = "stream-monaco-unchanged-pane-divider";
988
+ divider.setAttribute("aria-hidden", "true");
989
+ bridge.append(summary, divider);
990
+ return {
991
+ bridge,
992
+ summary,
993
+ visualMeta,
994
+ divider
995
+ };
996
+ }
997
+ function createDiffUnchangedBridgeOverlay() {
998
+ const overlay = document.createElement("div");
999
+ overlay.className = "stream-monaco-diff-unchanged-overlay";
1000
+ return overlay;
1001
+ }
1002
+ function syncDiffUnchangedBridgeVisibility(bridge, visible) {
1003
+ bridge.hidden = !visible;
1004
+ bridge.toggleAttribute("aria-hidden", !visible);
1005
+ }
1006
+ function clearDiffUnchangedBridgeSourceClasses(container) {
1007
+ const bridgedCenters = container.querySelectorAll(".stream-monaco-unchanged-bridge-source");
1008
+ bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
1009
+ }
1010
+ function resetDiffUnchangedOverlayTransform(overlay) {
1011
+ if (!overlay) return;
1012
+ overlay.style.transform = "translate3d(0px, 0px, 0px)";
1013
+ }
1014
+ function resolveDiffUnchangedViewZoneHeight(unchangedRegionStyle) {
1015
+ return unchangedRegionStyle === "simple" ? 28 : 32;
1016
+ }
1017
+ function collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
1018
+ 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);
1019
+ if (widgetTopValues.length === 0) return [];
1020
+ return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
1021
+ const zoneTop = Number.parseFloat(node.style.top || "NaN");
1022
+ const currentHeight = Number.parseFloat(node.style.height || "0");
1023
+ return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
1024
+ }).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
1025
+ }
1026
+ function findDiffUnchangedActivationAction(...roots) {
1027
+ for (const root of roots) {
1028
+ const action = (root === null || root === void 0 ? void 0 : root.querySelector("a, button")) ?? null;
1029
+ if (action) return action;
1030
+ }
1031
+ return null;
1032
+ }
1033
+ function findDiffUnchangedExpandAction(root) {
1034
+ return (root === null || root === void 0 ? void 0 : root.querySelector("a")) ?? null;
1035
+ }
1036
+ function shouldIgnoreDiffUnchangedCenterClickTarget(target) {
1037
+ return target instanceof HTMLElement && Boolean(target.closest("a, .breadcrumb-item"));
1038
+ }
1039
+ function shouldHandleDiffUnchangedCenterClick(event) {
1040
+ return event.button === 0 && !shouldIgnoreDiffUnchangedCenterClickTarget(event.target);
1041
+ }
1042
+ function activateDiffUnchangedExpandAction(root, onBeforeActivate) {
1043
+ const action = findDiffUnchangedExpandAction(root);
1044
+ if (!action) return false;
1045
+ onBeforeActivate === null || onBeforeActivate === void 0 || onBeforeActivate(action);
1046
+ action.click();
1047
+ return true;
1048
+ }
1049
+ function syncDiffUnchangedCenterNode(node, mergeRole) {
1050
+ node.classList.add("stream-monaco-clickable");
1051
+ node.title = "Click to expand all unmodified lines";
1052
+ node.classList.toggle("stream-monaco-unchanged-merged-secondary", mergeRole === "secondary");
1053
+ node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
1054
+ }
1055
+ function syncDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
1056
+ const lastStyle = metaNode.dataset.style;
1057
+ const lastLabel = metaNode.dataset.label;
1058
+ if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
1059
+ metaNode.dataset.style = unchangedRegionStyle;
1060
+ metaNode.dataset.label = summaryLabel;
1061
+ metaNode.replaceChildren();
1062
+ metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
1063
+ if (unchangedRegionStyle === "simple") {
1064
+ const simpleBar = document.createElement("span");
1065
+ simpleBar.className = "stream-monaco-unchanged-simple-bar";
1066
+ simpleBar.setAttribute("aria-hidden", "true");
1067
+ metaNode.append(simpleBar);
1068
+ return;
1069
+ }
1070
+ const label = document.createElement("span");
1071
+ label.className = unchangedRegionStyle === "metadata" ? "stream-monaco-unchanged-metadata-label" : "stream-monaco-unchanged-count";
1072
+ label.textContent = summaryLabel;
1073
+ metaNode.append(label);
1074
+ }
1075
+ function syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel) {
1076
+ summary.classList.remove(...diffUnchangedSummaryStyleClasses);
1077
+ summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
1078
+ const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
1079
+ summary.disabled = !summaryInteractive;
1080
+ summary.tabIndex = summaryInteractive ? 0 : -1;
1081
+ if (summaryInteractive) {
1082
+ summary.removeAttribute("aria-hidden");
1083
+ summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
1084
+ summary.title = "Expand all unmodified lines";
1085
+ return;
1086
+ }
1087
+ if (unchangedRegionStyle === "simple") {
1088
+ summary.setAttribute("aria-hidden", "true");
1089
+ summary.removeAttribute("aria-label");
1090
+ summary.title = "";
1091
+ return;
1092
+ }
1093
+ summary.removeAttribute("aria-hidden");
1094
+ summary.removeAttribute("aria-label");
1095
+ summary.title = "";
1096
+ }
1097
+ function syncDiffUnchangedExpandAction(action, hidden) {
1098
+ action.classList.add("stream-monaco-unchanged-expand");
1099
+ action.dataset.streamMonacoLabel = "Expand all";
1100
+ action.title = "Expand all unmodified lines";
1101
+ action.setAttribute("aria-label", "Expand all unmodified lines");
1102
+ action.toggleAttribute("aria-hidden", hidden);
1103
+ action.tabIndex = hidden ? -1 : 0;
1104
+ }
1105
+ function createDiffUnchangedRevealButton(direction) {
1106
+ const button = document.createElement("button");
1107
+ button.type = "button";
1108
+ button.className = "stream-monaco-unchanged-reveal";
1109
+ button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
1110
+ button.dataset.direction = direction;
1111
+ return button;
1112
+ }
1113
+ function syncDiffUnchangedRevealButtonNode(button, handle, label) {
1114
+ button.hidden = !handle;
1115
+ button.disabled = !handle;
1116
+ button.toggleAttribute("aria-hidden", !handle);
1117
+ button.title = handle ? label : "";
1118
+ button.setAttribute("aria-label", handle ? label : "");
1119
+ }
1120
+ function bindDiffUnchangedRevealButtonAction(button, handle, onActivate) {
1121
+ button.onclick = handle ? (event) => {
1122
+ event.preventDefault();
1123
+ event.stopPropagation();
1124
+ onActivate(handle);
1125
+ } : null;
1126
+ }
1127
+ function shouldHandleDiffUnchangedWheel(event) {
1128
+ return Math.abs(event.deltaY) >= .5 || Math.abs(event.deltaX) >= .5;
1129
+ }
1130
+ function resolveDiffUnchangedWheelScrollTarget(scrollTop, scrollLeft, event) {
1131
+ return {
1132
+ targetScrollTop: scrollTop + event.deltaY,
1133
+ targetScrollLeft: scrollLeft + event.deltaX,
1134
+ syncHorizontal: Math.abs(event.deltaX) >= .5
1135
+ };
1136
+ }
1137
+ function syncDiffUnchangedBridgeNode(options) {
1138
+ const { bridge, bridgeLeftInset, bridgeRailWidth, containerRect, containerScrollLeft, containerScrollTop, editorBackgroundColor, primaryAnchorRect, primaryStyle, secondaryAnchorRect, unchangedRegionStyle } = options;
1139
+ bridge.className = "stream-monaco-diff-unchanged-bridge";
1140
+ bridge.classList.add(`stream-monaco-diff-unchanged-bridge-${unchangedRegionStyle}`);
1141
+ bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + containerScrollLeft + bridgeLeftInset}px`;
1142
+ bridge.style.top = `${primaryAnchorRect.top - containerRect.top + containerScrollTop}px`;
1143
+ bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
1144
+ bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
1145
+ bridge.style.color = primaryStyle.color;
1146
+ bridge.style.fontFamily = primaryStyle.fontFamily;
1147
+ bridge.style.fontSize = primaryStyle.fontSize;
1148
+ bridge.style.lineHeight = primaryStyle.lineHeight;
1149
+ bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
1150
+ bridge.style.setProperty("--stream-monaco-editor-bg", editorBackgroundColor);
1151
+ bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
1152
+ if (bridgeRailWidth) {
1153
+ bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
1154
+ return;
1155
+ }
1156
+ bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
1157
+ }
1158
+ function syncDiffUnchangedRailNode(rail, showTopHandle, showBottomHandle) {
1159
+ const shouldRenderRail = showTopHandle || showBottomHandle;
1160
+ rail.hidden = !shouldRenderRail;
1161
+ rail.toggleAttribute("aria-hidden", !shouldRenderRail);
1162
+ rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
1163
+ rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
1164
+ rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
1165
+ }
1166
+ function dispatchSyntheticPrimaryMouseDown(node) {
1167
+ const view = node.ownerDocument.defaultView;
1168
+ if (!view) return;
1169
+ const rect = node.getBoundingClientRect();
1170
+ node.dispatchEvent(new view.MouseEvent("mousedown", {
1171
+ bubbles: true,
1172
+ cancelable: true,
1173
+ button: 0,
1174
+ clientX: rect.left + rect.width / 2,
1175
+ clientY: rect.top + rect.height / 2
1176
+ }));
1177
+ }
1178
+ function dispatchSyntheticPrimaryMouseTap(node) {
1179
+ const view = node.ownerDocument.defaultView;
1180
+ if (!view) return;
1181
+ const rect = node.getBoundingClientRect();
1182
+ const clientX = rect.left + rect.width / 2;
1183
+ const clientY = rect.top + rect.height / 2;
1184
+ node.dispatchEvent(new view.MouseEvent("mousedown", {
1185
+ bubbles: true,
1186
+ cancelable: true,
1187
+ button: 0,
1188
+ clientX,
1189
+ clientY
1190
+ }));
1191
+ node.dispatchEvent(new view.MouseEvent("mouseup", {
1192
+ bubbles: true,
1193
+ cancelable: true,
1194
+ button: 0,
1195
+ clientX,
1196
+ clientY
1197
+ }));
1198
+ }
1199
+
1200
+ //#endregion
1201
+ //#region src/core/diffViewport.ts
1202
+ function computeDiffRawHeight({ diffEditorView, maxHeightValue }) {
1203
+ var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
1204
+ if (!diffEditorView) return Math.min(18 + padding, maxHeightValue);
1205
+ const modifiedEditor = diffEditorView.getModifiedEditor();
1206
+ const originalEditor = diffEditorView.getOriginalEditor();
1207
+ const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
1208
+ const originalLineCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
1209
+ const modifiedLineCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
1210
+ const lineCount = Math.max(originalLineCount, modifiedLineCount);
1211
+ const fromLines = lineCount * lineHeight + padding;
1212
+ 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);
1213
+ return Math.min(Math.max(fromLines, scrollHeight), maxHeightValue);
1214
+ }
1215
+ function computeDiffHeight({ inlineDiffStreamingHeightFloor, inlineDiffStreamingPresentationActive, isInlineMode, rawHeight }) {
1216
+ if (!isInlineMode || !inlineDiffStreamingPresentationActive && inlineDiffStreamingHeightFloor <= 0) return {
1217
+ height: rawHeight,
1218
+ nextInlineDiffStreamingHeightFloor: inlineDiffStreamingHeightFloor
1219
+ };
1220
+ const nextInlineDiffStreamingHeightFloor = Math.max(rawHeight, inlineDiffStreamingHeightFloor);
1221
+ return {
1222
+ height: nextInlineDiffStreamingHeightFloor,
1223
+ nextInlineDiffStreamingHeightFloor
1224
+ };
1225
+ }
1226
+ function readContainerLayoutSize(container) {
1227
+ var _container$getBoundin;
1228
+ const rect = (_container$getBoundin = container.getBoundingClientRect) === null || _container$getBoundin === void 0 ? void 0 : _container$getBoundin.call(container);
1229
+ return {
1230
+ width: container.clientWidth || (rect === null || rect === void 0 ? void 0 : rect.width) || 0,
1231
+ height: container.clientHeight || (rect === null || rect === void 0 ? void 0 : rect.height) || 0
1232
+ };
1233
+ }
1234
+ function hasVerticalScrollbar(measurement) {
1235
+ const epsilon = Math.max(2, Math.round(measurement.lineHeight / 8));
1236
+ return measurement.scrollHeight > measurement.computedHeight + Math.max(padding / 2, epsilon);
1237
+ }
1238
+ function isUserNearBottom(measurement, options) {
1239
+ const lineThreshold = options.autoScrollThresholdLines * measurement.lineHeight;
1240
+ const threshold = Math.max(lineThreshold || 0, options.autoScrollThresholdPx);
1241
+ const distance = measurement.scrollHeight - (measurement.scrollTop + measurement.viewportHeight);
1242
+ return distance <= threshold;
1243
+ }
1244
+ function revealEditorLine(editor, line, strategy, scrollType) {
1245
+ if (strategy === "bottom") {
1246
+ if (typeof scrollType !== "undefined") editor.revealLine(line, scrollType);
1247
+ else editor.revealLine(line);
1248
+ return;
1249
+ }
1250
+ if (strategy === "center") {
1251
+ if (typeof scrollType !== "undefined") editor.revealLineInCenter(line, scrollType);
1252
+ else editor.revealLineInCenter(line);
1253
+ return;
1254
+ }
1255
+ if (typeof scrollType !== "undefined") editor.revealLineInCenterIfOutsideViewport(line, scrollType);
1256
+ else editor.revealLineInCenterIfOutsideViewport(line);
1257
+ }
1258
+ function waitForElementHeightApplied(element, target, timeoutMs = 500) {
1259
+ return new Promise((resolve) => {
1260
+ const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1261
+ const check = () => {
1262
+ const applied = element ? Number.parseFloat((element.style.height || "").replace("px", "")) || 0 : -1;
1263
+ if (applied >= target - 1) {
1264
+ resolve();
1265
+ return;
1266
+ }
1267
+ const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1268
+ if (now - start > timeoutMs) {
1269
+ resolve();
1270
+ return;
1271
+ }
1272
+ requestAnimationFrame(check);
1273
+ };
1274
+ check();
1275
+ });
1276
+ }
1277
+
470
1278
  //#endregion
471
1279
  //#region src/core/DiffEditorManager.ts
472
1280
  var DiffEditorManager = class DiffEditorManager {
@@ -490,6 +1298,8 @@ var DiffEditorManager = class DiffEditorManager {
490
1298
  lastKnownModifiedCode = null;
491
1299
  lastKnownModifiedLineCount = null;
492
1300
  pendingDiffUpdate = null;
1301
+ minimalEditMaxCharsValue = minimalEditMaxChars;
1302
+ minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
493
1303
  shouldAutoScrollDiff = true;
494
1304
  diffScrollWatcher = null;
495
1305
  lastScrollTopDiff = 0;
@@ -498,6 +1308,7 @@ var DiffEditorManager = class DiffEditorManager {
498
1308
  cachedLineHeightDiff = null;
499
1309
  cachedComputedHeightDiff = null;
500
1310
  lastKnownModifiedDirty = false;
1311
+ programmaticModifiedContentChangeDepth = 0;
501
1312
  measureViewportDiff() {
502
1313
  var _me$getLayoutInfo, _me$getScrollTop, _me$getScrollHeight;
503
1314
  if (!this.diffEditorView) return null;
@@ -637,6 +1448,8 @@ var DiffEditorManager = class DiffEditorManager {
637
1448
  this.diffAutoScroll = diffAutoScroll;
638
1449
  this.revealDebounceMsOption = revealDebounceMsOption;
639
1450
  this.diffUpdateThrottleMsOption = diffUpdateThrottleMsOption;
1451
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
1452
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
640
1453
  }
641
1454
  resolveDiffHideUnchangedRegionsOption() {
642
1455
  const normalize = (value) => {
@@ -677,188 +1490,21 @@ var DiffEditorManager = class DiffEditorManager {
677
1490
  if (typeof explicitThrottle === "number") return explicitThrottle;
678
1491
  return 50;
679
1492
  }
680
- parseCssColorRgb(color) {
681
- const normalized = color.trim().toLowerCase();
682
- const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
683
- if (rgbMatch) return [
684
- Number.parseFloat(rgbMatch[1]),
685
- Number.parseFloat(rgbMatch[2]),
686
- Number.parseFloat(rgbMatch[3])
687
- ];
688
- const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
689
- if (!hexMatch) return null;
690
- const hex = hexMatch[1];
691
- if (hex.length === 3 || hex.length === 4) return [
692
- Number.parseInt(`${hex[0]}${hex[0]}`, 16),
693
- Number.parseInt(`${hex[1]}${hex[1]}`, 16),
694
- Number.parseInt(`${hex[2]}${hex[2]}`, 16)
695
- ];
696
- if (hex.length === 6 || hex.length === 8) return [
697
- Number.parseInt(hex.slice(0, 2), 16),
698
- Number.parseInt(hex.slice(2, 4), 16),
699
- Number.parseInt(hex.slice(4, 6), 16)
700
- ];
701
- return null;
702
- }
703
- resolveCssColorLuminance(color) {
704
- const rgb = this.parseCssColorRgb(color);
705
- if (!rgb) return null;
706
- const channel = (value) => {
707
- const normalized = Math.max(0, Math.min(255, value)) / 255;
708
- return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
709
- };
710
- const [r, g, b] = rgb;
711
- return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
712
- }
713
- resolveDiffUnchangedLineInfoRailMetrics(node) {
714
- const editorRoot = node.closest(".monaco-editor");
715
- if (!editorRoot) return {
716
- leftInset: 0,
717
- width: null
718
- };
719
- const editorRect = editorRoot.getBoundingClientRect();
720
- const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
721
- const rect = candidate.getBoundingClientRect();
722
- return rect.width > 0 && rect.height > 0;
723
- });
724
- if (!lineNumberNode) return {
725
- leftInset: 0,
726
- width: null
727
- };
728
- const lineNumberRect = lineNumberNode.getBoundingClientRect();
729
- return {
730
- leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
731
- width: Math.max(0, lineNumberRect.width) || null
732
- };
733
- }
734
- looksLikeDarkThemeName(themeName) {
735
- if (!themeName) return false;
736
- const normalized = themeName.toLowerCase();
737
- return [
738
- "dark",
739
- "night",
740
- "moon",
741
- "black",
742
- "dracula",
743
- "mocha",
744
- "frappe",
745
- "macchiato",
746
- "palenight",
747
- "ocean",
748
- "poimandres",
749
- "monokai",
750
- "laserwave",
751
- "tokyo",
752
- "slack-dark",
753
- "rose-pine",
754
- "github-dark",
755
- "material-theme",
756
- "one-dark",
757
- "catppuccin-mocha",
758
- "catppuccin-frappe",
759
- "catppuccin-macchiato"
760
- ].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
761
- }
762
- looksLikeLightThemeName(themeName) {
763
- if (!themeName) return false;
764
- const normalized = themeName.toLowerCase();
765
- return [
766
- "light",
767
- "day",
768
- "dawn",
769
- "latte",
770
- "solarized-light",
771
- "github-light",
772
- "rose-pine-dawn",
773
- "catppuccin-latte",
774
- "one-light",
775
- "vitesse-light",
776
- "snazzy-light",
777
- "material-lighter",
778
- "material-theme-lighter",
779
- "lotus"
780
- ].some((token) => normalized.includes(token));
781
- }
782
- resolveDiffAppearanceOption() {
783
- var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2, _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
784
- if (this.options.diffAppearance === "light") return "light";
785
- if (this.options.diffAppearance === "dark") return "dark";
786
- if (this.looksLikeDarkThemeName(this.options.theme)) return "dark";
787
- if (this.looksLikeLightThemeName(this.options.theme)) return "light";
788
- const appearanceProbeNodes = [
789
- (_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$),
790
- (_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),
791
- this.lastContainer
792
- ];
793
- for (const node of appearanceProbeNodes) {
794
- if (!(node instanceof HTMLElement)) continue;
795
- const style = globalThis.getComputedStyle(node);
796
- const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
797
- const candidates = [
798
- style.getPropertyValue("--stream-monaco-editor-bg"),
799
- style.getPropertyValue("--vscode-editor-background"),
800
- editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
801
- style.backgroundColor
802
- ];
803
- for (const color of candidates) {
804
- const luminance = this.resolveCssColorLuminance(color);
805
- if (luminance == null) continue;
806
- return luminance <= .42 ? "dark" : "light";
807
- }
808
- }
809
- return this.looksLikeDarkThemeName(this.options.theme) ? "dark" : "light";
810
- }
811
- syncDiffRootThemeVariables(appearance) {
812
- var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7, _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10;
813
- if (!(this.lastContainer instanceof HTMLElement)) return;
814
- const probeNodes = [
815
- (_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),
816
- (_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),
817
- this.lastContainer
818
- ];
819
- const containerStyle = globalThis.getComputedStyle(this.lastContainer);
820
- const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
821
- let backgroundColor = null;
822
- let foregroundColor = null;
823
- for (const node of probeNodes) {
824
- if (!(node instanceof HTMLElement)) continue;
825
- const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
826
- const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
827
- const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
828
- if (!backgroundColor && this.resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
829
- const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
830
- if (!foregroundColor && this.resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
831
- if (backgroundColor && foregroundColor) break;
832
- }
833
- const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
834
- if (resolvedBackgroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
835
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-bg");
836
- if (foregroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
837
- else this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
838
- }
839
1493
  applyDiffRootAppearanceClass() {
840
- if (!this.lastContainer) return;
841
- const resolvedAppearance = this.resolveDiffAppearanceOption();
842
- this.syncDiffRootThemeVariables(resolvedAppearance);
843
- const containerClassList = this.lastContainer.classList;
844
- const activeLineStyleClass = `stream-monaco-diff-style-${this.resolveDiffLineStyleOption()}`;
845
- const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${this.resolveDiffUnchangedRegionStyleOption()}`;
846
- const sideBySide = !this.isDiffInlineMode();
847
- const activeLayoutModeClass = sideBySide ? "stream-monaco-diff-side-by-side" : "stream-monaco-diff-inline";
848
- const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
849
- const nextSignature = [
850
- activeLineStyleClass,
851
- activeUnchangedRegionStyleClass,
852
- activeLayoutModeClass,
853
- activeAppearanceClass
854
- ].join("|");
855
- if (this.diffRootAppearanceSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return;
856
- containerClassList.add("stream-monaco-diff-root");
857
- for (const className of DiffEditorManager.diffLineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
858
- for (const className of DiffEditorManager.diffUnchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
859
- for (const className of DiffEditorManager.diffLayoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
860
- for (const className of DiffEditorManager.diffAppearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
861
- this.diffRootAppearanceSignature = nextSignature;
1494
+ this.diffRootAppearanceSignature = applyDiffRootAppearanceClass({
1495
+ container: this.lastContainer,
1496
+ diffEditorView: this.diffEditorView,
1497
+ diffAppearance: this.options.diffAppearance,
1498
+ themeName: this.options.theme ?? null,
1499
+ currentSignature: this.diffRootAppearanceSignature,
1500
+ lineStyle: this.resolveDiffLineStyleOption(),
1501
+ unchangedRegionStyle: this.resolveDiffUnchangedRegionStyleOption(),
1502
+ isInlineMode: this.isDiffInlineMode(),
1503
+ lineStyleClasses: DiffEditorManager.diffLineStyleClasses,
1504
+ unchangedRegionStyleClasses: DiffEditorManager.diffUnchangedRegionStyleClasses,
1505
+ layoutModeClasses: DiffEditorManager.diffLayoutModeClasses,
1506
+ appearanceClasses: DiffEditorManager.diffAppearanceClasses
1507
+ });
862
1508
  }
863
1509
  disposeDiffHunkInteractions() {
864
1510
  if (this.diffHunkHideTimer != null) {
@@ -986,9 +1632,9 @@ var DiffEditorManager = class DiffEditorManager {
986
1632
  });
987
1633
  }
988
1634
  clearFallbackDiffDecorations() {
989
- var _this$diffEditorView11, _this$diffEditorView12;
990
- const originalEditor = (_this$diffEditorView11 = this.diffEditorView) === null || _this$diffEditorView11 === void 0 ? void 0 : _this$diffEditorView11.getOriginalEditor();
991
- const modifiedEditor = (_this$diffEditorView12 = this.diffEditorView) === null || _this$diffEditorView12 === void 0 ? void 0 : _this$diffEditorView12.getModifiedEditor();
1635
+ var _this$diffEditorView, _this$diffEditorView2;
1636
+ const originalEditor = (_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 ? void 0 : _this$diffEditorView.getOriginalEditor();
1637
+ const modifiedEditor = (_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 ? void 0 : _this$diffEditorView2.getModifiedEditor();
992
1638
  if (originalEditor && this.fallbackOriginalDecorationIds.length > 0) this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, []);
993
1639
  else this.fallbackOriginalDecorationIds = [];
994
1640
  if (modifiedEditor && this.fallbackModifiedDecorationIds.length > 0) this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, []);
@@ -996,8 +1642,8 @@ var DiffEditorManager = class DiffEditorManager {
996
1642
  this.clearFallbackInlineDeletedZones();
997
1643
  }
998
1644
  clearFallbackInlineDeletedZones() {
999
- var _this$diffEditorView13;
1000
- const modifiedEditor = (_this$diffEditorView13 = this.diffEditorView) === null || _this$diffEditorView13 === void 0 ? void 0 : _this$diffEditorView13.getModifiedEditor();
1645
+ var _this$diffEditorView3;
1646
+ const modifiedEditor = (_this$diffEditorView3 = this.diffEditorView) === null || _this$diffEditorView3 === void 0 ? void 0 : _this$diffEditorView3.getModifiedEditor();
1001
1647
  if (modifiedEditor && this.fallbackInlineDeletedZoneIds.length > 0) try {
1002
1648
  var _modifiedEditor$chang;
1003
1649
  (_modifiedEditor$chang = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang === void 0 || _modifiedEditor$chang.call(modifiedEditor, (accessor) => {
@@ -1026,8 +1672,7 @@ var DiffEditorManager = class DiffEditorManager {
1026
1672
  }
1027
1673
  syncDiffEditorLayoutToContainer() {
1028
1674
  if (!this.diffEditorView || !this.lastContainer) return;
1029
- const width = this.lastContainer.clientWidth || this.lastContainer.getBoundingClientRect().width;
1030
- const height = this.lastContainer.clientHeight || this.lastContainer.getBoundingClientRect().height;
1675
+ const { width, height } = readContainerLayoutSize(this.lastContainer);
1031
1676
  if (!(width > 0) || !(height > 0)) return;
1032
1677
  try {
1033
1678
  var _layout, _ref;
@@ -1090,7 +1735,7 @@ var DiffEditorManager = class DiffEditorManager {
1090
1735
  }
1091
1736
  const lineHeightOption = (_EditorOption = monaco_shim_exports.editor.EditorOption) === null || _EditorOption === void 0 ? void 0 : _EditorOption.lineHeight;
1092
1737
  const lineHeight = ((_modifiedEditor$getOp = modifiedEditor.getOption) === null || _modifiedEditor$getOp === void 0 ? void 0 : _modifiedEditor$getOp.call(modifiedEditor, lineHeightOption)) ?? 20;
1093
- const relevantChanges = lineChanges.filter((change) => this.hasOriginalLines(change));
1738
+ const relevantChanges = lineChanges.filter((change) => hasOriginalLines(change));
1094
1739
  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) => {
1095
1740
  return node instanceof HTMLElement && !!node.querySelector(".view-lines.line-delete");
1096
1741
  });
@@ -1224,7 +1869,7 @@ var DiffEditorManager = class DiffEditorManager {
1224
1869
  };
1225
1870
  }
1226
1871
  syncDiffPresentationDecorations() {
1227
- var _this$diffEditorView$3, _this$lastContainer$q, _this$lastContainer5;
1872
+ var _this$diffEditorView$, _this$lastContainer$q, _this$lastContainer5;
1228
1873
  if (!this.diffEditorView || !this.lastContainer) return;
1229
1874
  const nativeFresh = this.hasFreshNativeDiffResult();
1230
1875
  const useInlineMode = this.isDiffInlineMode();
@@ -1232,10 +1877,10 @@ var DiffEditorManager = class DiffEditorManager {
1232
1877
  const nativeInlineDeleteZoneCount = useInlineMode ? this.countNativeInlineDeleteZoneNodes() : 0;
1233
1878
  const hasNativeInlineDeleteZoneNodes = nativeInlineDeleteZoneCount > 0;
1234
1879
  const hasNativeInlineDeleteNodes = useInlineMode && this.hasVisibleNativeInlineDeleteNodes();
1235
- const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => this.hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1880
+ const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1236
1881
  const useInlineStaleFallback = shouldKeepInlineFallback;
1237
1882
  this.lastContainer.classList.toggle("stream-monaco-diff-inline-native-ready", useInlineMode && !shouldKeepInlineFallback && (nativeFresh || hasNativeInlineDeleteNodes || hasNativeInlineDeleteZoneNodes));
1238
- 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")));
1883
+ 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")));
1239
1884
  this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh && !keepNativeDecorationsWhileStale);
1240
1885
  if (nativeFresh && !shouldKeepInlineFallback) {
1241
1886
  this.clearFallbackDiffDecorations();
@@ -2510,27 +3155,6 @@ var DiffEditorManager = class DiffEditorManager {
2510
3155
  el.addEventListener(eventName, listener);
2511
3156
  bucket.push({ dispose: () => el.removeEventListener(eventName, listener) });
2512
3157
  }
2513
- createDiffHunkActionNode(side) {
2514
- const node = document.createElement("div");
2515
- node.className = "stream-monaco-diff-hunk-actions";
2516
- node.dataset.side = side;
2517
- const createButton = (action, label) => {
2518
- const button = document.createElement("button");
2519
- button.type = "button";
2520
- button.textContent = label;
2521
- button.dataset.action = action;
2522
- button.addEventListener("click", (event) => {
2523
- event.preventDefault();
2524
- event.stopPropagation();
2525
- this.applyDiffHunkAction(side, action);
2526
- });
2527
- return button;
2528
- };
2529
- node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
2530
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
2531
- this.createDomDisposable(this.diffHunkDisposables, node, "mouseleave", () => this.scheduleHideDiffHunkActions());
2532
- return node;
2533
- }
2534
3158
  cloneSerializableValue(value) {
2535
3159
  if (typeof structuredClone === "function") return structuredClone(value);
2536
3160
  return JSON.parse(JSON.stringify(value));
@@ -2789,8 +3413,8 @@ var DiffEditorManager = class DiffEditorManager {
2789
3413
  this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
2790
3414
  }
2791
3415
  this.withLockedDiffScrollPosition(() => {
2792
- var _this$diffEditorView14;
2793
- (_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || _this$diffEditorView14.updateOptions(presentationOptions);
3416
+ var _this$diffEditorView4;
3417
+ (_this$diffEditorView4 = this.diffEditorView) === null || _this$diffEditorView4 === void 0 || _this$diffEditorView4.updateOptions(presentationOptions);
2794
3418
  });
2795
3419
  (_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 || _this$diffHeightManag.update();
2796
3420
  this.applyDiffRootAppearanceClass();
@@ -2812,8 +3436,8 @@ var DiffEditorManager = class DiffEditorManager {
2812
3436
  if (!this.diffHideUnchangedRegionsDeferred) return;
2813
3437
  this.diffHideUnchangedRegionsDeferred = false;
2814
3438
  this.withLockedDiffScrollPosition(() => {
2815
- var _this$diffEditorView15;
2816
- (_this$diffEditorView15 = this.diffEditorView) === null || _this$diffEditorView15 === void 0 || _this$diffEditorView15.updateOptions({ hideUnchangedRegions });
3439
+ var _this$diffEditorView5;
3440
+ (_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || _this$diffEditorView5.updateOptions({ hideUnchangedRegions });
2817
3441
  });
2818
3442
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2819
3443
  if (this.shouldAutoScrollDiff) {
@@ -2823,7 +3447,7 @@ var DiffEditorManager = class DiffEditorManager {
2823
3447
  }
2824
3448
  markDiffStreamingActivity() {
2825
3449
  var _this$lastContainer6;
2826
- (_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.classList.remove("stream-monaco-diff-inline-native-ready");
3450
+ (_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");
2827
3451
  if (this.isDiffInlineMode()) {
2828
3452
  var _this$diffHeightManag2, _this$lastContainer7, _this$lastContainer7$;
2829
3453
  this.inlineDiffStreamingPresentationActive = true;
@@ -2849,8 +3473,8 @@ var DiffEditorManager = class DiffEditorManager {
2849
3473
  this.diffHideUnchangedRegionsDeferred = true;
2850
3474
  this.hideAllDiffUnchangedBridgeEntries();
2851
3475
  this.withLockedDiffScrollPosition(() => {
2852
- var _this$diffEditorView16;
2853
- (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.updateOptions({ hideUnchangedRegions: {
3476
+ var _this$diffEditorView6;
3477
+ (_this$diffEditorView6 = this.diffEditorView) === null || _this$diffEditorView6 === void 0 || _this$diffEditorView6.updateOptions({ hideUnchangedRegions: {
2854
3478
  ...hideUnchangedRegions,
2855
3479
  enabled: false
2856
3480
  } });
@@ -2924,7 +3548,7 @@ var DiffEditorManager = class DiffEditorManager {
2924
3548
  var _this$diffUnchangedBr;
2925
3549
  this.clearDiffUnchangedBridgeSources();
2926
3550
  if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.replaceChildren();
2927
- if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.style.transform = "translate3d(0px, 0px, 0px)";
3551
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2928
3552
  this.diffUnchangedBridgeEntries.clear();
2929
3553
  this.diffUnchangedBridgePool.length = 0;
2930
3554
  this.diffUnchangedOverlayScrollTop = 0;
@@ -2934,30 +3558,27 @@ var DiffEditorManager = class DiffEditorManager {
2934
3558
  }
2935
3559
  clearDiffUnchangedBridgeSources() {
2936
3560
  if (!this.lastContainer) return;
2937
- const bridgedCenters = this.lastContainer.querySelectorAll(".stream-monaco-unchanged-bridge-source");
2938
- bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
3561
+ clearDiffUnchangedBridgeSourceClasses(this.lastContainer);
2939
3562
  }
2940
3563
  ensureDiffUnchangedBridgeOverlay() {
2941
3564
  if (!this.lastContainer) return null;
2942
3565
  if (!this.diffUnchangedBridgeOverlay) {
2943
- const overlay = document.createElement("div");
2944
- overlay.className = "stream-monaco-diff-unchanged-overlay";
3566
+ const overlay = createDiffUnchangedBridgeOverlay();
2945
3567
  this.lastContainer.append(overlay);
2946
3568
  this.diffUnchangedBridgeOverlay = overlay;
2947
3569
  }
2948
3570
  return this.diffUnchangedBridgeOverlay;
2949
3571
  }
2950
3572
  readDiffUnchangedOverlayScrollState() {
2951
- var _this$diffEditorView17, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
2952
- const modifiedEditor = (_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 ? void 0 : _this$diffEditorView17.getModifiedEditor();
3573
+ var _this$diffEditorView7, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
3574
+ const modifiedEditor = (_this$diffEditorView7 = this.diffEditorView) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.getModifiedEditor();
2953
3575
  return {
2954
3576
  top: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc6 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc6 === void 0 ? void 0 : _modifiedEditor$getSc6.call(modifiedEditor)) ?? 0,
2955
3577
  left: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc7 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc7 === void 0 ? void 0 : _modifiedEditor$getSc7.call(modifiedEditor)) ?? 0
2956
3578
  };
2957
3579
  }
2958
3580
  syncDiffUnchangedOverlayScrollBaseline() {
2959
- const overlay = this.diffUnchangedBridgeOverlay;
2960
- if (overlay) overlay.style.transform = "translate3d(0px, 0px, 0px)";
3581
+ resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
2961
3582
  const { top, left } = this.readDiffUnchangedOverlayScrollState();
2962
3583
  this.diffUnchangedOverlayScrollTop = top;
2963
3584
  this.diffUnchangedOverlayScrollLeft = left;
@@ -2971,28 +3592,10 @@ var DiffEditorManager = class DiffEditorManager {
2971
3592
  if (Math.abs(deltaY) < .5 && Math.abs(deltaX) < .5) return;
2972
3593
  overlay.style.transform = `translate3d(${deltaX}px, ${deltaY}px, 0px)`;
2973
3594
  }
2974
- resolveDiffUnchangedViewZoneHeight() {
2975
- switch (this.resolveDiffUnchangedRegionStyleOption()) {
2976
- case "line-info":
2977
- case "line-info-basic":
2978
- case "metadata": return 32;
2979
- case "simple": return 28;
2980
- default: return 32;
2981
- }
2982
- }
2983
- collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
2984
- 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);
2985
- if (widgetTopValues.length === 0) return [];
2986
- return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
2987
- const zoneTop = Number.parseFloat(node.style.top || "NaN");
2988
- const currentHeight = Number.parseFloat(node.style.height || "0");
2989
- return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
2990
- }).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
2991
- }
2992
3595
  syncDiffUnchangedViewZoneHeightsForEditor(editor, editorRoot, targetHeight) {
2993
3596
  var _editor$getScrollTop, _editorInternal$_mode;
2994
3597
  if (!editor || !(editorRoot instanceof HTMLElement)) return false;
2995
- const zoneIds = this.collectDiffUnchangedViewZoneIds(editorRoot, ((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
3598
+ const zoneIds = collectDiffUnchangedViewZoneIds(editorRoot, ((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
2996
3599
  if (zoneIds.length === 0) return false;
2997
3600
  const editorInternal = editor;
2998
3601
  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;
@@ -3017,7 +3620,7 @@ var DiffEditorManager = class DiffEditorManager {
3017
3620
  syncDiffUnchangedViewZoneHeights() {
3018
3621
  var _originalEditor$getCo, _modifiedEditor$getCo3;
3019
3622
  if (!this.diffEditorView) return false;
3020
- const targetHeight = this.resolveDiffUnchangedViewZoneHeight();
3623
+ const targetHeight = resolveDiffUnchangedViewZoneHeight(this.resolveDiffUnchangedRegionStyleOption());
3021
3624
  const originalEditor = this.diffEditorView.getOriginalEditor();
3022
3625
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
3023
3626
  const originalChanged = this.syncDiffUnchangedViewZoneHeightsForEditor(originalEditor, (_originalEditor$getCo = originalEditor.getContainerDomNode) === null || _originalEditor$getCo === void 0 ? void 0 : _originalEditor$getCo.call(originalEditor), targetHeight);
@@ -3035,19 +3638,7 @@ var DiffEditorManager = class DiffEditorManager {
3035
3638
  return `${this.getDiffUnchangedNodeId(secondaryNode)}:${this.getDiffUnchangedNodeId(primaryNode)}`;
3036
3639
  }
3037
3640
  createDiffUnchangedBridgeEntry(key) {
3038
- const bridge = document.createElement("div");
3039
- bridge.className = "stream-monaco-diff-unchanged-bridge";
3040
- bridge.setAttribute("role", "group");
3041
- bridge.hidden = true;
3042
- const summary = document.createElement("button");
3043
- summary.type = "button";
3044
- summary.className = "stream-monaco-unchanged-summary";
3045
- const visualMeta = document.createElement("div");
3046
- visualMeta.className = "stream-monaco-unchanged-meta";
3047
- summary.append(visualMeta);
3048
- const divider = document.createElement("span");
3049
- divider.className = "stream-monaco-unchanged-pane-divider";
3050
- divider.setAttribute("aria-hidden", "true");
3641
+ const { bridge, summary, visualMeta, divider } = createDiffUnchangedBridgeScaffold();
3051
3642
  const entry = {
3052
3643
  key,
3053
3644
  bridge,
@@ -3066,16 +3657,15 @@ var DiffEditorManager = class DiffEditorManager {
3066
3657
  const onWheel = (event) => {
3067
3658
  var _modifiedEditor$getSc8, _modifiedEditor$getSc9, _originalEditor$setSc6, _modifiedEditor$setSc6;
3068
3659
  if (!this.diffEditorView) return;
3069
- if (Math.abs(event.deltaY) < .5 && Math.abs(event.deltaX) < .5) return;
3660
+ if (!shouldHandleDiffUnchangedWheel(event)) return;
3070
3661
  event.preventDefault();
3071
3662
  event.stopPropagation();
3072
3663
  const originalEditor = this.diffEditorView.getOriginalEditor();
3073
3664
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
3074
- const targetScrollTop = (((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0) + event.deltaY;
3075
- const targetScrollLeft = (((_modifiedEditor$getSc9 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc9 === void 0 ? void 0 : _modifiedEditor$getSc9.call(modifiedEditor)) ?? 0) + event.deltaX;
3665
+ 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);
3076
3666
  (_originalEditor$setSc6 = originalEditor.setScrollTop) === null || _originalEditor$setSc6 === void 0 || _originalEditor$setSc6.call(originalEditor, targetScrollTop);
3077
3667
  (_modifiedEditor$setSc6 = modifiedEditor.setScrollTop) === null || _modifiedEditor$setSc6 === void 0 || _modifiedEditor$setSc6.call(modifiedEditor, targetScrollTop);
3078
- if (Math.abs(event.deltaX) >= .5) {
3668
+ if (syncHorizontal) {
3079
3669
  var _originalEditor$setSc7, _modifiedEditor$setSc7;
3080
3670
  (_originalEditor$setSc7 = originalEditor.setScrollLeft) === null || _originalEditor$setSc7 === void 0 || _originalEditor$setSc7.call(originalEditor, targetScrollLeft);
3081
3671
  (_modifiedEditor$setSc7 = modifiedEditor.setScrollLeft) === null || _modifiedEditor$setSc7 === void 0 || _modifiedEditor$setSc7.call(modifiedEditor, targetScrollLeft);
@@ -3084,7 +3674,6 @@ var DiffEditorManager = class DiffEditorManager {
3084
3674
  };
3085
3675
  bridge.addEventListener("wheel", onWheel, { passive: false });
3086
3676
  this.diffUnchangedRegionDisposables.push({ dispose: () => bridge.removeEventListener("wheel", onWheel) });
3087
- bridge.append(summary, divider);
3088
3677
  return entry;
3089
3678
  }
3090
3679
  acquireDiffUnchangedBridgeEntry(key) {
@@ -3092,16 +3681,14 @@ var DiffEditorManager = class DiffEditorManager {
3092
3681
  if (existing) return existing;
3093
3682
  const entry = this.diffUnchangedBridgePool.pop() ?? this.createDiffUnchangedBridgeEntry(key);
3094
3683
  entry.key = key;
3095
- entry.bridge.hidden = false;
3096
- entry.bridge.removeAttribute("aria-hidden");
3684
+ syncDiffUnchangedBridgeVisibility(entry.bridge, true);
3097
3685
  this.diffUnchangedBridgeEntries.set(key, entry);
3098
3686
  return entry;
3099
3687
  }
3100
3688
  releaseDiffUnchangedBridgeEntry(entry) {
3101
3689
  if (entry.key) this.diffUnchangedBridgeEntries.delete(entry.key);
3102
3690
  entry.key = null;
3103
- entry.bridge.hidden = true;
3104
- entry.bridge.setAttribute("aria-hidden", "true");
3691
+ syncDiffUnchangedBridgeVisibility(entry.bridge, false);
3105
3692
  this.diffUnchangedBridgePool.push(entry);
3106
3693
  }
3107
3694
  hideAllDiffUnchangedBridgeEntries() {
@@ -3127,51 +3714,15 @@ var DiffEditorManager = class DiffEditorManager {
3127
3714
  entry.activate();
3128
3715
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3129
3716
  }
3130
- updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel) {
3131
- this.updateDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
3132
- }
3133
- updateDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
3134
- const lastStyle = metaNode.dataset.style;
3135
- const lastLabel = metaNode.dataset.label;
3136
- if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
3137
- metaNode.dataset.style = unchangedRegionStyle;
3138
- metaNode.dataset.label = summaryLabel;
3139
- metaNode.replaceChildren();
3140
- metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
3141
- if (unchangedRegionStyle === "simple") {
3142
- const simpleBar = document.createElement("span");
3143
- simpleBar.className = "stream-monaco-unchanged-simple-bar";
3144
- simpleBar.setAttribute("aria-hidden", "true");
3145
- metaNode.append(simpleBar);
3146
- return;
3147
- }
3148
- const label = document.createElement("span");
3149
- if (unchangedRegionStyle === "metadata") label.className = "stream-monaco-unchanged-metadata-label";
3150
- else label.className = "stream-monaco-unchanged-count";
3151
- label.textContent = summaryLabel;
3152
- metaNode.append(label);
3153
- }
3154
3717
  syncDiffUnchangedRevealButton(entry, slot, handle, direction, label) {
3155
3718
  const existingButton = entry[slot];
3156
- const button = existingButton ?? document.createElement("button");
3157
- if (!existingButton) {
3158
- button.type = "button";
3159
- button.className = "stream-monaco-unchanged-reveal";
3160
- button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
3161
- }
3162
- button.dataset.direction = direction;
3163
- button.hidden = !handle;
3164
- button.disabled = !handle;
3165
- button.toggleAttribute("aria-hidden", !handle);
3166
- button.title = handle ? label : "";
3167
- button.setAttribute("aria-label", handle ? label : "");
3168
- button.onclick = handle ? (event) => {
3169
- event.preventDefault();
3170
- event.stopPropagation();
3719
+ const button = existingButton ?? createDiffUnchangedRevealButton(direction);
3720
+ syncDiffUnchangedRevealButtonNode(button, handle, label);
3721
+ bindDiffUnchangedRevealButtonAction(button, handle, (nextHandle) => {
3171
3722
  this.hideAllDiffUnchangedBridgeEntries();
3172
- this.activateDiffUnchangedHandle(handle);
3723
+ this.activateDiffUnchangedHandle(nextHandle);
3173
3724
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3174
- } : null;
3725
+ });
3175
3726
  entry[slot] = button;
3176
3727
  }
3177
3728
  syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle, showBottomHandle, bottomHandle) {
@@ -3179,14 +3730,9 @@ var DiffEditorManager = class DiffEditorManager {
3179
3730
  entry.rail = document.createElement("div");
3180
3731
  entry.rail.className = "stream-monaco-unchanged-rail";
3181
3732
  }
3182
- const shouldRenderRail = showTopHandle || showBottomHandle;
3183
3733
  this.syncDiffUnchangedRevealButton(entry, "topButton", showTopHandle ? topHandle : null, "down", "Reveal more unmodified lines below");
3184
3734
  this.syncDiffUnchangedRevealButton(entry, "bottomButton", showBottomHandle ? bottomHandle : null, "up", "Reveal more unmodified lines above");
3185
- entry.rail.hidden = !shouldRenderRail;
3186
- entry.rail.toggleAttribute("aria-hidden", !shouldRenderRail);
3187
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
3188
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
3189
- entry.rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
3735
+ syncDiffUnchangedRailNode(entry.rail, showTopHandle, showBottomHandle);
3190
3736
  if (entry.topButton && entry.topButton.parentElement !== entry.rail) entry.rail.append(entry.topButton);
3191
3737
  if (entry.bottomButton && entry.bottomButton.parentElement !== entry.rail) entry.rail.append(entry.bottomButton);
3192
3738
  }
@@ -3196,201 +3742,46 @@ var DiffEditorManager = class DiffEditorManager {
3196
3742
  this.releaseDiffUnchangedBridgeEntry(entry);
3197
3743
  }
3198
3744
  }
3199
- dispatchSyntheticMouseDown(node) {
3200
- const view = node.ownerDocument.defaultView;
3201
- if (!view) return;
3202
- const rect = node.getBoundingClientRect();
3203
- node.dispatchEvent(new view.MouseEvent("mousedown", {
3204
- bubbles: true,
3205
- cancelable: true,
3206
- button: 0,
3207
- clientX: rect.left + rect.width / 2,
3208
- clientY: rect.top + rect.height / 2
3209
- }));
3210
- }
3211
- dispatchSyntheticMouseTap(node) {
3212
- const view = node.ownerDocument.defaultView;
3213
- if (!view) return;
3214
- const rect = node.getBoundingClientRect();
3215
- const clientX = rect.left + rect.width / 2;
3216
- const clientY = rect.top + rect.height / 2;
3217
- node.dispatchEvent(new view.MouseEvent("mousedown", {
3218
- bubbles: true,
3219
- cancelable: true,
3220
- button: 0,
3221
- clientX,
3222
- clientY
3223
- }));
3224
- node.dispatchEvent(new view.MouseEvent("mouseup", {
3225
- bubbles: true,
3226
- cancelable: true,
3227
- button: 0,
3228
- clientX,
3229
- clientY
3230
- }));
3231
- }
3232
- formatDiffUnchangedCountLabel(text) {
3233
- const match = text.match(/\d+/);
3234
- const count = match ? Number.parseInt(match[0], 10) : NaN;
3235
- if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
3236
- return text.replace(/hidden/gi, "unmodified");
3237
- }
3238
- countDiffLines(startLineNumber, endLineNumber) {
3239
- return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
3240
- }
3241
- measureDiffUnchangedSurroundingLines(primaryNode) {
3242
- const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
3243
- if (!editorRoot) return {
3244
- previousVisibleLine: null,
3245
- nextVisibleLine: null
3246
- };
3247
- const widgetRect = primaryNode.getBoundingClientRect();
3248
- let previousVisibleLine = null;
3249
- let nextVisibleLine = null;
3250
- const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
3251
- lineNumberNodes.forEach((node) => {
3252
- var _node$textContent3;
3253
- const lineNumber = Number.parseInt(((_node$textContent3 = node.textContent) === null || _node$textContent3 === void 0 ? void 0 : _node$textContent3.trim()) || "", 10);
3254
- if (!Number.isFinite(lineNumber)) return;
3255
- const top = node.getBoundingClientRect().top;
3256
- if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
3257
- else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
3258
- });
3259
- return {
3260
- previousVisibleLine,
3261
- nextVisibleLine
3262
- };
3263
- }
3264
- formatDiffMetadataRange(startLineNumber, lineCount) {
3265
- return `${startLineNumber},${Math.max(0, lineCount)}`;
3266
- }
3267
- buildDiffHunkMetadataLabel(change) {
3268
- var _this$originalModel, _this$modifiedModel2;
3269
- const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3270
- const originalTotalLines = ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0;
3271
- const modifiedTotalLines = ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0;
3272
- const originalChangedCount = this.countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
3273
- const modifiedChangedCount = this.countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
3274
- const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
3275
- const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
3276
- const originalStart = Math.max(1, originalAnchor - contextLineCount);
3277
- const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
3278
- const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
3279
- const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
3280
- const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
3281
- const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
3282
- return {
3283
- modifiedStart,
3284
- originalStart,
3285
- label: `@@ -${this.formatDiffMetadataRange(originalStart, originalDisplayCount)} +${this.formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
3286
- };
3287
- }
3288
- resolveDiffMetadataLabel(primaryNode, pairIndex) {
3289
- var _metadataEntries$Math;
3290
- const lineChanges = this.getEffectiveLineChanges();
3291
- if (lineChanges.length === 0) return null;
3292
- const metadataEntries = lineChanges.map((change) => this.buildDiffHunkMetadataLabel(change));
3293
- const { nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
3294
- if (nextVisibleLine != null) {
3295
- const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
3296
- for (const candidateStart of candidateStarts) {
3297
- const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
3298
- if (matching) return matching.label;
3299
- }
3300
- }
3301
- return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
3302
- }
3303
3745
  activateDiffUnchangedHandle(node) {
3304
3746
  if (!(node instanceof HTMLElement)) return;
3305
- this.dispatchSyntheticMouseTap(node);
3747
+ dispatchSyntheticPrimaryMouseTap(node);
3306
3748
  this.scheduleCapturePersistedDiffUnchangedState(1);
3307
3749
  }
3308
- resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount) {
3309
- var _this$diffEditorView18, _this$diffEditorView19;
3310
- let showTopHandle = pairCount === 1 || pairIndex > 0;
3311
- let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
3312
- const countMatch = countText.match(/\d+/);
3313
- const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
3314
- if (!Number.isFinite(hiddenCount)) return {
3315
- showTopHandle,
3316
- showBottomHandle
3317
- };
3318
- const { previousVisibleLine, nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
3319
- if (previousVisibleLine == null && nextVisibleLine != null) {
3320
- showTopHandle = false;
3321
- showBottomHandle = true;
3322
- return {
3323
- showTopHandle,
3324
- showBottomHandle
3325
- };
3326
- }
3327
- if (nextVisibleLine == null && previousVisibleLine != null) {
3328
- showTopHandle = true;
3329
- showBottomHandle = false;
3330
- return {
3331
- showTopHandle,
3332
- showBottomHandle
3333
- };
3334
- }
3335
- if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
3336
- showTopHandle = false;
3337
- showBottomHandle = true;
3338
- }
3339
- 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;
3340
- if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
3341
- showTopHandle = true;
3342
- showBottomHandle = false;
3343
- }
3344
- return {
3345
- showTopHandle,
3346
- showBottomHandle
3347
- };
3348
- }
3349
- resolveDiffUnchangedMergeRole(node) {
3350
- var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24, _this$diffEditorView25;
3351
- const diffRoot = node.closest(".monaco-diff-editor.side-by-side");
3352
- if (!(diffRoot instanceof HTMLElement)) return "none";
3353
- const nodeRect = node.getBoundingClientRect();
3354
- const nodeCenter = nodeRect.left + nodeRect.width / 2;
3355
- 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);
3356
- 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);
3357
- if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
3358
- const originalRect = originalHost.getBoundingClientRect();
3359
- const modifiedRect = modifiedHost.getBoundingClientRect();
3360
- const originalCenter = originalRect.left + originalRect.width / 2;
3361
- const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
3362
- return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
3363
- }
3364
- const diffRect = diffRoot.getBoundingClientRect();
3365
- return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
3366
- }
3367
3750
  patchDiffUnchangedCenter(node, pairIndex = 0) {
3368
- node.classList.add("stream-monaco-clickable");
3369
- node.title = "Click to expand all unmodified lines";
3370
- const mergeRole = this.resolveDiffUnchangedMergeRole(node);
3751
+ var _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10, _this$diffEditorView11, _this$diffEditorView12, _this$diffEditorView13;
3752
+ const mergeRole = resolveDiffUnchangedMergeRole({
3753
+ node,
3754
+ diffRoot: node.closest(".monaco-diff-editor.side-by-side"),
3755
+ 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),
3756
+ 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)
3757
+ });
3371
3758
  const shouldUseMergedSecondary = mergeRole === "secondary";
3372
3759
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3373
- node.classList.toggle("stream-monaco-unchanged-merged-secondary", shouldUseMergedSecondary);
3374
- node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
3760
+ syncDiffUnchangedCenterNode(node, mergeRole);
3375
3761
  const primary = node.children.item(0);
3376
3762
  const meta = node.children.item(1);
3377
3763
  if (primary instanceof HTMLElement) primary.classList.add("stream-monaco-unchanged-primary");
3378
3764
  if (meta instanceof HTMLElement) {
3379
- var _countSource$textCont;
3765
+ var _countSource$textCont, _this$originalModel, _this$modifiedModel2;
3380
3766
  meta.classList.add("stream-monaco-unchanged-meta");
3381
3767
  const countSource = meta.querySelector(".count") ?? meta.firstElementChild;
3382
- 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");
3383
- const summaryLabel = unchangedRegionStyle === "metadata" ? this.resolveDiffMetadataLabel(node, pairIndex) ?? countText : countText;
3384
- this.updateDiffUnchangedMetaNode(meta, unchangedRegionStyle, summaryLabel);
3768
+ const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont = countSource.textContent) === null || _countSource$textCont === void 0 ? void 0 : _countSource$textCont.trim()) || "Unmodified lines");
3769
+ const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3770
+ const summaryLabel = resolveDiffUnchangedSummaryLabel({
3771
+ countText,
3772
+ unchangedRegionStyle,
3773
+ lineChanges: this.getEffectiveLineChanges(),
3774
+ pairIndex,
3775
+ primaryNode: node,
3776
+ contextLineCount,
3777
+ originalTotalLines: ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0,
3778
+ modifiedTotalLines: ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0
3779
+ });
3780
+ syncDiffUnchangedMetaNode(meta, unchangedRegionStyle, summaryLabel);
3385
3781
  }
3386
- const action = node.querySelector("a");
3782
+ const action = findDiffUnchangedExpandAction(node);
3387
3783
  if (action instanceof HTMLElement) {
3388
- action.classList.add("stream-monaco-unchanged-expand");
3389
- action.dataset.streamMonacoLabel = "Expand all";
3390
- action.title = "Expand all unmodified lines";
3391
- action.setAttribute("aria-label", "Expand all unmodified lines");
3392
- action.toggleAttribute("aria-hidden", shouldUseMergedSecondary);
3393
- action.tabIndex = shouldUseMergedSecondary ? -1 : 0;
3784
+ syncDiffUnchangedExpandAction(action, shouldUseMergedSecondary);
3394
3785
  if (action.dataset.streamMonacoExpandPatched !== "true") {
3395
3786
  action.dataset.streamMonacoExpandPatched = "true";
3396
3787
  const handleCaptureExpand = () => {
@@ -3408,28 +3799,21 @@ var DiffEditorManager = class DiffEditorManager {
3408
3799
  if (node.dataset.streamMonacoCenterPatched !== "true") {
3409
3800
  node.dataset.streamMonacoCenterPatched = "true";
3410
3801
  this.bindFocusWithinClass(this.diffUnchangedRegionDisposables, node, "stream-monaco-focus-within");
3411
- const activate = () => {
3412
- const action$1 = node.querySelector("a");
3413
- if (action$1 instanceof HTMLElement) {
3414
- this.capturePreviousDiffUnchangedState();
3415
- action$1.click();
3416
- }
3417
- };
3418
3802
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "click", (event) => {
3419
3803
  const mouseEvent = event;
3420
- if (mouseEvent.button !== 0) return;
3421
- const target = event.target instanceof HTMLElement ? event.target : null;
3422
- if (target === null || target === void 0 ? void 0 : target.closest("a, .breadcrumb-item")) return;
3804
+ if (!shouldHandleDiffUnchangedCenterClick(mouseEvent)) return;
3423
3805
  event.preventDefault();
3424
3806
  this.hideAllDiffUnchangedBridgeEntries();
3425
- activate();
3807
+ if (!activateDiffUnchangedExpandAction(node, () => {
3808
+ this.capturePreviousDiffUnchangedState();
3809
+ })) return;
3426
3810
  this.scheduleCapturePersistedDiffUnchangedState(1);
3427
3811
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3428
3812
  });
3429
3813
  }
3430
3814
  }
3431
3815
  renderMergedDiffUnchangedBridge(secondaryNode, primaryNode, pairIndex, pairCount) {
3432
- var _countSource$textCont2, _secondaryNode$closes;
3816
+ var _countSource$textCont2, _this$originalModel2, _this$modifiedModel3, _this$diffEditorView14, _this$diffEditorView15, _secondaryNode$closes;
3433
3817
  if (!this.lastContainer) return null;
3434
3818
  const overlay = this.ensureDiffUnchangedBridgeOverlay();
3435
3819
  if (!overlay) return null;
@@ -3438,9 +3822,19 @@ var DiffEditorManager = class DiffEditorManager {
3438
3822
  const primaryRect = primaryNode.getBoundingClientRect();
3439
3823
  const primaryStyle = globalThis.getComputedStyle(primaryNode);
3440
3824
  const countSource = primaryNode.querySelector(".stream-monaco-unchanged-count") ?? secondaryNode.querySelector(".stream-monaco-unchanged-count");
3441
- 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");
3825
+ const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont2 = countSource.textContent) === null || _countSource$textCont2 === void 0 ? void 0 : _countSource$textCont2.trim()) || "Unmodified lines");
3442
3826
  const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
3443
- const metadataLabel = unchangedRegionStyle === "metadata" ? this.resolveDiffMetadataLabel(primaryNode, pairIndex) : null;
3827
+ const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
3828
+ const summaryLabel = resolveDiffUnchangedSummaryLabel({
3829
+ countText,
3830
+ unchangedRegionStyle,
3831
+ lineChanges: this.getEffectiveLineChanges(),
3832
+ pairIndex,
3833
+ primaryNode,
3834
+ contextLineCount,
3835
+ originalTotalLines: ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getLineCount()) ?? 0,
3836
+ modifiedTotalLines: ((_this$modifiedModel3 = this.modifiedModel) === null || _this$modifiedModel3 === void 0 ? void 0 : _this$modifiedModel3.getLineCount()) ?? 0
3837
+ });
3444
3838
  const editorSurface = primaryNode.closest(".monaco-editor") ?? primaryNode;
3445
3839
  const editorSurfaceStyle = globalThis.getComputedStyle(editorSurface);
3446
3840
  const primaryHidden = primaryNode.parentElement;
@@ -3449,7 +3843,13 @@ var DiffEditorManager = class DiffEditorManager {
3449
3843
  const secondaryWidget = secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.parentElement;
3450
3844
  const topHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".top")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".top"));
3451
3845
  const bottomHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".bottom")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".bottom"));
3452
- const { showTopHandle, showBottomHandle } = this.resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount);
3846
+ const { showTopHandle, showBottomHandle } = resolveDiffUnchangedRevealLayout({
3847
+ primaryNode,
3848
+ countText,
3849
+ pairIndex,
3850
+ pairCount,
3851
+ 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
3852
+ });
3453
3853
  const key = this.getDiffUnchangedBridgeKey(secondaryNode, primaryNode);
3454
3854
  secondaryNode.classList.add("stream-monaco-unchanged-bridge-source");
3455
3855
  primaryNode.classList.add("stream-monaco-unchanged-bridge-source");
@@ -3461,42 +3861,24 @@ var DiffEditorManager = class DiffEditorManager {
3461
3861
  const primaryAnchorRect = (primaryWidget === null || primaryWidget === void 0 ? void 0 : primaryWidget.getBoundingClientRect()) ?? primaryRect;
3462
3862
  const secondaryMargin = (_secondaryNode$closes = secondaryNode.closest(".monaco-editor")) === null || _secondaryNode$closes === void 0 ? void 0 : _secondaryNode$closes.querySelector(".margin");
3463
3863
  const secondaryMarginRect = secondaryMargin === null || secondaryMargin === void 0 ? void 0 : secondaryMargin.getBoundingClientRect();
3464
- const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? this.resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3864
+ const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
3465
3865
  const bridgeLeftInset = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.leftInset) ?? 0;
3466
3866
  const bridgeRailWidth = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.width) ?? (secondaryMarginRect === null || secondaryMarginRect === void 0 ? void 0 : secondaryMarginRect.width) ?? null;
3467
- bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + this.lastContainer.scrollLeft + bridgeLeftInset}px`;
3468
- bridge.style.top = `${primaryAnchorRect.top - containerRect.top + this.lastContainer.scrollTop}px`;
3469
- bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
3470
- bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
3471
- bridge.style.color = primaryStyle.color;
3472
- bridge.style.fontFamily = primaryStyle.fontFamily;
3473
- bridge.style.fontSize = primaryStyle.fontSize;
3474
- bridge.style.lineHeight = primaryStyle.lineHeight;
3475
- bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
3476
- bridge.style.setProperty("--stream-monaco-editor-bg", editorSurfaceStyle.backgroundColor);
3477
- bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
3478
- if (bridgeRailWidth) bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
3479
- else bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
3480
- 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");
3481
- summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
3482
- const summaryLabel = metadataLabel || countText;
3483
- const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
3484
- summary.disabled = !summaryInteractive;
3485
- summary.tabIndex = summaryInteractive ? 0 : -1;
3486
- if (summaryInteractive) {
3487
- summary.removeAttribute("aria-hidden");
3488
- summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
3489
- summary.title = "Expand all unmodified lines";
3490
- } else if (unchangedRegionStyle === "simple") {
3491
- summary.setAttribute("aria-hidden", "true");
3492
- summary.removeAttribute("aria-label");
3493
- summary.title = "";
3494
- } else {
3495
- summary.removeAttribute("aria-hidden");
3496
- summary.removeAttribute("aria-label");
3497
- summary.title = "";
3498
- }
3499
- this.updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel);
3867
+ syncDiffUnchangedBridgeNode({
3868
+ bridge,
3869
+ unchangedRegionStyle,
3870
+ containerRect,
3871
+ containerScrollLeft: this.lastContainer.scrollLeft,
3872
+ containerScrollTop: this.lastContainer.scrollTop,
3873
+ secondaryAnchorRect,
3874
+ primaryAnchorRect,
3875
+ bridgeLeftInset,
3876
+ bridgeRailWidth,
3877
+ primaryStyle,
3878
+ editorBackgroundColor: editorSurfaceStyle.backgroundColor
3879
+ });
3880
+ syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel);
3881
+ syncDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
3500
3882
  if (unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic") {
3501
3883
  this.syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle ?? null, showBottomHandle, bottomHandle ?? null);
3502
3884
  if (entry.rail && entry.rail.parentElement !== bridge) bridge.prepend(entry.rail);
@@ -3505,7 +3887,7 @@ var DiffEditorManager = class DiffEditorManager {
3505
3887
  entry.rail.setAttribute("aria-hidden", "true");
3506
3888
  }
3507
3889
  entry.activate = () => {
3508
- const action = primaryNode.querySelector("a, button") ?? secondaryNode.querySelector("a, button");
3890
+ const action = findDiffUnchangedActivationAction(primaryNode, secondaryNode);
3509
3891
  if (action instanceof HTMLElement) {
3510
3892
  this.capturePreviousDiffUnchangedState();
3511
3893
  action.click();
@@ -3542,7 +3924,7 @@ var DiffEditorManager = class DiffEditorManager {
3542
3924
  this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3543
3925
  return;
3544
3926
  }
3545
- this.dispatchSyntheticMouseDown(node);
3927
+ dispatchSyntheticPrimaryMouseDown(node);
3546
3928
  this.scheduleCapturePersistedDiffUnchangedState(1);
3547
3929
  });
3548
3930
  }
@@ -3671,8 +4053,12 @@ var DiffEditorManager = class DiffEditorManager {
3671
4053
  overlay.className = "stream-monaco-diff-hunk-overlay";
3672
4054
  this.diffHunkOverlay = overlay;
3673
4055
  this.lastContainer.append(overlay);
3674
- this.diffHunkUpperNode = this.createDiffHunkActionNode("upper");
3675
- this.diffHunkLowerNode = this.createDiffHunkActionNode("lower");
4056
+ this.diffHunkUpperNode = createDiffHunkActionNode("upper", (side, action) => this.applyDiffHunkAction(side, action));
4057
+ this.diffHunkLowerNode = createDiffHunkActionNode("lower", (side, action) => this.applyDiffHunkAction(side, action));
4058
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
4059
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
4060
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
4061
+ this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
3676
4062
  overlay.append(this.diffHunkUpperNode, this.diffHunkLowerNode);
3677
4063
  const originalEditor = this.diffEditorView.getOriginalEditor();
3678
4064
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
@@ -3715,71 +4101,27 @@ var DiffEditorManager = class DiffEditorManager {
3715
4101
  if (this.diffHunkUpperNode) this.diffHunkUpperNode.style.display = "none";
3716
4102
  if (this.diffHunkLowerNode) this.diffHunkLowerNode.style.display = "none";
3717
4103
  }
3718
- inferInlineDiffHunkHoverSide(change, event) {
3719
- var _event$target$positio;
3720
- const targetElement = event.target.element instanceof HTMLElement ? event.target.element : null;
3721
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
3722
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
3723
- if (!this.hasModifiedLines(change)) return "upper";
3724
- if (!this.hasOriginalLines(change)) return "lower";
3725
- const hoverLine = ((_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber) ?? 0;
3726
- const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
3727
- return hoverLine < modifiedAnchor ? "upper" : "lower";
3728
- }
3729
- hasOriginalLines(change) {
3730
- return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
3731
- }
3732
- hasModifiedLines(change) {
3733
- return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
3734
- }
3735
- distanceToLineChange(side, change, line) {
3736
- const hasRange = side === "original" ? this.hasOriginalLines(change) : this.hasModifiedLines(change);
3737
- const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
3738
- const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
3739
- if (hasRange) {
3740
- if (line < start) return start - line;
3741
- if (line > end) return line - end;
3742
- return 0;
3743
- }
3744
- const fallbackAnchor = Math.max(1, start || end || 1);
3745
- return Math.abs(line - fallbackAnchor);
3746
- }
3747
- findLineChangeByHoverLine(side, line) {
3748
- if (this.diffHunkLineChanges.length === 0) return null;
3749
- let best = null;
3750
- let bestDistance = Number.POSITIVE_INFINITY;
3751
- for (const change of this.diffHunkLineChanges) {
3752
- const distance = this.distanceToLineChange(side, change, line);
3753
- if (distance < bestDistance) {
3754
- bestDistance = distance;
3755
- best = change;
3756
- if (distance === 0) break;
3757
- }
3758
- }
3759
- if (bestDistance > 2) return null;
3760
- return best;
3761
- }
3762
4104
  handleDiffHunkMouseMove(side, event) {
3763
- var _event$target$positio2;
3764
- const line = (_event$target$positio2 = event.target.position) === null || _event$target$positio2 === void 0 ? void 0 : _event$target$positio2.lineNumber;
4105
+ var _event$target$positio, _event$target$positio2;
4106
+ const line = (_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber;
3765
4107
  if (!line) {
3766
4108
  this.scheduleHideDiffHunkActions(120);
3767
4109
  return;
3768
4110
  }
3769
- const change = this.findLineChangeByHoverLine(side, line);
4111
+ const change = findLineChangeByHoverLine(this.diffHunkLineChanges, side, line);
3770
4112
  if (!change) {
3771
4113
  this.scheduleHideDiffHunkActions(120);
3772
4114
  return;
3773
4115
  }
3774
4116
  this.cancelScheduledHideDiffHunkActions();
3775
4117
  this.diffHunkActiveChange = change;
3776
- this.diffHunkActiveHoverSide = this.isDiffInlineMode() ? this.inferInlineDiffHunkHoverSide(change, event) : null;
4118
+ 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;
3777
4119
  this.repositionDiffHunkNodes();
3778
4120
  }
3779
4121
  isOriginalEditorCollapsed() {
3780
- var _this$diffEditorView$4, _this$diffEditorView$5;
4122
+ var _this$diffEditorView$2, _this$diffEditorView$3;
3781
4123
  if (!this.diffEditorView) return true;
3782
- 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);
4124
+ 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);
3783
4125
  return !info || info.width < 24;
3784
4126
  }
3785
4127
  isDiffInlineMode() {
@@ -3788,40 +4130,6 @@ var DiffEditorManager = class DiffEditorManager {
3788
4130
  if (typeof HTMLElement !== "undefined" && diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
3789
4131
  return this.isOriginalEditorCollapsed();
3790
4132
  }
3791
- getEditorBySide(side) {
3792
- if (!this.diffEditorView) return null;
3793
- return side === "original" ? this.diffEditorView.getOriginalEditor() : this.diffEditorView.getModifiedEditor();
3794
- }
3795
- getFullLineRange(model, startLine, endLine) {
3796
- if (endLine < startLine) return null;
3797
- const lineCount = model.getLineCount();
3798
- if (lineCount < 1) return null;
3799
- const start = Math.max(1, Math.min(startLine, lineCount));
3800
- const end = Math.max(start, Math.min(endLine, lineCount));
3801
- if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
3802
- return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
3803
- }
3804
- getLinesText(model, startLine, endLine) {
3805
- const range = this.getFullLineRange(model, startLine, endLine);
3806
- if (!range) return "";
3807
- return model.getValueInRange(range);
3808
- }
3809
- getInsertRangeBeforeLine(model, lineNumber) {
3810
- const lineCount = model.getLineCount();
3811
- if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3812
- if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
3813
- const lastLine = lineCount;
3814
- const lastColumn = model.getLineMaxColumn(lastLine);
3815
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3816
- }
3817
- getInsertRangeAfterLine(model, lineNumber) {
3818
- const lineCount = model.getLineCount();
3819
- if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
3820
- if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
3821
- const lastLine = lineCount;
3822
- const lastColumn = model.getLineMaxColumn(lastLine);
3823
- return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
3824
- }
3825
4133
  applyDiffModelLanguage(models, codeLanguage) {
3826
4134
  if (!codeLanguage) return;
3827
4135
  const lang = processedLanguage(codeLanguage);
@@ -3833,8 +4141,8 @@ var DiffEditorManager = class DiffEditorManager {
3833
4141
  if (!this.diffEditorView || !viewState) return;
3834
4142
  const restore = () => {
3835
4143
  try {
3836
- var _this$diffEditorView26;
3837
- (_this$diffEditorView26 = this.diffEditorView) === null || _this$diffEditorView26 === void 0 || _this$diffEditorView26.restoreViewState(viewState);
4144
+ var _this$diffEditorView16;
4145
+ (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.restoreViewState(viewState);
3838
4146
  } catch {}
3839
4147
  };
3840
4148
  restore();
@@ -3852,7 +4160,7 @@ var DiffEditorManager = class DiffEditorManager {
3852
4160
  this.pendingPreparedDiffViewModel = null;
3853
4161
  }
3854
4162
  syncDiffKnownValues() {
3855
- var _this$diffEditorView27, _this$diffEditorView28, _this$diffEditorView29, _this$diffHeightManag4;
4163
+ var _this$diffEditorView17, _this$diffEditorView18, _this$diffEditorView19, _this$diffHeightManag4;
3856
4164
  if (this.originalModel) this.lastKnownOriginalCode = this.originalModel.getValue();
3857
4165
  if (this.modifiedModel) {
3858
4166
  this.lastKnownModifiedCode = this.modifiedModel.getValue();
@@ -3861,67 +4169,15 @@ var DiffEditorManager = class DiffEditorManager {
3861
4169
  this.lastKnownModifiedDirty = false;
3862
4170
  this._hasScrollBar = false;
3863
4171
  this.cachedComputedHeightDiff = this.computedHeight();
3864
- 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;
4172
+ 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;
3865
4173
  (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3866
4174
  }
3867
- applyDefaultDiffHunkAction(context) {
3868
- const { action, side, lineChange } = context;
3869
- if (!this.originalModel || !this.modifiedModel) return;
3870
- const hasOriginal = this.hasOriginalLines(lineChange);
3871
- const hasModified = this.hasModifiedLines(lineChange);
3872
- if (action === "revert" && side === "upper") {
3873
- if (!hasOriginal) return;
3874
- const text = this.getLinesText(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3875
- if (!text) return;
3876
- const range = hasModified ? this.getInsertRangeBeforeLine(this.modifiedModel, lineChange.modifiedStartLineNumber) : this.getInsertRangeAfterLine(this.modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
3877
- this.modifiedModel.applyEdits([{
3878
- range,
3879
- text,
3880
- forceMoveMarkers: true
3881
- }]);
3882
- return;
3883
- }
3884
- if (action === "revert" && side === "lower") {
3885
- if (!hasModified) return;
3886
- const range = this.getFullLineRange(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3887
- if (!range) return;
3888
- this.modifiedModel.applyEdits([{
3889
- range,
3890
- text: "",
3891
- forceMoveMarkers: true
3892
- }]);
3893
- return;
3894
- }
3895
- if (action === "stage" && side === "upper") {
3896
- if (!hasOriginal) return;
3897
- const range = this.getFullLineRange(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
3898
- if (!range) return;
3899
- this.originalModel.applyEdits([{
3900
- range,
3901
- text: "",
3902
- forceMoveMarkers: true
3903
- }]);
3904
- return;
3905
- }
3906
- if (action === "stage" && side === "lower") {
3907
- if (!hasModified) return;
3908
- const text = this.getLinesText(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
3909
- if (!text) return;
3910
- const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
3911
- const range = this.getInsertRangeAfterLine(this.originalModel, anchor);
3912
- this.originalModel.applyEdits([{
3913
- range,
3914
- text,
3915
- forceMoveMarkers: true
3916
- }]);
3917
- }
3918
- }
3919
4175
  async applyDiffHunkAction(side, action) {
3920
4176
  if (!this.diffHunkActiveChange || !this.originalModel || !this.modifiedModel) return;
3921
4177
  if (this.diffHunkActionInFlight) return;
3922
4178
  this.diffHunkActionInFlight = true;
3923
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
3924
- this.setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
4179
+ setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
4180
+ setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
3925
4181
  try {
3926
4182
  this.flushOriginalAppendBufferSync();
3927
4183
  this.flushModifiedAppendBufferSync();
@@ -3938,39 +4194,13 @@ var DiffEditorManager = class DiffEditorManager {
3938
4194
  } catch (error$1) {
3939
4195
  console.warn("onDiffHunkAction callback threw an error:", error$1);
3940
4196
  }
3941
- if (allowDefault) this.applyDefaultDiffHunkAction(context);
4197
+ if (allowDefault) applyDefaultDiffHunkAction(context);
3942
4198
  this.syncDiffKnownValues();
3943
4199
  this.hideDiffHunkActions();
3944
4200
  } finally {
3945
4201
  this.diffHunkActionInFlight = false;
3946
4202
  }
3947
4203
  }
3948
- setDiffHunkNodeEnabled(node, enabled) {
3949
- if (!node) return;
3950
- const buttons = node.querySelectorAll("button");
3951
- buttons.forEach((button) => {
3952
- button.disabled = !enabled;
3953
- });
3954
- }
3955
- positionDiffHunkNode(node, side, anchorLine, extraOffsetY = 0) {
3956
- var _editor$getScrollTop2;
3957
- if (!this.diffHunkOverlay) return;
3958
- const editor = this.getEditorBySide(side);
3959
- if (!editor) return;
3960
- const host = editor.getContainerDomNode();
3961
- const line = Math.max(1, anchorLine);
3962
- const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop2 = editor.getScrollTop) === null || _editor$getScrollTop2 === void 0 ? void 0 : _editor$getScrollTop2.call(editor)) ?? 0);
3963
- const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
3964
- const nodeWidth = node.offsetWidth || 130;
3965
- const nodeHeight = node.offsetHeight || 30;
3966
- const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
3967
- const hostTop = host.offsetTop;
3968
- const minTop = hostTop + 4;
3969
- const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
3970
- const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
3971
- node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
3972
- node.style.display = "flex";
3973
- }
3974
4204
  repositionDiffHunkNodes() {
3975
4205
  if (!this.diffHunkActiveChange) {
3976
4206
  this.hideDiffHunkActions();
@@ -3979,22 +4209,22 @@ var DiffEditorManager = class DiffEditorManager {
3979
4209
  if (!this.diffHunkUpperNode || !this.diffHunkLowerNode) return;
3980
4210
  if (!this.diffEditorView) return;
3981
4211
  const change = this.diffHunkActiveChange;
3982
- const hasOriginal = this.hasOriginalLines(change);
3983
- const hasModified = this.hasModifiedLines(change);
3984
- this.setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
3985
- this.setDiffHunkNodeEnabled(this.diffHunkLowerNode, hasModified);
4212
+ const hasOriginal = hasOriginalLines(change);
4213
+ const hasModified = hasModifiedLines(change);
4214
+ setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
4215
+ setDiffHunkNodeEnabled(this.diffHunkLowerNode, hasModified);
3986
4216
  const inlineMode = this.isDiffInlineMode();
3987
4217
  if (inlineMode) {
3988
4218
  const inlineHoverSide = this.diffHunkActiveHoverSide ?? (hasOriginal && !hasModified ? "upper" : "lower");
3989
4219
  if (inlineHoverSide === "upper" && hasOriginal) {
3990
4220
  const upperAnchor = Math.max(1, change.modifiedStartLineNumber - 1 || change.modifiedEndLineNumber || 1);
3991
- this.positionDiffHunkNode(this.diffHunkUpperNode, "modified", upperAnchor);
4221
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getModifiedEditor(), upperAnchor);
3992
4222
  this.diffHunkLowerNode.style.display = "none";
3993
4223
  return;
3994
4224
  }
3995
4225
  if (hasModified) {
3996
4226
  const lowerAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
3997
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4227
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
3998
4228
  this.diffHunkUpperNode.style.display = "none";
3999
4229
  return;
4000
4230
  }
@@ -4002,13 +4232,12 @@ var DiffEditorManager = class DiffEditorManager {
4002
4232
  return;
4003
4233
  }
4004
4234
  if (hasOriginal) {
4005
- const upperSide = "original";
4006
4235
  const upperAnchor = change.originalStartLineNumber;
4007
- this.positionDiffHunkNode(this.diffHunkUpperNode, upperSide, upperAnchor);
4236
+ positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getOriginalEditor(), upperAnchor);
4008
4237
  } else this.diffHunkUpperNode.style.display = "none";
4009
4238
  if (hasModified) {
4010
4239
  const lowerAnchor = change.modifiedStartLineNumber;
4011
- this.positionDiffHunkNode(this.diffHunkLowerNode, "modified", lowerAnchor);
4240
+ positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
4012
4241
  } else this.diffHunkLowerNode.style.display = "none";
4013
4242
  }
4014
4243
  scheduleFlushAppendBufferDiff() {
@@ -4047,26 +4276,20 @@ var DiffEditorManager = class DiffEditorManager {
4047
4276
  this.appendToModel(this.originalModel, text);
4048
4277
  }
4049
4278
  computeRawHeight() {
4050
- var _originalEditor$getMo, _modifiedEditor$getMo2, _originalEditor$getSc5, _modifiedEditor$getSc10;
4051
- if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
4052
- const modifiedEditor = this.diffEditorView.getModifiedEditor();
4053
- const originalEditor = this.diffEditorView.getOriginalEditor();
4054
- const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
4055
- const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
4056
- const mCount = ((_modifiedEditor$getMo2 = modifiedEditor.getModel()) === null || _modifiedEditor$getMo2 === void 0 ? void 0 : _modifiedEditor$getMo2.getLineCount()) ?? 1;
4057
- const lineCount = Math.max(oCount, mCount);
4058
- const fromLines = lineCount * lineHeight + padding;
4059
- 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);
4060
- const desired = Math.max(fromLines, scrollH);
4061
- return Math.min(desired, this.maxHeightValue);
4279
+ return computeDiffRawHeight({
4280
+ diffEditorView: this.diffEditorView,
4281
+ maxHeightValue: this.maxHeightValue
4282
+ });
4062
4283
  }
4063
4284
  computedHeight() {
4064
- const rawHeight = this.computeRawHeight();
4065
- if (!this.isDiffInlineMode()) return rawHeight;
4066
- if (!this.inlineDiffStreamingPresentationActive && this.inlineDiffStreamingHeightFloor <= 0) return rawHeight;
4067
- const lockedHeight = Math.max(rawHeight, this.inlineDiffStreamingHeightFloor);
4068
- this.inlineDiffStreamingHeightFloor = lockedHeight;
4069
- return lockedHeight;
4285
+ const { height, nextInlineDiffStreamingHeightFloor } = computeDiffHeight({
4286
+ rawHeight: this.computeRawHeight(),
4287
+ isInlineMode: this.isDiffInlineMode(),
4288
+ inlineDiffStreamingPresentationActive: this.inlineDiffStreamingPresentationActive,
4289
+ inlineDiffStreamingHeightFloor: this.inlineDiffStreamingHeightFloor
4290
+ });
4291
+ this.inlineDiffStreamingHeightFloor = nextInlineDiffStreamingHeightFloor;
4292
+ return height;
4070
4293
  }
4071
4294
  eagerlyGrowDiffContainerHeight() {
4072
4295
  var _this$lastContainer$g, _this$lastContainer10;
@@ -4111,17 +4334,22 @@ var DiffEditorManager = class DiffEditorManager {
4111
4334
  if (this._hasScrollBar) return true;
4112
4335
  const m = this.measureViewportDiff();
4113
4336
  if (!m) return false;
4114
- const epsilon = Math.max(2, Math.round(m.lineHeight / 8));
4115
- return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
4337
+ return this._hasScrollBar = hasVerticalScrollbar(m);
4116
4338
  }
4117
4339
  userIsNearBottomDiff() {
4118
4340
  if (!this.diffEditorView) return true;
4119
4341
  const m = this.measureViewportDiff();
4120
4342
  if (!m || !m.li) return true;
4121
- const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
4122
- const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
4123
- const distance = m.scrollHeight - (m.scrollTop + m.li.height);
4124
- return distance <= threshold;
4343
+ return isUserNearBottom({
4344
+ computedHeight: m.computedHeight,
4345
+ lineHeight: m.lineHeight,
4346
+ scrollHeight: m.scrollHeight,
4347
+ scrollTop: m.scrollTop,
4348
+ viewportHeight: m.li.height
4349
+ }, {
4350
+ autoScrollThresholdLines: this.autoScrollThresholdLines ?? 0,
4351
+ autoScrollThresholdPx: this.autoScrollThresholdPx || 0
4352
+ });
4125
4353
  }
4126
4354
  maybeScrollDiffToBottom(targetLine, prevLineOverride) {
4127
4355
  this.rafScheduler.schedule("maybe-scroll-diff", () => {
@@ -4197,7 +4425,7 @@ var DiffEditorManager = class DiffEditorManager {
4197
4425
  }
4198
4426
  performRevealDiffTicketed(line, ticket) {
4199
4427
  this.rafScheduler.schedule("revealDiff", () => {
4200
- var _editor;
4428
+ var _editor$1;
4201
4429
  if (this.diffScrollWatcher) {
4202
4430
  log("diff", "performRevealDiffTicketed - suppressing watcher", {
4203
4431
  ticket,
@@ -4212,16 +4440,11 @@ var DiffEditorManager = class DiffEditorManager {
4212
4440
  line
4213
4441
  });
4214
4442
  const strategy = this.diffHideUnchangedRegionsDeferred ? "bottom" : this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
4215
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
4216
- const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
4443
+ const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
4444
+ const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
4217
4445
  try {
4218
4446
  const me = this.diffEditorView.getModifiedEditor();
4219
- if (strategy === "bottom") if (typeof smooth !== "undefined") me.revealLine(line, smooth);
4220
- else me.revealLine(line);
4221
- else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
4222
- else me.revealLineInCenter(line);
4223
- else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
4224
- else me.revealLineInCenterIfOutsideViewport(line);
4447
+ revealEditorLine(me, line, strategy, smooth);
4225
4448
  } catch {
4226
4449
  try {
4227
4450
  this.diffEditorView.getModifiedEditor().revealLine(line);
@@ -4233,8 +4456,8 @@ var DiffEditorManager = class DiffEditorManager {
4233
4456
  lastRevealLineDiff: this.lastRevealLineDiff
4234
4457
  });
4235
4458
  try {
4236
- var _this$diffEditorView30, _this$diffEditorView31, _this$diffEditorView32;
4237
- 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;
4459
+ var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22;
4460
+ 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;
4238
4461
  } catch {}
4239
4462
  });
4240
4463
  }
@@ -4242,11 +4465,10 @@ var DiffEditorManager = class DiffEditorManager {
4242
4465
  var _editor2;
4243
4466
  if (!this.diffEditorView) return;
4244
4467
  if (ticket !== this.revealTicketDiff) return;
4245
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
4246
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
4468
+ const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
4469
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
4247
4470
  const me = this.diffEditorView.getModifiedEditor();
4248
- if (typeof immediate !== "undefined") me.revealLine(line, immediate);
4249
- else me.revealLine(line);
4471
+ revealEditorLine(me, line, "bottom", immediate);
4250
4472
  this.measureViewportDiff();
4251
4473
  log("diff", "performImmediateRevealDiff", {
4252
4474
  line,
@@ -4266,22 +4488,7 @@ var DiffEditorManager = class DiffEditorManager {
4266
4488
  });
4267
4489
  }
4268
4490
  waitForHeightAppliedDiff(target, timeoutMs = 500) {
4269
- return new Promise((resolve) => {
4270
- const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
4271
- const check = () => {
4272
- const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
4273
- if (applied >= target - 1) {
4274
- resolve();
4275
- return;
4276
- }
4277
- if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
4278
- resolve();
4279
- return;
4280
- }
4281
- requestAnimationFrame(check);
4282
- };
4283
- check();
4284
- });
4491
+ return waitForElementHeightApplied(this.lastContainer, target, timeoutMs);
4285
4492
  }
4286
4493
  async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
4287
4494
  var _me$getScrollHeight2, _me$getOption, _oEditor$onDidLayoutC, _mEditor$onDidLayoutC, _oEditor$onDidContent, _mEditor$onDidContent;
@@ -4430,8 +4637,8 @@ var DiffEditorManager = class DiffEditorManager {
4430
4637
  if (this.lastContainer) {
4431
4638
  this.lastContainer.style.overflow = "hidden";
4432
4639
  if (computed$2 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
4433
- var _this$modifiedModel3;
4434
- this.maybeScrollDiffToBottom((_this$modifiedModel3 = this.modifiedModel) === null || _this$modifiedModel3 === void 0 ? void 0 : _this$modifiedModel3.getLineCount());
4640
+ var _this$modifiedModel4;
4641
+ this.maybeScrollDiffToBottom((_this$modifiedModel4 = this.modifiedModel) === null || _this$modifiedModel4 === void 0 ? void 0 : _this$modifiedModel4.getLineCount());
4435
4642
  }
4436
4643
  }
4437
4644
  });
@@ -4454,13 +4661,14 @@ var DiffEditorManager = class DiffEditorManager {
4454
4661
  if (this.lastContainer) {
4455
4662
  this.lastContainer.style.overflow = "hidden";
4456
4663
  if (computed$2 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
4457
- var _this$modifiedModel4;
4458
- this.maybeScrollDiffToBottom((_this$modifiedModel4 = this.modifiedModel) === null || _this$modifiedModel4 === void 0 ? void 0 : _this$modifiedModel4.getLineCount());
4664
+ var _this$modifiedModel5;
4665
+ this.maybeScrollDiffToBottom((_this$modifiedModel5 = this.modifiedModel) === null || _this$modifiedModel5 === void 0 ? void 0 : _this$modifiedModel5.getLineCount());
4459
4666
  }
4460
4667
  }
4461
4668
  });
4462
4669
  });
4463
4670
  mEditor.onDidChangeModelContent(() => {
4671
+ if (this.programmaticModifiedContentChangeDepth > 0) return;
4464
4672
  this.lastKnownModifiedDirty = true;
4465
4673
  this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
4466
4674
  });
@@ -4604,7 +4812,7 @@ var DiffEditorManager = class DiffEditorManager {
4604
4812
  if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
4605
4813
  }
4606
4814
  async setDiffModels(models, options = {}) {
4607
- var _this$originalModel2, _this$modifiedModel5, _this$diffEditorView$6, _this$diffEditorView$7, _this$diffEditorView$8, _this$diffEditorView$9;
4815
+ var _this$originalModel3, _this$modifiedModel6, _this$diffEditorView$4, _this$diffEditorView$5, _this$diffEditorView$6, _this$diffEditorView$7;
4608
4816
  if (!this.diffEditorView) return;
4609
4817
  const transitionRequestId = ++this.diffModelTransitionRequestId;
4610
4818
  this.preserveNativeDiffDecorationsOnStaleAppend = false;
@@ -4612,8 +4820,8 @@ var DiffEditorManager = class DiffEditorManager {
4612
4820
  const nextOriginal = models.original;
4613
4821
  const nextModified = models.modified;
4614
4822
  this.applyDiffModelLanguage(models, options.codeLanguage);
4615
- const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getValue()) ?? null;
4616
- const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$modifiedModel5 = this.modifiedModel) === null || _this$modifiedModel5 === void 0 ? void 0 : _this$modifiedModel5.getValue()) ?? null;
4823
+ const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel3 = this.originalModel) === null || _this$originalModel3 === void 0 ? void 0 : _this$originalModel3.getValue()) ?? null;
4824
+ const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$modifiedModel6 = this.modifiedModel) === null || _this$modifiedModel6 === void 0 ? void 0 : _this$modifiedModel6.getValue()) ?? null;
4617
4825
  const nextOriginalValue = nextOriginal.getValue();
4618
4826
  const nextModifiedValue = nextModified.getValue();
4619
4827
  const sameContent = currentOriginalValue === nextOriginalValue && currentModifiedValue === nextModifiedValue;
@@ -4669,8 +4877,8 @@ var DiffEditorManager = class DiffEditorManager {
4669
4877
  this.queuePendingDiffScrollRestore(preservedScrollPosition, shouldRestorePersistedUnchangedState ? 2 : 0);
4670
4878
  if (shouldRestorePersistedUnchangedState) this.capturePersistedDiffUnchangedState();
4671
4879
  const applyModelSwap = () => {
4672
- var _this$diffEditorView33;
4673
- (_this$diffEditorView33 = this.diffEditorView) === null || _this$diffEditorView33 === void 0 || _this$diffEditorView33.setModel(nextModelTarget);
4880
+ var _this$diffEditorView23;
4881
+ (_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || _this$diffEditorView23.setModel(nextModelTarget);
4674
4882
  };
4675
4883
  if (preserveViewState) this.withLockedDiffScrollPosition(applyModelSwap);
4676
4884
  else applyModelSwap();
@@ -4685,8 +4893,8 @@ var DiffEditorManager = class DiffEditorManager {
4685
4893
  this.lastKnownModifiedLineCount = nextModified.getLineCount();
4686
4894
  this.lastKnownModifiedDirty = false;
4687
4895
  this._hasScrollBar = false;
4688
- 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;
4689
- 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;
4896
+ 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;
4897
+ 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;
4690
4898
  this.cachedComputedHeightDiff = this.computedHeight();
4691
4899
  this.diffHunkLineChanges = this.getEffectiveLineChanges();
4692
4900
  this.hideDiffHunkActions();
@@ -4922,11 +5130,13 @@ var DiffEditorManager = class DiffEditorManager {
4922
5130
  const lastColumn$1 = model.getLineMaxColumn(prevLine);
4923
5131
  const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
4924
5132
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4925
- model.applyEdits([{
4926
- range: range$1,
4927
- text: part,
4928
- forceMoveMarkers: true
4929
- }]);
5133
+ this.runAsProgrammaticModifiedContentChange(() => {
5134
+ model.applyEdits([{
5135
+ range: range$1,
5136
+ text: part,
5137
+ forceMoveMarkers: true
5138
+ }]);
5139
+ });
4930
5140
  this.lastKnownModifiedCode = model.getValue();
4931
5141
  const newLine$1 = model.getLineCount();
4932
5142
  this.lastKnownModifiedLineCount = newLine$1;
@@ -4962,11 +5172,13 @@ var DiffEditorManager = class DiffEditorManager {
4962
5172
  const lastColumn = model.getLineMaxColumn(prevLine);
4963
5173
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
4964
5174
  this.preserveNativeDiffDecorationsOnStaleAppend = true;
4965
- model.applyEdits([{
4966
- range,
4967
- text,
4968
- forceMoveMarkers: true
4969
- }]);
5175
+ this.runAsProgrammaticModifiedContentChange(() => {
5176
+ model.applyEdits([{
5177
+ range,
5178
+ text,
5179
+ forceMoveMarkers: true
5180
+ }]);
5181
+ });
4970
5182
  this.lastKnownModifiedCode = model.getValue();
4971
5183
  const newLine = model.getLineCount();
4972
5184
  this.lastKnownModifiedLineCount = newLine;
@@ -4979,17 +5191,19 @@ var DiffEditorManager = class DiffEditorManager {
4979
5191
  else this.maybeScrollDiffToBottom(newLine, prevLine);
4980
5192
  if (suppressedByFlush) watcherApi.setSuppressed(false);
4981
5193
  try {
4982
- var _this$diffEditorView34, _this$diffEditorView35, _this$diffEditorView36;
4983
- 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;
5194
+ var _this$diffEditorView24, _this$diffEditorView25, _this$diffEditorView26;
5195
+ 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;
4984
5196
  } catch {}
4985
5197
  }
4986
5198
  applyMinimalEditToModel(model, prev, next) {
4987
- const maxChars = minimalEditMaxChars;
4988
- const ratio = minimalEditMaxChangeRatio;
5199
+ const maxChars = this.minimalEditMaxCharsValue;
5200
+ const ratio = this.minimalEditMaxChangeRatioValue;
4989
5201
  const maxLen = Math.max(prev.length, next.length);
4990
5202
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
4991
5203
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
4992
- model.setValue(next);
5204
+ this.applyModelEdit(model, () => {
5205
+ model.setValue(next);
5206
+ });
4993
5207
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
4994
5208
  return;
4995
5209
  }
@@ -4999,11 +5213,13 @@ var DiffEditorManager = class DiffEditorManager {
4999
5213
  const rangeStart = model.getPositionAt(start);
5000
5214
  const rangeEnd = model.getPositionAt(endPrevIncl + 1);
5001
5215
  const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
5002
- model.applyEdits([{
5003
- range,
5004
- text: replaceText,
5005
- forceMoveMarkers: true
5006
- }]);
5216
+ this.applyModelEdit(model, () => {
5217
+ model.applyEdits([{
5218
+ range,
5219
+ text: replaceText,
5220
+ forceMoveMarkers: true
5221
+ }]);
5222
+ });
5007
5223
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
5008
5224
  }
5009
5225
  appendToModel(model, appendText) {
@@ -5011,13 +5227,30 @@ var DiffEditorManager = class DiffEditorManager {
5011
5227
  const lastLine = model.getLineCount();
5012
5228
  const lastColumn = model.getLineMaxColumn(lastLine);
5013
5229
  const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
5014
- model.applyEdits([{
5015
- range,
5016
- text: appendText,
5017
- forceMoveMarkers: true
5018
- }]);
5230
+ this.applyModelEdit(model, () => {
5231
+ model.applyEdits([{
5232
+ range,
5233
+ text: appendText,
5234
+ forceMoveMarkers: true
5235
+ }]);
5236
+ });
5019
5237
  if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
5020
5238
  }
5239
+ applyModelEdit(model, fn) {
5240
+ if (model === this.modifiedModel) {
5241
+ this.runAsProgrammaticModifiedContentChange(fn);
5242
+ return;
5243
+ }
5244
+ fn();
5245
+ }
5246
+ runAsProgrammaticModifiedContentChange(fn) {
5247
+ this.programmaticModifiedContentChangeDepth += 1;
5248
+ try {
5249
+ fn();
5250
+ } finally {
5251
+ this.programmaticModifiedContentChangeDepth -= 1;
5252
+ }
5253
+ }
5021
5254
  };
5022
5255
 
5023
5256
  //#endregion
@@ -5029,6 +5262,8 @@ var EditorManager = class {
5029
5262
  pendingUpdate = null;
5030
5263
  _hasScrollBar = false;
5031
5264
  updateThrottleMs = 50;
5265
+ minimalEditMaxCharsValue = minimalEditMaxChars;
5266
+ minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
5032
5267
  lastUpdateFlushTime = 0;
5033
5268
  updateThrottleTimer = null;
5034
5269
  shouldAutoScroll = true;
@@ -5084,6 +5319,8 @@ var EditorManager = class {
5084
5319
  this.revealDebounceMsOption = revealDebounceMsOption;
5085
5320
  this.updateThrottleMsOption = updateThrottleMsOption;
5086
5321
  this.updateThrottleMs = this.updateThrottleMsOption ?? this.options.updateThrottleMs ?? 50;
5322
+ this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
5323
+ this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
5087
5324
  }
5088
5325
  cancelRafs() {
5089
5326
  this.rafScheduler.cancel("update");
@@ -5218,7 +5455,7 @@ var EditorManager = class {
5218
5455
  }
5219
5456
  performReveal(line, ticket) {
5220
5457
  this.rafScheduler.schedule("reveal", () => {
5221
- var _editor;
5458
+ var _editor$1;
5222
5459
  if (ticket !== this.revealTicket) {
5223
5460
  this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
5224
5461
  return;
@@ -5226,8 +5463,8 @@ var EditorManager = class {
5226
5463
  this.dlog("performReveal executing, ticket=", ticket, "line=", line);
5227
5464
  const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
5228
5465
  this.dlog("performReveal strategy=", strategy);
5229
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
5230
- const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
5466
+ const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
5467
+ const smooth = ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
5231
5468
  try {
5232
5469
  if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
5233
5470
  else this.editorView.revealLine(line);
@@ -5251,8 +5488,8 @@ var EditorManager = class {
5251
5488
  this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
5252
5489
  return;
5253
5490
  }
5254
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
5255
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
5491
+ const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
5492
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
5256
5493
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
5257
5494
  else this.editorView.revealLine(line);
5258
5495
  } catch {}
@@ -5264,8 +5501,8 @@ var EditorManager = class {
5264
5501
  try {
5265
5502
  var _editor3;
5266
5503
  if (!this.editorView) return;
5267
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
5268
- const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
5504
+ const ScrollType$1 = ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
5505
+ const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
5269
5506
  if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
5270
5507
  else this.editorView.revealLine(line);
5271
5508
  } catch {}
@@ -5349,9 +5586,10 @@ var EditorManager = class {
5349
5586
  try {
5350
5587
  var _this$editorView8, _this$editorHeightMan, _this$editorHeightMan2;
5351
5588
  this.dlog("content-size-change frame");
5589
+ 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;
5590
+ this.cachedComputedHeight = null;
5352
5591
  const m = this.measureViewport();
5353
5592
  this.dlog("content-size-change measure", m);
5354
- 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;
5355
5593
  if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
5356
5594
  this.dlog("content-size-change skipped height update (suppressed)");
5357
5595
  return;
@@ -5405,6 +5643,7 @@ var EditorManager = class {
5405
5643
  if (model) {
5406
5644
  this.lastKnownCode = model.getValue();
5407
5645
  this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
5646
+ this.cachedComputedHeight = null;
5408
5647
  }
5409
5648
  this.lastKnownCodeDirty = false;
5410
5649
  }
@@ -5505,6 +5744,7 @@ var EditorManager = class {
5505
5744
  this.lastKnownCode = newCode;
5506
5745
  const newLineCount$1 = model.getLineCount();
5507
5746
  this.cachedLineCount = newLineCount$1;
5747
+ this.cachedComputedHeight = null;
5508
5748
  if (newLineCount$1 !== prevLineCount$1) {
5509
5749
  const shouldImmediate = this.shouldPerformImmediateReveal();
5510
5750
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
@@ -5533,7 +5773,6 @@ var EditorManager = class {
5533
5773
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
5534
5774
  const suffix = newCode.slice(prevCode.length);
5535
5775
  if (suffix) this.appendCode(suffix, codeLanguage);
5536
- this.lastKnownCode = newCode;
5537
5776
  return;
5538
5777
  }
5539
5778
  const prevLineCount = model.getLineCount();
@@ -5541,6 +5780,7 @@ var EditorManager = class {
5541
5780
  this.lastKnownCode = newCode;
5542
5781
  const newLineCount = model.getLineCount();
5543
5782
  this.cachedLineCount = newLineCount;
5783
+ this.cachedComputedHeight = null;
5544
5784
  if (newLineCount !== prevLineCount) {
5545
5785
  const shouldImmediate = this.shouldPerformImmediateReveal();
5546
5786
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
@@ -5566,8 +5806,8 @@ var EditorManager = class {
5566
5806
  if (!this.editorView) return;
5567
5807
  const model = this.editorView.getModel();
5568
5808
  if (!model) return;
5569
- const maxChars = minimalEditMaxChars;
5570
- const ratio = minimalEditMaxChangeRatio;
5809
+ const maxChars = this.minimalEditMaxCharsValue;
5810
+ const ratio = this.minimalEditMaxChangeRatioValue;
5571
5811
  const maxLen = Math.max(prev.length, next.length);
5572
5812
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
5573
5813
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
@@ -5630,6 +5870,7 @@ var EditorManager = class {
5630
5870
  const newLineCount = model.getLineCount();
5631
5871
  if (lastLine !== newLineCount) {
5632
5872
  this.cachedLineCount = newLineCount;
5873
+ this.cachedComputedHeight = null;
5633
5874
  const shouldImmediate = this.shouldPerformImmediateReveal();
5634
5875
  if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5635
5876
  const computed$2 = this.computedHeight(this.editorView);
@@ -5651,6 +5892,10 @@ var EditorManager = class {
5651
5892
  getEditorView() {
5652
5893
  return this.editorView;
5653
5894
  }
5895
+ getCode() {
5896
+ var _this$editorView9;
5897
+ return ((_this$editorView9 = this.editorView) === null || _this$editorView9 === void 0 || (_this$editorView9 = _this$editorView9.getModel()) === null || _this$editorView9 === void 0 ? void 0 : _this$editorView9.getValue()) ?? null;
5898
+ }
5654
5899
  setUpdateThrottleMs(ms) {
5655
5900
  this.updateThrottleMs = ms;
5656
5901
  if (!this.updateThrottleMs && this.updateThrottleTimer != null) {
@@ -5833,6 +6078,14 @@ async function ensureMonacoHighlighter(themes, languages$1) {
5833
6078
  */
5834
6079
  function clearHighlighterCache() {
5835
6080
  highlighterCache.clear();
6081
+ monacoHighlighterPromise = null;
6082
+ lastPatchedHighlighter = null;
6083
+ lastPatchedLanguages = /* @__PURE__ */ new Set();
6084
+ monacoThemeByKey.clear();
6085
+ monacoLanguageSet.clear();
6086
+ themeRegisterPromise = null;
6087
+ languagesRegistered = false;
6088
+ currentLanguages = [];
5836
6089
  }
5837
6090
  function serializeThemes(themes) {
5838
6091
  return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
@@ -6072,15 +6325,13 @@ let globalAppliedThemeName = null;
6072
6325
  function useMonaco(monacoOptions = {}) {
6073
6326
  var _monacoOptions$themes;
6074
6327
  const disposals = [];
6075
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.forEach((d) => d.dispose());
6076
- if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
6328
+ const pendingCreateDisposables = /* @__PURE__ */ new Map();
6077
6329
  let editorView = null;
6078
6330
  let editorMgr = null;
6079
6331
  let diffEditorView = null;
6080
6332
  let diffMgr = null;
6081
6333
  let originalModel = null;
6082
6334
  let modifiedModel = null;
6083
- let _hasScrollBar = false;
6084
6335
  const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
6085
6336
  if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
6086
6337
  const languages$1 = monacoOptions.languages ?? defaultLanguages;
@@ -6101,22 +6352,12 @@ function useMonaco(monacoOptions = {}) {
6101
6352
  };
6102
6353
  const maxHeightValue = getMaxHeightValue();
6103
6354
  const maxHeightCSS = getMaxHeightCSS();
6104
- let lastContainer = null;
6105
- let lastKnownCode = null;
6106
- const minimalEditMaxCharsLocal = monacoOptions.minimalEditMaxChars ?? minimalEditMaxChars;
6107
- const minimalEditMaxChangeRatioLocal = monacoOptions.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
6108
- let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
6109
- let lastFlushTime = 0;
6110
- let updateThrottleTimer = null;
6111
- let pendingUpdate = null;
6112
- let shouldAutoScroll = true;
6113
- const cachedComputedHeight = null;
6114
- const appendBuffer = [];
6115
- let appendBufferScheduled = false;
6355
+ let createRequestSeq = 0;
6356
+ let activeCreateRequestId = null;
6357
+ let activeCreateKind = null;
6358
+ let queuedEditorUpdateDuringCreate = null;
6116
6359
  const currentTheme = computed$1(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
6117
6360
  let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
6118
- let themeWatcher = null;
6119
- const rafScheduler = createRafScheduler();
6120
6361
  async function tryLoadAndSetShikiTheme(highlighter, themeName) {
6121
6362
  if (!highlighter || typeof highlighter.setTheme !== "function") return;
6122
6363
  try {
@@ -6187,326 +6428,206 @@ function useMonaco(monacoOptions = {}) {
6187
6428
  const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
6188
6429
  await registerMonacoThemes(list, languages$1);
6189
6430
  }
6190
- function hasVerticalScrollbar() {
6191
- if (!editorView) return false;
6192
- if (_hasScrollBar) return true;
6193
- const ch = cachedComputedHeight ?? computedHeight(editorView);
6194
- return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
6195
- }
6196
- let revealDebounceId = null;
6197
- const revealDebounceMs = 75;
6198
- function maybeScrollToBottom(targetLine) {
6199
- if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
6200
- const model = editorView.getModel();
6201
- const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
6202
- if (revealDebounceId != null) {
6203
- clearTimeout(revealDebounceId);
6204
- revealDebounceId = null;
6205
- }
6206
- revealDebounceId = setTimeout(() => {
6207
- revealDebounceId = null;
6208
- rafScheduler.schedule("reveal", () => {
6209
- try {
6210
- var _editor;
6211
- const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
6212
- if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
6213
- else editorView.revealLineInCenterIfOutsideViewport(line);
6214
- } catch {}
6215
- });
6216
- }, revealDebounceMs);
6217
- }
6431
+ function resolveRequestedThemeName() {
6432
+ return requestedThemeName ?? globalRequestedThemeName ?? monacoOptions.theme ?? currentTheme.value;
6218
6433
  }
6219
- async function createEditor(container, code, language) {
6220
- cleanupEditor();
6221
- lastContainer = container;
6222
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
6223
- disposals.forEach((d) => d.dispose());
6224
- disposals.length = 0;
6225
- }
6226
- if (monacoOptions.onBeforeCreate) {
6227
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
6228
- if (ds) disposals.push(...ds);
6229
- }
6230
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
6231
- await ensureThemeRegistered(initialThemeName);
6232
- editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, updateThrottleMs);
6233
- editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
6234
- if (pendingUpdate && editorMgr) {
6235
- const { code: queuedCode, lang: queuedLang } = pendingUpdate;
6236
- pendingUpdate = null;
6237
- editorMgr.updateCode(queuedCode, queuedLang);
6238
- }
6239
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
6240
- if (editorView) lastKnownCode = editorView.getValue();
6241
- return editorView;
6242
- }
6243
- function computedHeight(editorView$1) {
6244
- var _getModel;
6245
- const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
6246
- const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
6247
- const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
6248
- return height;
6434
+ function commitAppliedTheme(themeName) {
6435
+ requestedThemeName = themeName;
6436
+ globalRequestedThemeName = themeName;
6437
+ globalAppliedThemeName = themeName;
6438
+ monacoOptions.theme = themeName;
6249
6439
  }
6250
- async function createDiffEditor(container, originalCode, modifiedCode, language) {
6251
- cleanupEditor();
6252
- lastContainer = container;
6253
- if (monacoOptions.isCleanOnBeforeCreate ?? true) {
6254
- disposals.forEach((d) => d.dispose());
6255
- disposals.length = 0;
6256
- }
6257
- if (monacoOptions.onBeforeCreate) {
6258
- const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
6259
- if (ds) disposals.push(...ds);
6260
- }
6261
- const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
6262
- await ensureThemeRegistered(initialThemeName);
6440
+ async function notifyThemeApplied(themeName) {
6441
+ if (typeof monacoOptions.onThemeChange !== "function") return;
6263
6442
  try {
6264
- monaco_shim_exports.editor.setTheme(initialThemeName);
6443
+ await monacoOptions.onThemeChange(themeName);
6444
+ } catch (err) {
6445
+ console.warn("onThemeChange callback threw an error:", err);
6446
+ }
6447
+ }
6448
+ function disposeDisposables(items) {
6449
+ if (!(items === null || items === void 0 ? void 0 : items.length)) return;
6450
+ for (const item of items) try {
6451
+ item.dispose();
6265
6452
  } catch {}
6266
- diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
6267
- diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
6268
- if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
6269
- const models = diffMgr.getDiffModels();
6270
- originalModel = models.original;
6271
- modifiedModel = models.modified;
6272
- return diffEditorView;
6273
- }
6274
- function clearFallbackAsyncWork() {
6275
- rafScheduler.cancel("update");
6276
- rafScheduler.cancel("append");
6277
- rafScheduler.cancel("reveal");
6278
- pendingUpdate = null;
6279
- appendBufferScheduled = false;
6280
- appendBuffer.length = 0;
6281
- if (revealDebounceId != null) {
6282
- clearTimeout(revealDebounceId);
6283
- revealDebounceId = null;
6284
- }
6285
- if (updateThrottleTimer != null) {
6286
- clearTimeout(updateThrottleTimer);
6287
- updateThrottleTimer = null;
6288
- }
6289
- lastFlushTime = 0;
6290
6453
  }
6291
- function cleanupEditor() {
6454
+ function takePendingCreateDisposables(requestId) {
6455
+ const items = pendingCreateDisposables.get(requestId) ?? [];
6456
+ pendingCreateDisposables.delete(requestId);
6457
+ return items;
6458
+ }
6459
+ function disposeAllPendingCreateDisposables() {
6460
+ for (const requestId of Array.from(pendingCreateDisposables.keys())) disposeDisposables(takePendingCreateDisposables(requestId));
6461
+ }
6462
+ function cleanupInstances() {
6292
6463
  if (editorMgr) {
6293
6464
  editorMgr.cleanup();
6294
6465
  editorMgr = null;
6295
- }
6466
+ } else if (editorView) try {
6467
+ editorView.dispose();
6468
+ } catch {}
6296
6469
  if (diffMgr) {
6297
6470
  diffMgr.cleanup();
6298
6471
  diffMgr = null;
6472
+ } else {
6473
+ try {
6474
+ diffEditorView === null || diffEditorView === void 0 || diffEditorView.dispose();
6475
+ } catch {}
6476
+ try {
6477
+ originalModel === null || originalModel === void 0 || originalModel.dispose();
6478
+ } catch {}
6479
+ try {
6480
+ modifiedModel === null || modifiedModel === void 0 || modifiedModel.dispose();
6481
+ } catch {}
6299
6482
  }
6300
- clearFallbackAsyncWork();
6301
- if (!editorMgr && editorView) {
6302
- editorView.dispose();
6303
- editorView = null;
6304
- }
6305
- lastKnownCode = null;
6306
- if (lastContainer) {
6307
- lastContainer.innerHTML = "";
6308
- lastContainer = null;
6309
- }
6310
- if (themeWatcher) {
6311
- themeWatcher();
6312
- themeWatcher = null;
6313
- }
6483
+ editorView = null;
6314
6484
  diffEditorView = null;
6315
6485
  originalModel = null;
6316
6486
  modifiedModel = null;
6317
6487
  }
6318
- function appendCode(appendText, codeLanguage) {
6319
- if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
6320
- else {
6321
- if (!editorView) return;
6322
- const model = editorView.getModel();
6323
- if (!model) return;
6324
- const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
6325
- if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
6326
- if (appendText && lastKnownCode != null) lastKnownCode = lastKnownCode + appendText;
6327
- if (appendText) {
6328
- appendBuffer.push(appendText);
6329
- if (!appendBufferScheduled) {
6330
- appendBufferScheduled = true;
6331
- rafScheduler.schedule("append", flushAppendBuffer);
6332
- }
6333
- }
6488
+ function createSupersededError() {
6489
+ const err = new Error("Editor creation was superseded");
6490
+ err.name = "AbortError";
6491
+ err.code = "STREAM_MONACO_CREATE_SUPERSEDED";
6492
+ return err;
6493
+ }
6494
+ function isCreateActive(requestId, kind) {
6495
+ return activeCreateRequestId === requestId && activeCreateKind === kind;
6496
+ }
6497
+ function assertCreateStillActive(requestId, kind) {
6498
+ if (!isCreateActive(requestId, kind)) throw createSupersededError();
6499
+ }
6500
+ function cancelPendingCreates() {
6501
+ activeCreateRequestId = null;
6502
+ activeCreateKind = null;
6503
+ queuedEditorUpdateDuringCreate = null;
6504
+ disposeAllPendingCreateDisposables();
6505
+ }
6506
+ async function resolveCreateThemeName(requestId, kind) {
6507
+ let themeName = resolveRequestedThemeName();
6508
+ while (true) {
6509
+ assertCreateStillActive(requestId, kind);
6510
+ await ensureThemeRegistered(themeName);
6511
+ assertCreateStillActive(requestId, kind);
6512
+ const latestThemeName = resolveRequestedThemeName();
6513
+ if (latestThemeName === themeName) return themeName;
6514
+ themeName = latestThemeName;
6334
6515
  }
6335
6516
  }
6336
- function applyMinimalEdit(prev, next) {
6337
- if (!editorView) return;
6338
- const model = editorView.getModel();
6339
- if (!model) return;
6517
+ async function createEditor(container, code, language) {
6518
+ var _monacoOptions$onBefo;
6519
+ cancelPendingCreates();
6520
+ cleanupInstances();
6521
+ const requestId = ++createRequestSeq;
6522
+ activeCreateRequestId = requestId;
6523
+ activeCreateKind = "editor";
6524
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6525
+ const requestDisposables = ((_monacoOptions$onBefo = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo === void 0 ? void 0 : _monacoOptions$onBefo.call(monacoOptions, monaco_shim_exports)) ?? [];
6526
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6527
+ let nextEditorMgr = null;
6340
6528
  try {
6341
- const maxChars = minimalEditMaxCharsLocal;
6342
- const ratio = minimalEditMaxChangeRatioLocal;
6343
- const maxLen = Math.max(prev.length, next.length);
6344
- const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
6345
- if (prev.length + next.length > maxChars || changeRatio > ratio) {
6346
- const prevLineCount = model.getLineCount();
6347
- model.setValue(next);
6348
- lastKnownCode = next;
6349
- const newLineCount = model.getLineCount();
6350
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6351
- return;
6352
- }
6353
- } catch {}
6354
- const res = computeMinimalEdit(prev, next);
6355
- if (!res) return;
6356
- const { start, endPrevIncl, replaceText } = res;
6357
- const rangeStart = model.getPositionAt(start);
6358
- const rangeEnd = model.getPositionAt(endPrevIncl + 1);
6359
- const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
6360
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
6361
- const edit = [{
6362
- range,
6363
- text: replaceText,
6364
- forceMoveMarkers: true
6365
- }];
6366
- if (isReadOnly) model.applyEdits(edit);
6367
- else editorView.executeEdits("minimal-replace", edit);
6368
- }
6369
- function flushPendingUpdate() {
6370
- if (!pendingUpdate) return;
6371
- lastFlushTime = Date.now();
6372
- if (!editorView) return;
6373
- const model = editorView.getModel();
6374
- if (!model) return;
6375
- const { code: newCode, lang: codeLanguage } = pendingUpdate;
6376
- pendingUpdate = null;
6377
- const processedCodeLanguage = processedLanguage(codeLanguage);
6378
- let prevCode = null;
6379
- if (appendBuffer.length > 0) {
6380
- appendBuffer.length = 0;
6381
- appendBufferScheduled = false;
6382
- rafScheduler.cancel("append");
6383
- try {
6384
- prevCode = model.getValue();
6385
- lastKnownCode = prevCode;
6386
- } catch {
6387
- prevCode = lastKnownCode ?? "";
6529
+ const initialThemeName = await resolveCreateThemeName(requestId, "editor");
6530
+ nextEditorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, monacoOptions.updateThrottleMs);
6531
+ const nextEditorView = await nextEditorMgr.createEditor(container, code, language, initialThemeName);
6532
+ assertCreateStillActive(requestId, "editor");
6533
+ editorMgr = nextEditorMgr;
6534
+ editorView = nextEditorView;
6535
+ diffMgr = null;
6536
+ diffEditorView = null;
6537
+ originalModel = null;
6538
+ modifiedModel = null;
6539
+ commitAppliedTheme(initialThemeName);
6540
+ const committedDisposables = takePendingCreateDisposables(requestId);
6541
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6542
+ activeCreateRequestId = null;
6543
+ activeCreateKind = null;
6544
+ const queuedUpdate = queuedEditorUpdateDuringCreate;
6545
+ if ((queuedUpdate === null || queuedUpdate === void 0 ? void 0 : queuedUpdate.requestId) === requestId) {
6546
+ queuedEditorUpdateDuringCreate = null;
6547
+ editorMgr.updateCode(queuedUpdate.code, queuedUpdate.lang);
6388
6548
  }
6389
- } else {
6390
- prevCode = lastKnownCode;
6391
- if (prevCode == null) try {
6392
- prevCode = model.getValue();
6393
- lastKnownCode = prevCode;
6394
- } catch {
6395
- prevCode = "";
6549
+ await notifyThemeApplied(initialThemeName);
6550
+ return nextEditorView;
6551
+ } catch (error$1) {
6552
+ if (nextEditorMgr) try {
6553
+ nextEditorMgr.cleanup();
6554
+ } catch {}
6555
+ disposeDisposables(takePendingCreateDisposables(requestId));
6556
+ if (activeCreateRequestId === requestId) {
6557
+ activeCreateRequestId = null;
6558
+ activeCreateKind = null;
6559
+ queuedEditorUpdateDuringCreate = null;
6396
6560
  }
6561
+ throw error$1;
6397
6562
  }
6398
- if (prevCode === newCode) return;
6399
- const languageId = model.getLanguageId();
6400
- if (languageId !== processedCodeLanguage) {
6401
- if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
6402
- const prevLineCount = model.getLineCount();
6403
- model.setValue(newCode);
6404
- lastKnownCode = newCode;
6405
- const newLineCount = model.getLineCount();
6406
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6407
- return;
6408
- }
6409
- if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
6410
- const suffix = newCode.slice(prevCode.length);
6411
- if (suffix) appendCode(suffix, codeLanguage);
6412
- lastKnownCode = newCode;
6413
- return;
6414
- }
6415
- try {
6416
- const maxChars = minimalEditMaxCharsLocal;
6417
- const ratio = minimalEditMaxChangeRatioLocal;
6418
- const maxLen = Math.max(prevCode.length, newCode.length);
6419
- const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
6420
- if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
6421
- const prevLineCount = model.getLineCount();
6422
- model.setValue(newCode);
6423
- lastKnownCode = newCode;
6424
- const newLineCount = model.getLineCount();
6425
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6426
- return;
6427
- }
6428
- } catch {}
6563
+ }
6564
+ async function createDiffEditor(container, originalCode, modifiedCode, language) {
6565
+ var _monacoOptions$onBefo2;
6566
+ cancelPendingCreates();
6567
+ cleanupInstances();
6568
+ const requestId = ++createRequestSeq;
6569
+ activeCreateRequestId = requestId;
6570
+ activeCreateKind = "diff";
6571
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
6572
+ const requestDisposables = ((_monacoOptions$onBefo2 = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo2 === void 0 ? void 0 : _monacoOptions$onBefo2.call(monacoOptions, monaco_shim_exports)) ?? [];
6573
+ if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
6574
+ let nextDiffMgr = null;
6429
6575
  try {
6430
- applyMinimalEdit(prevCode, newCode);
6431
- lastKnownCode = newCode;
6432
- const newLineCount = model.getLineCount();
6433
- const prevLineCount = (prevCode ? prevCode.split("\n").length : 0) || model.getLineCount();
6434
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6435
- } catch {
6436
- try {
6437
- const prevLineCount = model.getLineCount();
6438
- model.setValue(newCode);
6439
- lastKnownCode = newCode;
6440
- const newLineCount = model.getLineCount();
6441
- if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
6576
+ const initialThemeName = await resolveCreateThemeName(requestId, "diff");
6577
+ nextDiffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
6578
+ const nextDiffEditorView = await nextDiffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
6579
+ assertCreateStillActive(requestId, "diff");
6580
+ diffMgr = nextDiffMgr;
6581
+ diffEditorView = nextDiffEditorView;
6582
+ editorMgr = null;
6583
+ editorView = null;
6584
+ const models = diffMgr.getDiffModels();
6585
+ originalModel = models.original;
6586
+ modifiedModel = models.modified;
6587
+ commitAppliedTheme(initialThemeName);
6588
+ const committedDisposables = takePendingCreateDisposables(requestId);
6589
+ if (committedDisposables.length) disposals.push(...committedDisposables);
6590
+ activeCreateRequestId = null;
6591
+ activeCreateKind = null;
6592
+ await notifyThemeApplied(initialThemeName);
6593
+ return nextDiffEditorView;
6594
+ } catch (error$1) {
6595
+ if (nextDiffMgr) try {
6596
+ nextDiffMgr.cleanup();
6442
6597
  } catch {}
6598
+ disposeDisposables(takePendingCreateDisposables(requestId));
6599
+ if (activeCreateRequestId === requestId) {
6600
+ activeCreateRequestId = null;
6601
+ activeCreateKind = null;
6602
+ }
6603
+ throw error$1;
6443
6604
  }
6444
6605
  }
6445
- function flushAppendBuffer() {
6446
- if (!editorView) return;
6447
- if (appendBuffer.length === 0) return;
6448
- appendBufferScheduled = false;
6449
- const model = editorView.getModel();
6450
- if (!model) {
6451
- appendBuffer.length = 0;
6452
- return;
6453
- }
6454
- const text = appendBuffer.join("");
6455
- appendBuffer.length = 0;
6456
- try {
6457
- const lastLine = model.getLineCount();
6458
- const lastColumn = model.getLineMaxColumn(lastLine);
6459
- const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
6460
- const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
6461
- if (isReadOnly) model.applyEdits([{
6462
- range,
6463
- text,
6464
- forceMoveMarkers: true
6465
- }]);
6466
- else editorView.executeEdits("append", [{
6467
- range,
6468
- text,
6469
- forceMoveMarkers: true
6470
- }]);
6471
- if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
6472
- try {
6473
- if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
6474
- } catch {}
6475
- } catch {}
6606
+ function cleanupEditor() {
6607
+ cancelPendingCreates();
6608
+ cleanupInstances();
6609
+ disposeDisposables(disposals.splice(0));
6610
+ }
6611
+ function appendCode(appendText, codeLanguage) {
6612
+ if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
6476
6613
  }
6477
6614
  function updateCode(newCode, codeLanguage) {
6478
- if (editorMgr) editorMgr.updateCode(newCode, codeLanguage);
6479
- else {
6480
- pendingUpdate = {
6481
- code: newCode,
6482
- lang: codeLanguage
6483
- };
6484
- rafScheduler.schedule("update", () => {
6485
- if (!updateThrottleMs) {
6486
- flushPendingUpdate();
6487
- return;
6488
- }
6489
- const now = Date.now();
6490
- const since = now - lastFlushTime;
6491
- if (since >= updateThrottleMs) {
6492
- flushPendingUpdate();
6493
- return;
6494
- }
6495
- if (updateThrottleTimer != null) return;
6496
- const wait = updateThrottleMs - since;
6497
- updateThrottleTimer = setTimeout(() => {
6498
- updateThrottleTimer = null;
6499
- rafScheduler.schedule("update", () => flushPendingUpdate());
6500
- }, wait);
6501
- });
6615
+ if (editorMgr) {
6616
+ editorMgr.updateCode(newCode, codeLanguage);
6617
+ return;
6502
6618
  }
6619
+ if (activeCreateRequestId != null && activeCreateKind === "editor") queuedEditorUpdateDuringCreate = {
6620
+ requestId: activeCreateRequestId,
6621
+ code: newCode,
6622
+ lang: codeLanguage
6623
+ };
6503
6624
  }
6504
6625
  function setUpdateThrottleMs(ms) {
6505
- updateThrottleMs = ms;
6626
+ monacoOptions.updateThrottleMs = ms;
6506
6627
  editorMgr === null || editorMgr === void 0 || editorMgr.setUpdateThrottleMs(ms);
6507
6628
  }
6508
6629
  function getUpdateThrottleMs() {
6509
- return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? updateThrottleMs;
6630
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? monacoOptions.updateThrottleMs ?? 50;
6510
6631
  }
6511
6632
  function updateDiff(originalCode, modifiedCode, codeLanguage) {
6512
6633
  if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
@@ -6538,15 +6659,12 @@ function useMonaco(monacoOptions = {}) {
6538
6659
  createDiffEditor,
6539
6660
  cleanupEditor,
6540
6661
  safeClean() {
6541
- clearFallbackAsyncWork();
6542
6662
  if (editorMgr) try {
6543
6663
  editorMgr.safeClean();
6544
6664
  } catch {}
6545
6665
  if (diffMgr) try {
6546
6666
  diffMgr.safeClean();
6547
6667
  } catch {}
6548
- _hasScrollBar = false;
6549
- shouldAutoScroll = !!autoScrollInitial;
6550
6668
  },
6551
6669
  updateCode,
6552
6670
  appendCode,
@@ -6583,10 +6701,10 @@ function useMonaco(monacoOptions = {}) {
6583
6701
  return monaco_shim_exports.editor;
6584
6702
  },
6585
6703
  getEditorView() {
6586
- return editorView;
6704
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getEditorView()) ?? editorView;
6587
6705
  },
6588
6706
  getDiffEditorView() {
6589
- return diffEditorView;
6707
+ return (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffEditorView()) ?? diffEditorView;
6590
6708
  },
6591
6709
  getDiffModels() {
6592
6710
  if (diffMgr) return diffMgr.getDiffModels();
@@ -6601,18 +6719,22 @@ function useMonaco(monacoOptions = {}) {
6601
6719
  setUpdateThrottleMs,
6602
6720
  getUpdateThrottleMs,
6603
6721
  getCode() {
6722
+ if (editorMgr) return editorMgr.getCode();
6604
6723
  if (editorView) try {
6605
6724
  var _editorView$getModel;
6606
6725
  return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
6607
6726
  } catch {
6608
6727
  return null;
6609
6728
  }
6610
- if (diffEditorView || originalModel && modifiedModel) try {
6611
- const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
6612
- const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
6729
+ const diffModels = (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffModels()) ?? {
6730
+ original: originalModel,
6731
+ modified: modifiedModel
6732
+ };
6733
+ if (diffEditorView || diffModels.original && diffModels.modified) try {
6734
+ var _diffModels$original, _diffModels$modified;
6613
6735
  return {
6614
- original,
6615
- modified
6736
+ original: ((_diffModels$original = diffModels.original) === null || _diffModels$original === void 0 ? void 0 : _diffModels$original.getValue()) ?? "",
6737
+ modified: ((_diffModels$modified = diffModels.modified) === null || _diffModels$modified === void 0 ? void 0 : _diffModels$modified.getValue()) ?? ""
6616
6738
  };
6617
6739
  } catch {
6618
6740
  return null;