stream-monaco 0.0.20 → 0.0.22

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.
@@ -548,9 +548,16 @@ var DiffEditorManager = class DiffEditorManager {
548
548
  diffHunkFallbackVersions = null;
549
549
  diffHunkActionInFlight = false;
550
550
  diffComputedVersions = null;
551
+ preserveNativeDiffDecorationsOnStaleAppend = false;
551
552
  diffPresentationDisposables = [];
553
+ diffPresentationObserver = null;
552
554
  fallbackOriginalDecorationIds = [];
553
555
  fallbackModifiedDecorationIds = [];
556
+ fallbackInlineDeletedZoneIds = [];
557
+ fallbackInlineDeletedZoneSignature = null;
558
+ inlineDiffStreamingPresentationActive = false;
559
+ inlineDiffStreamingPresentationIdleTimer = null;
560
+ inlineDiffStreamingHeightFloor = 0;
554
561
  diffHunkHideTimer = null;
555
562
  diffUnchangedRegionDisposables = [];
556
563
  diffUnchangedRegionObserver = null;
@@ -563,7 +570,55 @@ var DiffEditorManager = class DiffEditorManager {
563
570
  diffUnchangedOverlayScrollLeft = 0;
564
571
  diffRootAppearanceSignature = null;
565
572
  diffPersistedUnchangedModelState = null;
573
+ diffPreviousUnchangedModelState = null;
566
574
  pendingPreparedDiffViewModel = null;
575
+ cancelRafs() {
576
+ this.rafScheduler.cancel("sync-diff-presentation");
577
+ this.rafScheduler.cancel("sync-diff-layout");
578
+ this.rafScheduler.cancel("capture-diff-unchanged-state");
579
+ this.rafScheduler.cancel("restore-diff-unchanged-state");
580
+ this.rafScheduler.cancel("patch-diff-unchanged-regions");
581
+ this.rafScheduler.cancel("maybe-scroll-diff");
582
+ this.rafScheduler.cancel("revealDiff");
583
+ this.rafScheduler.cancel("immediate-reveal-diff");
584
+ this.rafScheduler.cancel("maybe-resume-diff");
585
+ this.rafScheduler.cancel("content-size-change-diff");
586
+ this.rafScheduler.cancel("sync-last-known-modified");
587
+ this.rafScheduler.cancel("diff");
588
+ this.rafScheduler.cancel("appendDiff");
589
+ }
590
+ clearRevealTimers() {
591
+ if (this.revealDebounceIdDiff != null) {
592
+ clearTimeout(this.revealDebounceIdDiff);
593
+ this.revealDebounceIdDiff = null;
594
+ }
595
+ if (this.revealIdleTimerIdDiff != null) {
596
+ clearTimeout(this.revealIdleTimerIdDiff);
597
+ this.revealIdleTimerIdDiff = null;
598
+ }
599
+ }
600
+ resetAppendState() {
601
+ this.appendBufferDiffScheduled = false;
602
+ this.appendBufferOriginalDiff.length = 0;
603
+ this.appendBufferModifiedDiff.length = 0;
604
+ if (this.appendFlushThrottleTimerDiff != null) {
605
+ clearTimeout(this.appendFlushThrottleTimerDiff);
606
+ this.appendFlushThrottleTimerDiff = null;
607
+ }
608
+ }
609
+ clearAsyncWork() {
610
+ this.cancelRafs();
611
+ this.pendingDiffUpdate = null;
612
+ this.lastKnownModifiedDirty = false;
613
+ this.resetAppendState();
614
+ this.clearRevealTimers();
615
+ if (this.diffScrollWatcherSuppressionTimer != null) {
616
+ clearTimeout(this.diffScrollWatcherSuppressionTimer);
617
+ this.diffScrollWatcherSuppressionTimer = null;
618
+ }
619
+ this.cancelScheduledHideDiffHunkActions();
620
+ this.clearPendingDiffThemeSync();
621
+ }
567
622
  diffModelTransitionRequestId = 0;
568
623
  pendingDiffScrollRestorePosition = null;
569
624
  pendingDiffScrollRestoreBudget = 0;
@@ -606,6 +661,9 @@ var DiffEditorManager = class DiffEditorManager {
606
661
  revealLineCount: 5
607
662
  };
608
663
  }
664
+ resolveDiffGlyphMarginOption(hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption()) {
665
+ return (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) ? true : this.options.glyphMargin;
666
+ }
609
667
  resolveDiffLineStyleOption() {
610
668
  return this.options.diffLineStyle === "bar" ? "bar" : "background";
611
669
  }
@@ -935,6 +993,220 @@ var DiffEditorManager = class DiffEditorManager {
935
993
  else this.fallbackOriginalDecorationIds = [];
936
994
  if (modifiedEditor && this.fallbackModifiedDecorationIds.length > 0) this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, []);
937
995
  else this.fallbackModifiedDecorationIds = [];
996
+ this.clearFallbackInlineDeletedZones();
997
+ }
998
+ clearFallbackInlineDeletedZones() {
999
+ var _this$diffEditorView13;
1000
+ const modifiedEditor = (_this$diffEditorView13 = this.diffEditorView) === null || _this$diffEditorView13 === void 0 ? void 0 : _this$diffEditorView13.getModifiedEditor();
1001
+ if (modifiedEditor && this.fallbackInlineDeletedZoneIds.length > 0) try {
1002
+ var _modifiedEditor$chang;
1003
+ (_modifiedEditor$chang = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang === void 0 || _modifiedEditor$chang.call(modifiedEditor, (accessor) => {
1004
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1005
+ });
1006
+ } catch {}
1007
+ this.fallbackInlineDeletedZoneIds = [];
1008
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1009
+ this.fallbackInlineDeletedZoneSignature = null;
1010
+ }
1011
+ clearFallbackInlineDeletedZoneWrapperContent() {
1012
+ var _this$lastContainer, _this$lastContainer2, _node$parentElement;
1013
+ const querySelectorAll = typeof ((_this$lastContainer = this.lastContainer) === null || _this$lastContainer === void 0 ? void 0 : _this$lastContainer.querySelectorAll) === "function" ? (_this$lastContainer2 = this.lastContainer) === null || _this$lastContainer2 === void 0 ? void 0 : _this$lastContainer2.querySelectorAll.bind(this.lastContainer) : null;
1014
+ if (!querySelectorAll) return;
1015
+ const nodes = Array.from(querySelectorAll(".stream-monaco-fallback-inline-delete-zone[data-stream-monaco-native-wrapper=\"true\"], .stream-monaco-fallback-inline-delete-margin[data-stream-monaco-native-wrapper=\"true\"]") ?? []);
1016
+ for (const node of nodes) (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 || _node$parentElement.removeChild(node);
1017
+ }
1018
+ clearInlineDiffStreamingPresentationIdleTimer() {
1019
+ if (this.inlineDiffStreamingPresentationIdleTimer != null) {
1020
+ clearTimeout(this.inlineDiffStreamingPresentationIdleTimer);
1021
+ this.inlineDiffStreamingPresentationIdleTimer = null;
1022
+ }
1023
+ }
1024
+ resetInlineDiffStreamingHeightFloor() {
1025
+ this.inlineDiffStreamingHeightFloor = 0;
1026
+ }
1027
+ syncDiffEditorLayoutToContainer() {
1028
+ 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;
1031
+ if (!(width > 0) || !(height > 0)) return;
1032
+ try {
1033
+ var _layout, _ref;
1034
+ (_layout = (_ref = this.diffEditorView).layout) === null || _layout === void 0 || _layout.call(_ref, {
1035
+ width: Math.round(width),
1036
+ height: Math.round(height)
1037
+ });
1038
+ } catch {
1039
+ try {
1040
+ var _layout2, _ref2;
1041
+ (_layout2 = (_ref2 = this.diffEditorView).layout) === null || _layout2 === void 0 || _layout2.call(_ref2);
1042
+ } catch {}
1043
+ }
1044
+ }
1045
+ scheduleSyncDiffEditorLayoutToContainer() {
1046
+ this.rafScheduler.schedule("sync-diff-layout", () => {
1047
+ this.syncDiffEditorLayoutToContainer();
1048
+ });
1049
+ }
1050
+ readModelLineContent(model, lineNumber) {
1051
+ const direct = model.getLineContent;
1052
+ if (typeof direct === "function") return direct.call(model, lineNumber);
1053
+ return model.getValue().split(/\r?\n/)[lineNumber - 1] ?? "";
1054
+ }
1055
+ hasVisibleNativeInlineDeleteNodes() {
1056
+ if (!this.lastContainer) return false;
1057
+ const querySelectorAll = typeof this.lastContainer.querySelectorAll === "function" ? this.lastContainer.querySelectorAll.bind(this.lastContainer) : null;
1058
+ if (!querySelectorAll) return false;
1059
+ const nodes = Array.from(querySelectorAll(".editor.modified .view-zones .line-delete, .editor.modified .inline-deleted-text, .editor.modified .inline-deleted-margin-view-zone") ?? []);
1060
+ return nodes.some((node) => {
1061
+ var _node$getBoundingClie, _globalThis$getComput, _globalThis;
1062
+ if (!(node instanceof HTMLElement)) return false;
1063
+ const rect = (_node$getBoundingClie = node.getBoundingClientRect) === null || _node$getBoundingClie === void 0 ? void 0 : _node$getBoundingClie.call(node);
1064
+ const style = (_globalThis$getComput = (_globalThis = globalThis).getComputedStyle) === null || _globalThis$getComput === void 0 ? void 0 : _globalThis$getComput.call(_globalThis, node);
1065
+ return ((rect === null || rect === void 0 ? void 0 : rect.width) ?? 0) > 0 && ((rect === null || rect === void 0 ? void 0 : rect.height) ?? 0) > 0 && (style === null || style === void 0 ? void 0 : style.display) !== "none" && (style === null || style === void 0 ? void 0 : style.visibility) !== "hidden" && Number.parseFloat((style === null || style === void 0 ? void 0 : style.opacity) || "1") > .01;
1066
+ });
1067
+ }
1068
+ countNativeInlineDeleteZoneNodes() {
1069
+ if (!this.lastContainer) return 0;
1070
+ const querySelectorAll = typeof this.lastContainer.querySelectorAll === "function" ? this.lastContainer.querySelectorAll.bind(this.lastContainer) : null;
1071
+ if (!querySelectorAll) return 0;
1072
+ const nodes = Array.from(querySelectorAll(".editor.modified .view-zones [monaco-view-zone], .editor.modified .margin-view-zones [monaco-view-zone]") ?? []);
1073
+ return nodes.filter((node) => {
1074
+ if (!(node instanceof HTMLElement)) return false;
1075
+ return node.matches(".view-lines.line-delete") || !!node.querySelector(".view-lines.line-delete") || node.matches(".inline-deleted-margin-view-zone") || !!node.querySelector(".inline-deleted-margin-view-zone");
1076
+ }).length;
1077
+ }
1078
+ syncFallbackInlineDeletedZones(lineChanges) {
1079
+ var _modifiedEditor$getMo, _EditorOption, _modifiedEditor$getOp, _this$lastContainer3, _this$lastContainer3$, _this$lastContainer4, _this$lastContainer4$;
1080
+ if (typeof document === "undefined" || !this.diffEditorView || !this.originalModel || !this.isDiffInlineMode()) {
1081
+ this.clearFallbackInlineDeletedZones();
1082
+ return;
1083
+ }
1084
+ const modifiedEditor = this.diffEditorView.getModifiedEditor();
1085
+ const modifiedModel = modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getMo = modifiedEditor.getModel) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.call(modifiedEditor);
1086
+ const originalModel = this.originalModel;
1087
+ if (!modifiedEditor || !modifiedModel || !originalModel) {
1088
+ this.fallbackInlineDeletedZoneIds = [];
1089
+ return;
1090
+ }
1091
+ const lineHeightOption = (_EditorOption = monaco_shim_exports.editor.EditorOption) === null || _EditorOption === void 0 ? void 0 : _EditorOption.lineHeight;
1092
+ 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));
1094
+ 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
+ return node instanceof HTMLElement && !!node.querySelector(".view-lines.line-delete");
1096
+ });
1097
+ const nativeMarginWrappers = Array.from(((_this$lastContainer4 = this.lastContainer) === null || _this$lastContainer4 === void 0 || (_this$lastContainer4$ = _this$lastContainer4.querySelectorAll) === null || _this$lastContainer4$ === void 0 ? void 0 : _this$lastContainer4$.call(_this$lastContainer4, ".editor.modified .margin-view-zones [monaco-view-zone]")) ?? []).filter((node) => {
1098
+ return node instanceof HTMLElement && !!node.querySelector(".inline-deleted-margin-view-zone");
1099
+ });
1100
+ const nativePairs = nativeViewWrappers.map((viewWrapper) => {
1101
+ const id = viewWrapper.getAttribute("monaco-view-zone");
1102
+ if (!id) return null;
1103
+ const marginWrapper = nativeMarginWrappers.find((candidate) => candidate.getAttribute("monaco-view-zone") === id);
1104
+ return {
1105
+ id,
1106
+ top: Number.parseFloat(viewWrapper.style.top || "NaN"),
1107
+ viewWrapper,
1108
+ marginWrapper: marginWrapper ?? null
1109
+ };
1110
+ }).filter((entry) => !!entry && Number.isFinite(entry.top)).sort((left, right) => left.top - right.top);
1111
+ if (nativePairs.length >= relevantChanges.length && relevantChanges.length > 0) {
1112
+ const nextSignature$1 = nativePairs.slice(0, relevantChanges.length).map((pair, index) => {
1113
+ const change = relevantChanges[index];
1114
+ const text = Array.from({ length: change.originalEndLineNumber - change.originalStartLineNumber + 1 }, (_, offset) => this.readModelLineContent(originalModel, change.originalStartLineNumber + offset)).join("\n");
1115
+ return `${pair.id}:${text}`;
1116
+ }).join("|");
1117
+ if (nextSignature$1 && this.fallbackInlineDeletedZoneSignature === nextSignature$1 && this.fallbackInlineDeletedZoneIds.length === 0) return;
1118
+ if (this.fallbackInlineDeletedZoneIds.length > 0) {
1119
+ try {
1120
+ var _modifiedEditor$chang2;
1121
+ (_modifiedEditor$chang2 = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang2 === void 0 || _modifiedEditor$chang2.call(modifiedEditor, (accessor) => {
1122
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1123
+ });
1124
+ } catch {}
1125
+ this.fallbackInlineDeletedZoneIds = [];
1126
+ }
1127
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1128
+ relevantChanges.forEach((change, index) => {
1129
+ var _modifiedEditor$apply;
1130
+ const pair = nativePairs[index];
1131
+ const domNode = document.createElement("div");
1132
+ domNode.className = "stream-monaco-fallback-inline-delete-zone";
1133
+ domNode.setAttribute("aria-hidden", "true");
1134
+ domNode.setAttribute("data-stream-monaco-native-wrapper", "true");
1135
+ (_modifiedEditor$apply = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply === void 0 || _modifiedEditor$apply.call(modifiedEditor, domNode);
1136
+ for (let line = change.originalStartLineNumber; line <= change.originalEndLineNumber; line++) {
1137
+ const lineNode = document.createElement("div");
1138
+ lineNode.className = "stream-monaco-fallback-inline-delete-line";
1139
+ lineNode.textContent = this.readModelLineContent(originalModel, line);
1140
+ lineNode.style.height = `${lineHeight}px`;
1141
+ lineNode.style.lineHeight = `${lineHeight}px`;
1142
+ domNode.append(lineNode);
1143
+ }
1144
+ pair.viewWrapper.append(domNode);
1145
+ if (pair.marginWrapper) {
1146
+ var _modifiedEditor$apply2;
1147
+ const marginDomNode = document.createElement("div");
1148
+ marginDomNode.className = "stream-monaco-fallback-inline-delete-margin";
1149
+ marginDomNode.setAttribute("aria-hidden", "true");
1150
+ marginDomNode.setAttribute("data-stream-monaco-native-wrapper", "true");
1151
+ marginDomNode.style.height = "100%";
1152
+ (_modifiedEditor$apply2 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply2 === void 0 || _modifiedEditor$apply2.call(modifiedEditor, marginDomNode);
1153
+ pair.marginWrapper.append(marginDomNode);
1154
+ }
1155
+ });
1156
+ this.fallbackInlineDeletedZoneSignature = nextSignature$1 || null;
1157
+ return;
1158
+ }
1159
+ this.clearFallbackInlineDeletedZoneWrapperContent();
1160
+ const nextZones = relevantChanges.map((change) => {
1161
+ var _modifiedEditor$apply3, _modifiedEditor$apply4;
1162
+ const lineCount = change.originalEndLineNumber - change.originalStartLineNumber + 1;
1163
+ if (lineCount < 1) return null;
1164
+ const domNode = document.createElement("div");
1165
+ domNode.className = "stream-monaco-fallback-inline-delete-zone";
1166
+ domNode.setAttribute("aria-hidden", "true");
1167
+ (_modifiedEditor$apply3 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply3 === void 0 || _modifiedEditor$apply3.call(modifiedEditor, domNode);
1168
+ for (let line = change.originalStartLineNumber; line <= change.originalEndLineNumber; line++) {
1169
+ const lineNode = document.createElement("div");
1170
+ lineNode.className = "stream-monaco-fallback-inline-delete-line";
1171
+ lineNode.textContent = this.readModelLineContent(originalModel, line);
1172
+ lineNode.style.height = `${lineHeight}px`;
1173
+ lineNode.style.lineHeight = `${lineHeight}px`;
1174
+ domNode.append(lineNode);
1175
+ }
1176
+ const marginDomNode = document.createElement("div");
1177
+ marginDomNode.className = "stream-monaco-fallback-inline-delete-margin";
1178
+ marginDomNode.setAttribute("aria-hidden", "true");
1179
+ (_modifiedEditor$apply4 = modifiedEditor.applyFontInfo) === null || _modifiedEditor$apply4 === void 0 || _modifiedEditor$apply4.call(modifiedEditor, marginDomNode);
1180
+ const anchorLine = Math.max(0, Math.min(modifiedModel.getLineCount(), (change.modifiedStartLineNumber || 1) - 1));
1181
+ return {
1182
+ afterLineNumber: anchorLine,
1183
+ heightInLines: lineCount,
1184
+ domNode,
1185
+ marginDomNode
1186
+ };
1187
+ }).filter(Boolean);
1188
+ const nextSignature = nextZones.map((zone) => {
1189
+ var _zone$domNode;
1190
+ const text = typeof ((_zone$domNode = zone.domNode) === null || _zone$domNode === void 0 ? void 0 : _zone$domNode.textContent) === "string" ? zone.domNode.textContent : "";
1191
+ return `${zone.afterLineNumber}:${zone.heightInLines}:${text}`;
1192
+ }).join("|");
1193
+ if (nextSignature && this.fallbackInlineDeletedZoneSignature === nextSignature && this.fallbackInlineDeletedZoneIds.length === nextZones.length) return;
1194
+ try {
1195
+ var _modifiedEditor$chang3;
1196
+ (_modifiedEditor$chang3 = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang3 === void 0 || _modifiedEditor$chang3.call(modifiedEditor, (accessor) => {
1197
+ for (const id of this.fallbackInlineDeletedZoneIds) accessor.removeZone(id);
1198
+ this.fallbackInlineDeletedZoneIds = nextZones.map((zone) => accessor.addZone(zone));
1199
+ });
1200
+ this.fallbackInlineDeletedZoneSignature = nextSignature || null;
1201
+ } catch {
1202
+ this.fallbackInlineDeletedZoneIds = [];
1203
+ this.fallbackInlineDeletedZoneSignature = null;
1204
+ }
1205
+ try {
1206
+ var _modifiedEditor$layou, _render;
1207
+ (_modifiedEditor$layou = modifiedEditor.layout) === null || _modifiedEditor$layou === void 0 || _modifiedEditor$layou.call(modifiedEditor);
1208
+ (_render = modifiedEditor.render) === null || _render === void 0 || _render.call(modifiedEditor, true);
1209
+ } catch {}
938
1210
  }
939
1211
  toWholeLineDecoration(side, startLineNumber, endLineNumber) {
940
1212
  if (endLineNumber < startLineNumber || startLineNumber < 1) return null;
@@ -947,30 +1219,50 @@ var DiffEditorManager = class DiffEditorManager {
947
1219
  marginClassName: removed ? "stream-monaco-fallback-gutter-delete" : "stream-monaco-fallback-gutter-insert",
948
1220
  linesDecorationsClassName: removed ? "stream-monaco-fallback-lines-delete" : "stream-monaco-fallback-lines-insert",
949
1221
  lineNumberClassName: removed ? "stream-monaco-fallback-line-number-delete" : "stream-monaco-fallback-line-number-insert",
950
- description: removed ? "stream-monaco-fallback-line-delete" : "stream-monaco-fallback-line-insert",
951
1222
  zIndex: 5
952
1223
  }
953
1224
  };
954
1225
  }
955
1226
  syncDiffPresentationDecorations() {
1227
+ var _this$diffEditorView$3, _this$lastContainer$q, _this$lastContainer5;
956
1228
  if (!this.diffEditorView || !this.lastContainer) return;
957
1229
  const nativeFresh = this.hasFreshNativeDiffResult();
958
- this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh);
959
- if (nativeFresh) {
1230
+ const useInlineMode = this.isDiffInlineMode();
1231
+ const lineChanges = this.getEffectiveLineChanges();
1232
+ const nativeInlineDeleteZoneCount = useInlineMode ? this.countNativeInlineDeleteZoneNodes() : 0;
1233
+ const hasNativeInlineDeleteZoneNodes = nativeInlineDeleteZoneCount > 0;
1234
+ const hasNativeInlineDeleteNodes = useInlineMode && this.hasVisibleNativeInlineDeleteNodes();
1235
+ const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => this.hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
1236
+ const useInlineStaleFallback = shouldKeepInlineFallback;
1237
+ 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")));
1239
+ this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh && !keepNativeDecorationsWhileStale);
1240
+ if (nativeFresh && !shouldKeepInlineFallback) {
960
1241
  this.clearFallbackDiffDecorations();
961
1242
  return;
962
1243
  }
963
1244
  const originalEditor = this.diffEditorView.getOriginalEditor();
964
1245
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
965
- const lineChanges = this.getEffectiveLineChanges();
966
1246
  const originalDecorations = lineChanges.map((change) => this.toWholeLineDecoration("original", change.originalStartLineNumber, change.originalEndLineNumber)).filter(Boolean);
967
1247
  const modifiedDecorations = lineChanges.map((change) => this.toWholeLineDecoration("modified", change.modifiedStartLineNumber, change.modifiedEndLineNumber)).filter(Boolean);
968
1248
  this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, originalDecorations);
969
1249
  this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, modifiedDecorations);
1250
+ if (useInlineStaleFallback) this.syncFallbackInlineDeletedZones(lineChanges);
1251
+ else this.clearFallbackInlineDeletedZones();
970
1252
  }
971
1253
  disposeDiffPresentationTracking() {
972
1254
  this.clearFallbackDiffDecorations();
973
- if (this.lastContainer) this.lastContainer.classList.remove("stream-monaco-diff-native-stale");
1255
+ if (this.diffPresentationObserver) {
1256
+ this.diffPresentationObserver.disconnect();
1257
+ this.diffPresentationObserver = null;
1258
+ }
1259
+ this.clearInlineDiffStreamingPresentationIdleTimer();
1260
+ this.inlineDiffStreamingPresentationActive = false;
1261
+ this.resetInlineDiffStreamingHeightFloor();
1262
+ if (this.lastContainer) {
1263
+ this.lastContainer.classList.remove("stream-monaco-diff-native-stale");
1264
+ this.lastContainer.classList.remove("stream-monaco-diff-inline-native-ready");
1265
+ }
974
1266
  this.diffComputedVersions = null;
975
1267
  this.diffPresentationDisposables.forEach((disposable) => disposable.dispose());
976
1268
  this.diffPresentationDisposables = [];
@@ -1321,6 +1613,31 @@ var DiffEditorManager = class DiffEditorManager {
1321
1613
  border: 0 !important;
1322
1614
  box-shadow: var(--stream-monaco-removed-line-shadow);
1323
1615
  }
1616
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-zone {
1617
+ box-sizing: border-box;
1618
+ width: 100%;
1619
+ pointer-events: none;
1620
+ }
1621
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-line {
1622
+ box-sizing: border-box;
1623
+ width: 100%;
1624
+ overflow: hidden;
1625
+ white-space: pre;
1626
+ color: inherit;
1627
+ background: var(--stream-monaco-removed-line-fill);
1628
+ box-shadow: var(--stream-monaco-removed-line-shadow);
1629
+ }
1630
+ .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-inline-delete-margin {
1631
+ box-sizing: border-box;
1632
+ width: 100%;
1633
+ background: var(--stream-monaco-removed-gutter);
1634
+ pointer-events: none;
1635
+ }
1636
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-zone,
1637
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-line,
1638
+ .stream-monaco-diff-root.stream-monaco-diff-inline-native-ready .stream-monaco-fallback-inline-delete-margin {
1639
+ display: none !important;
1640
+ }
1324
1641
  .stream-monaco-diff-root .monaco-editor .stream-monaco-fallback-gutter-insert,
1325
1642
  .stream-monaco-diff-root .monaco-diff-editor .stream-monaco-fallback-gutter-insert {
1326
1643
  background: var(--stream-monaco-added-gutter) !important;
@@ -1450,6 +1767,9 @@ var DiffEditorManager = class DiffEditorManager {
1450
1767
  }
1451
1768
  .stream-monaco-diff-root .monaco-diff-editor .editor.original .current-line {
1452
1769
  width: var(--stream-monaco-original-margin-width, auto) !important;
1770
+ display: none !important;
1771
+ opacity: 0 !important;
1772
+ pointer-events: none !important;
1453
1773
  }
1454
1774
  .stream-monaco-diff-root .monaco-diff-editor .editor.original .monaco-scrollable-element.editor-scrollable {
1455
1775
  left: var(--stream-monaco-original-scrollable-left, auto) !important;
@@ -1462,6 +1782,9 @@ var DiffEditorManager = class DiffEditorManager {
1462
1782
  }
1463
1783
  .stream-monaco-diff-root .monaco-diff-editor .editor.modified .current-line {
1464
1784
  width: var(--stream-monaco-modified-margin-width) !important;
1785
+ display: none !important;
1786
+ opacity: 0 !important;
1787
+ pointer-events: none !important;
1465
1788
  }
1466
1789
  .stream-monaco-diff-root .monaco-diff-editor .editor.modified .monaco-scrollable-element.editor-scrollable {
1467
1790
  left: var(--stream-monaco-modified-scrollable-left, var(--stream-monaco-modified-margin-width)) !important;
@@ -1492,15 +1815,39 @@ var DiffEditorManager = class DiffEditorManager {
1492
1815
  border: 0 !important;
1493
1816
  overflow: hidden !important;
1494
1817
  }
1818
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-editor,
1819
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-editor-background,
1820
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .lines-content {
1821
+ width: 0 !important;
1822
+ min-width: 0 !important;
1823
+ background: transparent !important;
1824
+ opacity: 0 !important;
1825
+ pointer-events: none !important;
1826
+ }
1495
1827
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .monaco-scrollable-element.editor-scrollable {
1496
1828
  left: 0 !important;
1497
1829
  width: 0 !important;
1498
1830
  }
1831
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin,
1832
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin-view-overlays,
1833
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .margin-view-zones,
1834
+ .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .overflow-guard {
1835
+ display: none !important;
1836
+ width: 0 !important;
1837
+ min-width: 0 !important;
1838
+ }
1499
1839
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.modified {
1500
1840
  left: 0 !important;
1501
1841
  width: 100% !important;
1502
1842
  border-left: 0 !important;
1503
1843
  }
1844
+ .stream-monaco-diff-root.stream-monaco-diff-inline.stream-monaco-diff-native-stale .monaco-diff-editor .editor.modified .view-lines.line-delete,
1845
+ .stream-monaco-diff-root.stream-monaco-diff-inline.stream-monaco-diff-native-stale .monaco-diff-editor .editor.modified .inline-deleted-margin-view-zone {
1846
+ display: none !important;
1847
+ height: 0 !important;
1848
+ min-height: 0 !important;
1849
+ overflow: hidden !important;
1850
+ }
1504
1851
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .gutter-delete,
1505
1852
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .gutter-insert,
1506
1853
  .stream-monaco-diff-root.stream-monaco-diff-inline .monaco-diff-editor .editor.original .line-delete,
@@ -2090,6 +2437,9 @@ var DiffEditorManager = class DiffEditorManager {
2090
2437
  opacity: 0.92 !important;
2091
2438
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.14s ease, opacity 0.14s ease, box-shadow 0.14s ease;
2092
2439
  }
2440
+ .stream-monaco-diff-root .monaco-editor .fold-unchanged.stream-monaco-fold-unchanged-hidden {
2441
+ display: none !important;
2442
+ }
2093
2443
  .stream-monaco-diff-root .monaco-editor .fold-unchanged:hover,
2094
2444
  .stream-monaco-diff-root .monaco-editor .fold-unchanged.stream-monaco-focus-visible {
2095
2445
  opacity: 1 !important;
@@ -2187,6 +2537,8 @@ var DiffEditorManager = class DiffEditorManager {
2187
2537
  }
2188
2538
  capturePersistedDiffUnchangedState() {
2189
2539
  if (!this.diffEditorView) return;
2540
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved ?? this.resolveDiffHideUnchangedRegionsOption();
2541
+ if (!(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) || this.diffHideUnchangedRegionsDeferred) return;
2190
2542
  const state = this.diffEditorView.saveViewState();
2191
2543
  if (!(state === null || state === void 0 ? void 0 : state.modelState)) {
2192
2544
  this.diffPersistedUnchangedModelState = null;
@@ -2194,6 +2546,14 @@ var DiffEditorManager = class DiffEditorManager {
2194
2546
  }
2195
2547
  this.diffPersistedUnchangedModelState = this.cloneSerializableValue(state.modelState);
2196
2548
  }
2549
+ capturePreviousDiffUnchangedState() {
2550
+ if (!this.diffEditorView) return;
2551
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved ?? this.resolveDiffHideUnchangedRegionsOption();
2552
+ if (!(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) || this.diffHideUnchangedRegionsDeferred) return;
2553
+ const state = this.diffEditorView.saveViewState();
2554
+ if (!(state === null || state === void 0 ? void 0 : state.modelState)) return;
2555
+ this.diffPreviousUnchangedModelState = this.cloneSerializableValue(state.modelState);
2556
+ }
2197
2557
  scheduleCapturePersistedDiffUnchangedState(frames = 1) {
2198
2558
  this.rafScheduler.schedule("capture-diff-unchanged-state", () => {
2199
2559
  let remaining = Math.max(0, frames);
@@ -2219,6 +2579,20 @@ var DiffEditorManager = class DiffEditorManager {
2219
2579
  });
2220
2580
  this.applyPendingDiffScrollRestore();
2221
2581
  }
2582
+ restorePreviousDiffUnchangedState() {
2583
+ if (!this.diffEditorView || !this.diffPreviousUnchangedModelState) return false;
2584
+ const current = this.diffEditorView.saveViewState();
2585
+ if (!current) return false;
2586
+ const previous = this.cloneSerializableValue(this.diffPreviousUnchangedModelState);
2587
+ this.diffEditorView.restoreViewState({
2588
+ original: current.original,
2589
+ modified: current.modified,
2590
+ modelState: previous
2591
+ });
2592
+ this.diffPersistedUnchangedModelState = this.cloneSerializableValue(previous);
2593
+ this.applyPendingDiffScrollRestore();
2594
+ return true;
2595
+ }
2222
2596
  scheduleRestorePersistedDiffUnchangedState() {
2223
2597
  if (this.diffHideUnchangedRegionsDeferred) return;
2224
2598
  if (!this.diffPersistedUnchangedModelState) return;
@@ -2382,7 +2756,7 @@ var DiffEditorManager = class DiffEditorManager {
2382
2756
  readOnly: this.options.readOnly ?? true,
2383
2757
  lineDecorationsWidth: this.options.lineDecorationsWidth,
2384
2758
  lineNumbersMinChars: this.options.lineNumbersMinChars,
2385
- glyphMargin: this.options.glyphMargin,
2759
+ glyphMargin: this.resolveDiffGlyphMarginOption(hideUnchangedRegions),
2386
2760
  fontFamily: this.options.fontFamily,
2387
2761
  fontSize: this.options.fontSize,
2388
2762
  lineHeight: this.options.lineHeight,
@@ -2402,9 +2776,10 @@ var DiffEditorManager = class DiffEditorManager {
2402
2776
  };
2403
2777
  }
2404
2778
  refreshDiffPresentation() {
2405
- var _this$diffHeightManag;
2779
+ var _this$diffHideUnchang, _this$diffHeightManag;
2406
2780
  if (!this.diffEditorView) return;
2407
2781
  const hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption();
2782
+ const shouldRecomputeDiffViewModelForUnchangedRegions = !this.diffHideUnchangedRegionsDeferred && (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) === true && ((_this$diffHideUnchang = this.diffHideUnchangedRegionsResolved) === null || _this$diffHideUnchang === void 0 ? void 0 : _this$diffHideUnchang.enabled) === false && !!this.originalModel && !!this.modifiedModel;
2408
2783
  const presentationOptions = this.resolveDiffPresentationEditorOptions(hideUnchangedRegions);
2409
2784
  this.diffHideUnchangedRegionsResolved = hideUnchangedRegions;
2410
2785
  this.diffUpdateThrottleMs = this.resolveDiffStreamingThrottleMs();
@@ -2414,13 +2789,20 @@ var DiffEditorManager = class DiffEditorManager {
2414
2789
  this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
2415
2790
  }
2416
2791
  this.withLockedDiffScrollPosition(() => {
2417
- var _this$diffEditorView13;
2418
- (_this$diffEditorView13 = this.diffEditorView) === null || _this$diffEditorView13 === void 0 || _this$diffEditorView13.updateOptions(presentationOptions);
2792
+ var _this$diffEditorView14;
2793
+ (_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || _this$diffEditorView14.updateOptions(presentationOptions);
2419
2794
  });
2420
2795
  (_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 || _this$diffHeightManag.update();
2421
2796
  this.applyDiffRootAppearanceClass();
2422
2797
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2423
2798
  this.repositionDiffHunkNodes();
2799
+ if (shouldRecomputeDiffViewModelForUnchangedRegions) this.setDiffModels({
2800
+ original: this.originalModel,
2801
+ modified: this.modifiedModel
2802
+ }, {
2803
+ preserveViewState: true,
2804
+ preserveModelState: false
2805
+ });
2424
2806
  }
2425
2807
  restoreDeferredDiffUnchangedRegions() {
2426
2808
  this.clearDeferredDiffUnchangedRegionsIdleTimer();
@@ -2430,8 +2812,8 @@ var DiffEditorManager = class DiffEditorManager {
2430
2812
  if (!this.diffHideUnchangedRegionsDeferred) return;
2431
2813
  this.diffHideUnchangedRegionsDeferred = false;
2432
2814
  this.withLockedDiffScrollPosition(() => {
2433
- var _this$diffEditorView14;
2434
- (_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || _this$diffEditorView14.updateOptions({ hideUnchangedRegions });
2815
+ var _this$diffEditorView15;
2816
+ (_this$diffEditorView15 = this.diffEditorView) === null || _this$diffEditorView15 === void 0 || _this$diffEditorView15.updateOptions({ hideUnchangedRegions });
2435
2817
  });
2436
2818
  this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
2437
2819
  if (this.shouldAutoScrollDiff) {
@@ -2440,6 +2822,22 @@ var DiffEditorManager = class DiffEditorManager {
2440
2822
  }
2441
2823
  }
2442
2824
  markDiffStreamingActivity() {
2825
+ var _this$lastContainer6;
2826
+ (_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.classList.remove("stream-monaco-diff-inline-native-ready");
2827
+ if (this.isDiffInlineMode()) {
2828
+ var _this$diffHeightManag2, _this$lastContainer7, _this$lastContainer7$;
2829
+ this.inlineDiffStreamingPresentationActive = true;
2830
+ this.inlineDiffStreamingHeightFloor = Math.max(this.inlineDiffStreamingHeightFloor, ((_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 ? void 0 : _this$diffHeightManag2.getLastApplied()) ?? 0, ((_this$lastContainer7 = this.lastContainer) === null || _this$lastContainer7 === void 0 || (_this$lastContainer7$ = _this$lastContainer7.getBoundingClientRect) === null || _this$lastContainer7$ === void 0 ? void 0 : _this$lastContainer7$.call(_this$lastContainer7).height) ?? 0);
2831
+ this.clearInlineDiffStreamingPresentationIdleTimer();
2832
+ this.inlineDiffStreamingPresentationIdleTimer = setTimeout(() => {
2833
+ var _this$diffHeightManag3;
2834
+ this.inlineDiffStreamingPresentationIdleTimer = null;
2835
+ this.inlineDiffStreamingPresentationActive = false;
2836
+ this.resetInlineDiffStreamingHeightFloor();
2837
+ this.scheduleSyncDiffPresentationDecorations();
2838
+ (_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 || _this$diffHeightManag3.update();
2839
+ }, 3e3);
2840
+ }
2443
2841
  const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved;
2444
2842
  if (!this.diffEditorView || !(hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled)) return;
2445
2843
  this.clearDeferredDiffUnchangedRegionsIdleTimer();
@@ -2451,8 +2849,8 @@ var DiffEditorManager = class DiffEditorManager {
2451
2849
  this.diffHideUnchangedRegionsDeferred = true;
2452
2850
  this.hideAllDiffUnchangedBridgeEntries();
2453
2851
  this.withLockedDiffScrollPosition(() => {
2454
- var _this$diffEditorView15;
2455
- (_this$diffEditorView15 = this.diffEditorView) === null || _this$diffEditorView15 === void 0 || _this$diffEditorView15.updateOptions({ hideUnchangedRegions: {
2852
+ var _this$diffEditorView16;
2853
+ (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.updateOptions({ hideUnchangedRegions: {
2456
2854
  ...hideUnchangedRegions,
2457
2855
  enabled: false
2458
2856
  } });
@@ -2550,8 +2948,8 @@ var DiffEditorManager = class DiffEditorManager {
2550
2948
  return this.diffUnchangedBridgeOverlay;
2551
2949
  }
2552
2950
  readDiffUnchangedOverlayScrollState() {
2553
- var _this$diffEditorView16, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
2554
- const modifiedEditor = (_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 ? void 0 : _this$diffEditorView16.getModifiedEditor();
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();
2555
2953
  return {
2556
2954
  top: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc6 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc6 === void 0 ? void 0 : _modifiedEditor$getSc6.call(modifiedEditor)) ?? 0,
2557
2955
  left: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc7 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc7 === void 0 ? void 0 : _modifiedEditor$getSc7.call(modifiedEditor)) ?? 0
@@ -2908,7 +3306,7 @@ var DiffEditorManager = class DiffEditorManager {
2908
3306
  this.scheduleCapturePersistedDiffUnchangedState(1);
2909
3307
  }
2910
3308
  resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount) {
2911
- var _this$diffEditorView17, _this$diffEditorView18;
3309
+ var _this$diffEditorView18, _this$diffEditorView19;
2912
3310
  let showTopHandle = pairCount === 1 || pairIndex > 0;
2913
3311
  let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
2914
3312
  const countMatch = countText.match(/\d+/);
@@ -2938,7 +3336,7 @@ var DiffEditorManager = class DiffEditorManager {
2938
3336
  showTopHandle = false;
2939
3337
  showBottomHandle = true;
2940
3338
  }
2941
- const modelLineCount = ((_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView17 = _this$diffEditorView17.getModifiedEditor().getModel()) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView18 = _this$diffEditorView17.getLineCount) === null || _this$diffEditorView18 === void 0 ? void 0 : _this$diffEditorView18.call(_this$diffEditorView17)) ?? null;
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;
2942
3340
  if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
2943
3341
  showTopHandle = true;
2944
3342
  showBottomHandle = false;
@@ -2949,13 +3347,13 @@ var DiffEditorManager = class DiffEditorManager {
2949
3347
  };
2950
3348
  }
2951
3349
  resolveDiffUnchangedMergeRole(node) {
2952
- var _this$diffEditorView19, _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24;
3350
+ var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24, _this$diffEditorView25;
2953
3351
  const diffRoot = node.closest(".monaco-diff-editor.side-by-side");
2954
3352
  if (!(diffRoot instanceof HTMLElement)) return "none";
2955
3353
  const nodeRect = node.getBoundingClientRect();
2956
3354
  const nodeCenter = nodeRect.left + nodeRect.width / 2;
2957
- const originalHost = (_this$diffEditorView19 = this.diffEditorView) === null || _this$diffEditorView19 === void 0 || (_this$diffEditorView21 = (_this$diffEditorView20 = _this$diffEditorView19.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView21 === void 0 ? void 0 : _this$diffEditorView21.call(_this$diffEditorView20);
2958
- const modifiedHost = (_this$diffEditorView22 = this.diffEditorView) === null || _this$diffEditorView22 === void 0 || (_this$diffEditorView24 = (_this$diffEditorView23 = _this$diffEditorView22.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView24 === void 0 ? void 0 : _this$diffEditorView24.call(_this$diffEditorView23);
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);
2959
3357
  if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
2960
3358
  const originalRect = originalHost.getBoundingClientRect();
2961
3359
  const modifiedRect = modifiedHost.getBoundingClientRect();
@@ -2995,6 +3393,11 @@ var DiffEditorManager = class DiffEditorManager {
2995
3393
  action.tabIndex = shouldUseMergedSecondary ? -1 : 0;
2996
3394
  if (action.dataset.streamMonacoExpandPatched !== "true") {
2997
3395
  action.dataset.streamMonacoExpandPatched = "true";
3396
+ const handleCaptureExpand = () => {
3397
+ this.capturePreviousDiffUnchangedState();
3398
+ };
3399
+ action.addEventListener("click", handleCaptureExpand, { capture: true });
3400
+ this.diffUnchangedRegionDisposables.push({ dispose: () => action.removeEventListener("click", handleCaptureExpand, true) });
2998
3401
  this.createDomDisposable(this.diffUnchangedRegionDisposables, action, "click", () => {
2999
3402
  this.hideAllDiffUnchangedBridgeEntries();
3000
3403
  this.scheduleCapturePersistedDiffUnchangedState(1);
@@ -3007,7 +3410,10 @@ var DiffEditorManager = class DiffEditorManager {
3007
3410
  this.bindFocusWithinClass(this.diffUnchangedRegionDisposables, node, "stream-monaco-focus-within");
3008
3411
  const activate = () => {
3009
3412
  const action$1 = node.querySelector("a");
3010
- if (action$1 instanceof HTMLElement) action$1.click();
3413
+ if (action$1 instanceof HTMLElement) {
3414
+ this.capturePreviousDiffUnchangedState();
3415
+ action$1.click();
3416
+ }
3011
3417
  };
3012
3418
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "click", (event) => {
3013
3419
  const mouseEvent = event;
@@ -3101,6 +3507,7 @@ var DiffEditorManager = class DiffEditorManager {
3101
3507
  entry.activate = () => {
3102
3508
  const action = primaryNode.querySelector("a, button") ?? secondaryNode.querySelector("a, button");
3103
3509
  if (action instanceof HTMLElement) {
3510
+ this.capturePreviousDiffUnchangedState();
3104
3511
  action.click();
3105
3512
  this.scheduleCapturePersistedDiffUnchangedState(1);
3106
3513
  }
@@ -3119,10 +3526,22 @@ var DiffEditorManager = class DiffEditorManager {
3119
3526
  node.title = node.title || "Collapse unchanged lines";
3120
3527
  this.bindFocusVisibleClass(this.diffUnchangedRegionDisposables, node);
3121
3528
  this.bindPersistOnMouseRelease(this.diffUnchangedRegionDisposables, node);
3529
+ this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "mouseup", (event) => {
3530
+ const mouseEvent = event;
3531
+ if (mouseEvent.button !== 0) return;
3532
+ if (!this.restorePreviousDiffUnchangedState()) return;
3533
+ event.preventDefault();
3534
+ event.stopPropagation();
3535
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3536
+ });
3122
3537
  this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "keydown", (event) => {
3123
3538
  const keyboardEvent = event;
3124
3539
  if (keyboardEvent.key !== "Enter" && keyboardEvent.key !== " ") return;
3125
3540
  keyboardEvent.preventDefault();
3541
+ if (this.restorePreviousDiffUnchangedState()) {
3542
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3543
+ return;
3544
+ }
3126
3545
  this.dispatchSyntheticMouseDown(node);
3127
3546
  this.scheduleCapturePersistedDiffUnchangedState(1);
3128
3547
  });
@@ -3132,6 +3551,11 @@ var DiffEditorManager = class DiffEditorManager {
3132
3551
  this.applyDiffRootAppearanceClass();
3133
3552
  const viewZoneHeightsChanged = this.syncDiffUnchangedViewZoneHeights();
3134
3553
  const centers = this.lastContainer.querySelectorAll(".diff-hidden-lines .center");
3554
+ const modifiedHiddenSummaryMidpoints = Array.from(this.lastContainer.querySelectorAll(".editor.modified .diff-hidden-lines .center")).map((node) => {
3555
+ const rect = node.getBoundingClientRect();
3556
+ if (rect.width <= 0 || rect.height <= 0) return null;
3557
+ return rect.top + rect.height / 2;
3558
+ }).filter((value) => value !== null);
3135
3559
  Array.from(centers).sort((a, b) => a.getBoundingClientRect().top - b.getBoundingClientRect().top).forEach((node, index) => this.patchDiffUnchangedCenter(node, index));
3136
3560
  const partialRevealHandles = this.lastContainer.querySelectorAll(".diff-hidden-lines .top, .diff-hidden-lines .bottom");
3137
3561
  partialRevealHandles.forEach((node) => {
@@ -3156,7 +3580,13 @@ var DiffEditorManager = class DiffEditorManager {
3156
3580
  this.pruneDiffUnchangedBridgeEntries(visibleKeys);
3157
3581
  this.syncDiffUnchangedOverlayScrollBaseline();
3158
3582
  const foldGlyphs = this.lastContainer.querySelectorAll(".fold-unchanged");
3159
- foldGlyphs.forEach((node) => this.patchDiffUnchangedFoldGlyph(node));
3583
+ foldGlyphs.forEach((node) => {
3584
+ const rect = node.getBoundingClientRect();
3585
+ const midpoint = rect.top + rect.height / 2;
3586
+ const overlapsHiddenSummary = modifiedHiddenSummaryMidpoints.some((summaryMidpoint) => Math.abs(summaryMidpoint - midpoint) <= 8);
3587
+ node.classList.toggle("stream-monaco-fold-unchanged-hidden", overlapsHiddenSummary);
3588
+ this.patchDiffUnchangedFoldGlyph(node);
3589
+ });
3160
3590
  if (viewZoneHeightsChanged) this.schedulePatchDiffUnchangedRegions();
3161
3591
  }
3162
3592
  schedulePatchDiffUnchangedRegions() {
@@ -3169,12 +3599,12 @@ var DiffEditorManager = class DiffEditorManager {
3169
3599
  this.schedulePatchDiffUnchangedRegions();
3170
3600
  }
3171
3601
  setupDiffUnchangedRegionEnhancements() {
3172
- var _globalThis$getComput, _globalThis;
3602
+ var _globalThis$getComput2, _globalThis2;
3173
3603
  this.disposeDiffUnchangedRegionEnhancements();
3174
3604
  if (!this.diffEditorView || !this.lastContainer) return;
3175
3605
  if (typeof document === "undefined") return;
3176
3606
  this.ensureDiffUiStyle();
3177
- const containerStyle = (_globalThis$getComput = (_globalThis = globalThis).getComputedStyle) === null || _globalThis$getComput === void 0 ? void 0 : _globalThis$getComput.call(_globalThis, this.lastContainer);
3607
+ const containerStyle = (_globalThis$getComput2 = (_globalThis2 = globalThis).getComputedStyle) === null || _globalThis$getComput2 === void 0 ? void 0 : _globalThis$getComput2.call(_globalThis2, this.lastContainer);
3178
3608
  if (!containerStyle || containerStyle.position === "static") this.lastContainer.style.position = "relative";
3179
3609
  this.applyDiffRootAppearanceClass();
3180
3610
  this.schedulePatchDiffUnchangedRegions();
@@ -3202,6 +3632,20 @@ var DiffEditorManager = class DiffEditorManager {
3202
3632
  this.applyDiffRootAppearanceClass();
3203
3633
  this.schedulePatchDiffUnchangedRegions();
3204
3634
  };
3635
+ const handleFoldMouseUp = (event) => {
3636
+ var _event$event, _event$target, _event$event2, _event$event2$prevent, _event$event3, _event$event3$stopPro;
3637
+ if (event === null || event === void 0 || (_event$event = event.event) === null || _event$event === void 0 ? void 0 : _event$event.rightButton) return;
3638
+ const targetElement = event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.element;
3639
+ const className = typeof (targetElement === null || targetElement === void 0 ? void 0 : targetElement.className) === "string" ? targetElement.className : "";
3640
+ if (!className.includes("fold-unchanged")) return;
3641
+ if (!this.diffPreviousUnchangedModelState) return;
3642
+ event === null || event === void 0 || (_event$event2 = event.event) === null || _event$event2 === void 0 || (_event$event2$prevent = _event$event2.preventDefault) === null || _event$event2$prevent === void 0 || _event$event2$prevent.call(_event$event2);
3643
+ event === null || event === void 0 || (_event$event3 = event.event) === null || _event$event3 === void 0 || (_event$event3$stopPro = _event$event3.stopPropagation) === null || _event$event3$stopPro === void 0 || _event$event3$stopPro.call(_event$event3);
3644
+ requestAnimationFrame(() => {
3645
+ if (!this.restorePreviousDiffUnchangedState()) return;
3646
+ this.schedulePatchDiffUnchangedRegionsAfterInteraction();
3647
+ });
3648
+ };
3205
3649
  this.diffUnchangedRegionDisposables.push(this.diffEditorView.onDidUpdateDiff(() => {
3206
3650
  repatch();
3207
3651
  this.scheduleRestorePersistedDiffUnchangedState();
@@ -3210,16 +3654,18 @@ var DiffEditorManager = class DiffEditorManager {
3210
3654
  this.diffUnchangedRegionDisposables.push(modifiedEditor.onDidLayoutChange(repatch));
3211
3655
  this.diffUnchangedRegionDisposables.push(originalEditor.onDidScrollChange(() => this.schedulePatchDiffUnchangedRegionsAfterScroll()));
3212
3656
  this.diffUnchangedRegionDisposables.push(modifiedEditor.onDidScrollChange(() => this.schedulePatchDiffUnchangedRegionsAfterScroll()));
3657
+ this.diffUnchangedRegionDisposables.push(originalEditor.onMouseUp(handleFoldMouseUp));
3658
+ this.diffUnchangedRegionDisposables.push(modifiedEditor.onMouseUp(handleFoldMouseUp));
3213
3659
  this.createDomDisposable(this.diffUnchangedRegionDisposables, this.lastContainer, "scroll", () => this.schedulePatchDiffUnchangedRegionsAfterScroll());
3214
3660
  }
3215
3661
  setupDiffHunkInteractions() {
3216
- var _globalThis$getComput2, _globalThis2;
3662
+ var _globalThis$getComput3, _globalThis3;
3217
3663
  this.disposeDiffHunkInteractions();
3218
3664
  if (!this.diffEditorView || !this.lastContainer) return;
3219
3665
  if (this.options.diffHunkActionsOnHover !== true) return;
3220
3666
  if (typeof document === "undefined") return;
3221
3667
  this.ensureDiffUiStyle();
3222
- const containerStyle = (_globalThis$getComput2 = (_globalThis2 = globalThis).getComputedStyle) === null || _globalThis$getComput2 === void 0 ? void 0 : _globalThis$getComput2.call(_globalThis2, this.lastContainer);
3668
+ const containerStyle = (_globalThis$getComput3 = (_globalThis3 = globalThis).getComputedStyle) === null || _globalThis$getComput3 === void 0 ? void 0 : _globalThis$getComput3.call(_globalThis3, this.lastContainer);
3223
3669
  if (!containerStyle || containerStyle.position === "static") this.lastContainer.style.position = "relative";
3224
3670
  const overlay = document.createElement("div");
3225
3671
  overlay.className = "stream-monaco-diff-hunk-overlay";
@@ -3331,15 +3777,15 @@ var DiffEditorManager = class DiffEditorManager {
3331
3777
  this.repositionDiffHunkNodes();
3332
3778
  }
3333
3779
  isOriginalEditorCollapsed() {
3334
- var _this$diffEditorView$3, _this$diffEditorView$4;
3780
+ var _this$diffEditorView$4, _this$diffEditorView$5;
3335
3781
  if (!this.diffEditorView) return true;
3336
- const info = (_this$diffEditorView$3 = (_this$diffEditorView$4 = this.diffEditorView.getOriginalEditor()).getLayoutInfo) === null || _this$diffEditorView$3 === void 0 ? void 0 : _this$diffEditorView$3.call(_this$diffEditorView$4);
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);
3337
3783
  return !info || info.width < 24;
3338
3784
  }
3339
3785
  isDiffInlineMode() {
3340
- var _this$lastContainer;
3341
- const diffRoot = (_this$lastContainer = this.lastContainer) === null || _this$lastContainer === void 0 ? void 0 : _this$lastContainer.querySelector(".monaco-diff-editor");
3342
- if (diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
3786
+ var _this$lastContainer8, _this$lastContainer9;
3787
+ const diffRoot = typeof ((_this$lastContainer8 = this.lastContainer) === null || _this$lastContainer8 === void 0 ? void 0 : _this$lastContainer8.querySelector) === "function" ? (_this$lastContainer9 = this.lastContainer) === null || _this$lastContainer9 === void 0 ? void 0 : _this$lastContainer9.querySelector(".monaco-diff-editor") : null;
3788
+ if (typeof HTMLElement !== "undefined" && diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
3343
3789
  return this.isOriginalEditorCollapsed();
3344
3790
  }
3345
3791
  getEditorBySide(side) {
@@ -3387,8 +3833,8 @@ var DiffEditorManager = class DiffEditorManager {
3387
3833
  if (!this.diffEditorView || !viewState) return;
3388
3834
  const restore = () => {
3389
3835
  try {
3390
- var _this$diffEditorView25;
3391
- (_this$diffEditorView25 = this.diffEditorView) === null || _this$diffEditorView25 === void 0 || _this$diffEditorView25.restoreViewState(viewState);
3836
+ var _this$diffEditorView26;
3837
+ (_this$diffEditorView26 = this.diffEditorView) === null || _this$diffEditorView26 === void 0 || _this$diffEditorView26.restoreViewState(viewState);
3392
3838
  } catch {}
3393
3839
  };
3394
3840
  restore();
@@ -3406,7 +3852,7 @@ var DiffEditorManager = class DiffEditorManager {
3406
3852
  this.pendingPreparedDiffViewModel = null;
3407
3853
  }
3408
3854
  syncDiffKnownValues() {
3409
- var _this$diffEditorView26, _this$diffEditorView27, _this$diffEditorView28, _this$diffHeightManag2;
3855
+ var _this$diffEditorView27, _this$diffEditorView28, _this$diffEditorView29, _this$diffHeightManag4;
3410
3856
  if (this.originalModel) this.lastKnownOriginalCode = this.originalModel.getValue();
3411
3857
  if (this.modifiedModel) {
3412
3858
  this.lastKnownModifiedCode = this.modifiedModel.getValue();
@@ -3415,8 +3861,8 @@ var DiffEditorManager = class DiffEditorManager {
3415
3861
  this.lastKnownModifiedDirty = false;
3416
3862
  this._hasScrollBar = false;
3417
3863
  this.cachedComputedHeightDiff = this.computedHeight();
3418
- this.cachedScrollHeightDiff = ((_this$diffEditorView26 = this.diffEditorView) === null || _this$diffEditorView26 === void 0 || (_this$diffEditorView28 = (_this$diffEditorView27 = _this$diffEditorView26.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView28 === void 0 ? void 0 : _this$diffEditorView28.call(_this$diffEditorView27)) ?? this.cachedScrollHeightDiff;
3419
- (_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
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;
3865
+ (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3420
3866
  }
3421
3867
  applyDefaultDiffHunkAction(context) {
3422
3868
  const { action, side, lineChange } = context;
@@ -3597,26 +4043,52 @@ var DiffEditorManager = class DiffEditorManager {
3597
4043
  const text = this.appendBufferOriginalDiff.join("");
3598
4044
  this.appendBufferOriginalDiff.length = 0;
3599
4045
  if (!text) return;
4046
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
3600
4047
  this.appendToModel(this.originalModel, text);
3601
4048
  }
3602
- computedHeight() {
3603
- var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc5, _modifiedEditor$getSc10;
4049
+ computeRawHeight() {
4050
+ var _originalEditor$getMo, _modifiedEditor$getMo2, _originalEditor$getSc5, _modifiedEditor$getSc10;
3604
4051
  if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
3605
4052
  const modifiedEditor = this.diffEditorView.getModifiedEditor();
3606
4053
  const originalEditor = this.diffEditorView.getOriginalEditor();
3607
4054
  const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
3608
4055
  const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
3609
- const mCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
4056
+ const mCount = ((_modifiedEditor$getMo2 = modifiedEditor.getModel()) === null || _modifiedEditor$getMo2 === void 0 ? void 0 : _modifiedEditor$getMo2.getLineCount()) ?? 1;
3610
4057
  const lineCount = Math.max(oCount, mCount);
3611
4058
  const fromLines = lineCount * lineHeight + padding;
3612
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);
3613
4060
  const desired = Math.max(fromLines, scrollH);
3614
4061
  return Math.min(desired, this.maxHeightValue);
3615
4062
  }
4063
+ 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;
4070
+ }
4071
+ eagerlyGrowDiffContainerHeight() {
4072
+ var _this$lastContainer$g, _this$lastContainer10;
4073
+ if (!this.lastContainer) return;
4074
+ const next = this.computedHeight();
4075
+ if (!Number.isFinite(next) || next <= 0) return;
4076
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4077
+ const measured = ((_this$lastContainer$g = (_this$lastContainer10 = this.lastContainer).getBoundingClientRect) === null || _this$lastContainer$g === void 0 ? void 0 : _this$lastContainer$g.call(_this$lastContainer10).height) ?? this.lastContainer.clientHeight ?? 0;
4078
+ const baseline = Math.max(applied, measured);
4079
+ if (next <= baseline + 1) return;
4080
+ this.lastContainer.style.height = `${next}px`;
4081
+ this.cachedComputedHeightDiff = next;
4082
+ this.scheduleSyncDiffEditorLayoutToContainer();
4083
+ }
3616
4084
  isOverflowAutoDiff() {
3617
4085
  if (!this.lastContainer) return false;
3618
4086
  return this.computedHeight() >= this.maxHeightValue - 1;
3619
4087
  }
4088
+ shouldAvoidOptimisticMaxHeightWriteDiff() {
4089
+ const hideUnchangedRegions = this.diffHideUnchangedRegionsResolved;
4090
+ return this.isDiffInlineMode() && (hideUnchangedRegions === null || hideUnchangedRegions === void 0 ? void 0 : hideUnchangedRegions.enabled) === true && !this.diffHideUnchangedRegionsDeferred;
4091
+ }
3620
4092
  shouldPerformImmediateRevealDiff() {
3621
4093
  return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
3622
4094
  }
@@ -3761,9 +4233,8 @@ var DiffEditorManager = class DiffEditorManager {
3761
4233
  lastRevealLineDiff: this.lastRevealLineDiff
3762
4234
  });
3763
4235
  try {
3764
- var _this$diffEditorView29, _this$diffEditorView30, _this$diffEditorView31;
3765
- this.shouldAutoScrollDiff = true;
3766
- this.lastScrollTopDiff = ((_this$diffEditorView29 = this.diffEditorView) === null || _this$diffEditorView29 === void 0 || (_this$diffEditorView31 = (_this$diffEditorView30 = _this$diffEditorView29.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView31 === void 0 ? void 0 : _this$diffEditorView31.call(_this$diffEditorView30)) ?? this.lastScrollTopDiff;
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;
3767
4238
  } catch {}
3768
4239
  });
3769
4240
  }
@@ -3781,11 +4252,6 @@ var DiffEditorManager = class DiffEditorManager {
3781
4252
  line,
3782
4253
  ticket
3783
4254
  });
3784
- try {
3785
- var _this$diffEditorView32, _this$diffEditorView33, _this$diffEditorView34;
3786
- this.shouldAutoScrollDiff = true;
3787
- this.lastScrollTopDiff = ((_this$diffEditorView32 = this.diffEditorView) === null || _this$diffEditorView32 === void 0 || (_this$diffEditorView34 = (_this$diffEditorView33 = _this$diffEditorView32.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView34 === void 0 ? void 0 : _this$diffEditorView34.call(_this$diffEditorView33)) ?? this.lastScrollTopDiff;
3788
- } catch {}
3789
4255
  }
3790
4256
  scheduleImmediateRevealAfterLayoutDiff(line) {
3791
4257
  const ticket = ++this.revealTicketDiff;
@@ -3794,6 +4260,7 @@ var DiffEditorManager = class DiffEditorManager {
3794
4260
  if (target !== -1 && this.diffHeightManager) {
3795
4261
  if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
3796
4262
  await this.waitForHeightAppliedDiff(target);
4263
+ this.syncDiffEditorLayoutToContainer();
3797
4264
  }
3798
4265
  this.performImmediateRevealDiff(line, ticket);
3799
4266
  });
@@ -3817,11 +4284,19 @@ var DiffEditorManager = class DiffEditorManager {
3817
4284
  });
3818
4285
  }
3819
4286
  async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
3820
- var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
4287
+ var _me$getScrollHeight2, _me$getOption, _oEditor$onDidLayoutC, _mEditor$onDidLayoutC, _oEditor$onDidContent, _mEditor$onDidContent;
3821
4288
  this.cleanup();
3822
4289
  this.lastContainer = container;
3823
4290
  container.style.overflow = "hidden";
3824
4291
  container.style.maxHeight = this.maxHeightCSS;
4292
+ container.innerHTML = "";
4293
+ const editorMount = typeof document !== "undefined" ? document.createElement("div") : container;
4294
+ if (editorMount !== container) {
4295
+ editorMount.style.width = "100%";
4296
+ editorMount.style.height = "100%";
4297
+ editorMount.style.overflow = "hidden";
4298
+ container.append(editorMount);
4299
+ }
3825
4300
  const lang = processedLanguage(language) || language;
3826
4301
  this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
3827
4302
  this.modifiedModel = monaco_shim_exports.editor.createModel(modifiedCode, lang);
@@ -3830,7 +4305,7 @@ var DiffEditorManager = class DiffEditorManager {
3830
4305
  const hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption();
3831
4306
  this.diffHideUnchangedRegionsResolved = hideUnchangedRegions;
3832
4307
  this.diffHideUnchangedRegionsDeferred = false;
3833
- this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(container, {
4308
+ this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(editorMount, {
3834
4309
  automaticLayout: true,
3835
4310
  scrollBeyondLastLine: false,
3836
4311
  renderSideBySide: true,
@@ -3844,6 +4319,7 @@ var DiffEditorManager = class DiffEditorManager {
3844
4319
  ...this.options.scrollbar || {}
3845
4320
  },
3846
4321
  ...this.options,
4322
+ glyphMargin: this.resolveDiffGlyphMarginOption(hideUnchangedRegions),
3847
4323
  hideUnchangedRegions
3848
4324
  });
3849
4325
  monaco_shim_exports.editor.setTheme(currentTheme);
@@ -3880,8 +4356,10 @@ var DiffEditorManager = class DiffEditorManager {
3880
4356
  autoScrollInitial: this.autoScrollInitial,
3881
4357
  diffAutoScroll: this.diffAutoScroll
3882
4358
  });
3883
- const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
3884
- container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
4359
+ const minVisibleHeight = this.shouldDeferTailAppendForInlineStreaming() ? 0 : Math.min(120, this.maxHeightValue);
4360
+ if (minVisibleHeight > 0) container.style.minHeight = `${minVisibleHeight}px`;
4361
+ else if (typeof container.style.removeProperty === "function") container.style.removeProperty("min-height");
4362
+ else delete container.style.minHeight;
3885
4363
  if (this.diffHeightManager) {
3886
4364
  this.diffHeightManager.dispose();
3887
4365
  this.diffHeightManager = null;
@@ -3900,6 +4378,7 @@ var DiffEditorManager = class DiffEditorManager {
3900
4378
  this.diffComputedVersions = null;
3901
4379
  this.diffPresentationDisposables.push(this.diffEditorView.onDidUpdateDiff(() => {
3902
4380
  this.diffComputedVersions = this.captureCurrentDiffVersions();
4381
+ this.syncDiffEditorLayoutToContainer();
3903
4382
  this.scheduleSyncDiffPresentationDecorations();
3904
4383
  }));
3905
4384
  this.diffPresentationDisposables.push(oEditor.onDidChangeModelContent(() => {
@@ -3908,16 +4387,46 @@ var DiffEditorManager = class DiffEditorManager {
3908
4387
  this.diffPresentationDisposables.push(mEditor.onDidChangeModelContent(() => {
3909
4388
  this.scheduleSyncDiffPresentationDecorations();
3910
4389
  }));
4390
+ const originalLayoutDisposable = (_oEditor$onDidLayoutC = oEditor.onDidLayoutChange) === null || _oEditor$onDidLayoutC === void 0 ? void 0 : _oEditor$onDidLayoutC.call(oEditor, () => {
4391
+ this.scheduleSyncDiffPresentationDecorations();
4392
+ });
4393
+ if (originalLayoutDisposable) this.diffPresentationDisposables.push(originalLayoutDisposable);
4394
+ const modifiedLayoutDisposable = (_mEditor$onDidLayoutC = mEditor.onDidLayoutChange) === null || _mEditor$onDidLayoutC === void 0 ? void 0 : _mEditor$onDidLayoutC.call(mEditor, () => {
4395
+ this.scheduleSyncDiffPresentationDecorations();
4396
+ });
4397
+ if (modifiedLayoutDisposable) this.diffPresentationDisposables.push(modifiedLayoutDisposable);
4398
+ if (typeof MutationObserver !== "undefined" && this.lastContainer) {
4399
+ this.diffPresentationObserver = new MutationObserver((mutations) => {
4400
+ const shouldSync = mutations.some((mutation) => {
4401
+ if (mutation.type !== "childList") return false;
4402
+ const nodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes));
4403
+ return nodes.some((node) => {
4404
+ if (!(node instanceof HTMLElement)) return false;
4405
+ return node.matches(".line-delete, .inline-deleted-text, .inline-deleted-margin-view-zone") || !!node.querySelector(".line-delete, .inline-deleted-text, .inline-deleted-margin-view-zone") || !!node.closest(".editor.modified .view-zones, .editor.modified .margin-view-zones");
4406
+ });
4407
+ });
4408
+ if (shouldSync) this.scheduleSyncDiffPresentationDecorations();
4409
+ });
4410
+ this.diffPresentationObserver.observe(this.lastContainer, {
4411
+ childList: true,
4412
+ subtree: true
4413
+ });
4414
+ }
3911
4415
  (_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
3912
4416
  this._hasScrollBar = false;
3913
4417
  this.rafScheduler.schedule("content-size-change-diff", () => {
3914
- var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
4418
+ var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag5, _this$diffHeightManag6;
3915
4419
  this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
3916
4420
  this.cachedLineHeightDiff = ((_oEditor$getOption = oEditor.getOption) === null || _oEditor$getOption === void 0 ? void 0 : _oEditor$getOption.call(oEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
3917
4421
  this.cachedComputedHeightDiff = this.computedHeight();
3918
- if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
3919
- (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
3920
- const computed$2 = this.computedHeight();
4422
+ if (this.lastContainer) {
4423
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4424
+ if (this.cachedComputedHeightDiff > applied + 1 && (this.cachedComputedHeightDiff < this.maxHeightValue - 1 || !this.shouldAvoidOptimisticMaxHeightWriteDiff())) this.lastContainer.style.height = `${this.cachedComputedHeightDiff}px`;
4425
+ }
4426
+ if ((_this$diffHeightManag5 = this.diffHeightManager) === null || _this$diffHeightManag5 === void 0 ? void 0 : _this$diffHeightManag5.isSuppressed()) return;
4427
+ (_this$diffHeightManag6 = this.diffHeightManager) === null || _this$diffHeightManag6 === void 0 || _this$diffHeightManag6.update();
4428
+ this.scheduleSyncDiffEditorLayoutToContainer();
4429
+ const computed$2 = this.cachedComputedHeightDiff;
3921
4430
  if (this.lastContainer) {
3922
4431
  this.lastContainer.style.overflow = "hidden";
3923
4432
  if (computed$2 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
@@ -3930,13 +4439,18 @@ var DiffEditorManager = class DiffEditorManager {
3930
4439
  (_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
3931
4440
  this._hasScrollBar = false;
3932
4441
  this.rafScheduler.schedule("content-size-change-diff", () => {
3933
- var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag5, _this$diffHeightManag6;
4442
+ var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag7, _this$diffHeightManag8;
3934
4443
  this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
3935
4444
  this.cachedLineHeightDiff = ((_mEditor$getOption = mEditor.getOption) === null || _mEditor$getOption === void 0 ? void 0 : _mEditor$getOption.call(mEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
3936
4445
  this.cachedComputedHeightDiff = this.computedHeight();
3937
- if ((_this$diffHeightManag5 = this.diffHeightManager) === null || _this$diffHeightManag5 === void 0 ? void 0 : _this$diffHeightManag5.isSuppressed()) return;
3938
- (_this$diffHeightManag6 = this.diffHeightManager) === null || _this$diffHeightManag6 === void 0 || _this$diffHeightManag6.update();
3939
- const computed$2 = this.computedHeight();
4446
+ if (this.lastContainer) {
4447
+ const applied = Number.parseFloat(this.lastContainer.style.height || "0") || 0;
4448
+ if (this.cachedComputedHeightDiff > applied + 1 && (this.cachedComputedHeightDiff < this.maxHeightValue - 1 || !this.shouldAvoidOptimisticMaxHeightWriteDiff())) this.lastContainer.style.height = `${this.cachedComputedHeightDiff}px`;
4449
+ }
4450
+ if ((_this$diffHeightManag7 = this.diffHeightManager) === null || _this$diffHeightManag7 === void 0 ? void 0 : _this$diffHeightManag7.isSuppressed()) return;
4451
+ (_this$diffHeightManag8 = this.diffHeightManager) === null || _this$diffHeightManag8 === void 0 || _this$diffHeightManag8.update();
4452
+ this.scheduleSyncDiffEditorLayoutToContainer();
4453
+ const computed$2 = this.cachedComputedHeightDiff;
3940
4454
  if (this.lastContainer) {
3941
4455
  this.lastContainer.style.overflow = "hidden";
3942
4456
  if (computed$2 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
@@ -3973,18 +4487,23 @@ var DiffEditorManager = class DiffEditorManager {
3973
4487
  if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = this.modifiedModel.getValue();
3974
4488
  const prevO = this.lastKnownOriginalCode;
3975
4489
  const prevM = this.lastKnownModifiedCode;
4490
+ const originalTailAppend = originalCode !== prevO && originalCode.startsWith(prevO) && prevO.length < originalCode.length;
4491
+ const modifiedTailAppend = modifiedCode !== prevM && modifiedCode.startsWith(prevM) && prevM.length < modifiedCode.length;
4492
+ const hasContentChange = originalCode !== prevO || modifiedCode !== prevM;
3976
4493
  if (originalCode !== prevO || modifiedCode !== prevM) this.markDiffStreamingActivity();
4494
+ const deferTailAppendForInline = this.shouldDeferTailAppendForInlineStreaming();
3977
4495
  let didImmediate = false;
3978
- if (originalCode !== prevO && originalCode.startsWith(prevO)) {
4496
+ if (originalTailAppend && !deferTailAppendForInline) {
3979
4497
  this.appendOriginal(originalCode.slice(prevO.length));
3980
4498
  this.lastKnownOriginalCode = originalCode;
3981
4499
  didImmediate = true;
3982
4500
  }
3983
- if (modifiedCode !== prevM && modifiedCode.startsWith(prevM)) {
4501
+ if (modifiedTailAppend && !deferTailAppendForInline) {
3984
4502
  this.appendModified(modifiedCode.slice(prevM.length));
3985
4503
  this.lastKnownModifiedCode = modifiedCode;
3986
4504
  didImmediate = true;
3987
4505
  }
4506
+ if (hasContentChange) this.preserveNativeDiffDecorationsOnStaleAppend = (originalCode === prevO || originalTailAppend) && (modifiedCode === prevM || modifiedTailAppend);
3988
4507
  if (originalCode !== this.lastKnownOriginalCode || modifiedCode !== this.lastKnownModifiedCode) {
3989
4508
  this.pendingDiffUpdate = {
3990
4509
  original: originalCode,
@@ -3993,6 +4512,16 @@ var DiffEditorManager = class DiffEditorManager {
3993
4512
  this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
3994
4513
  } else if (didImmediate) {}
3995
4514
  }
4515
+ shouldDeferTailAppendForInlineStreaming() {
4516
+ var _this$lastContainer11, _this$lastContainer12, _this$lastContainer13;
4517
+ const renderSideBySide = this.options.renderSideBySide ?? true;
4518
+ if (renderSideBySide === false) return true;
4519
+ const useInlineViewWhenSpaceIsLimited = this.options.useInlineViewWhenSpaceIsLimited ?? true;
4520
+ if (!useInlineViewWhenSpaceIsLimited) return false;
4521
+ const breakpoint = this.options.renderSideBySideInlineBreakpoint ?? 900;
4522
+ const width = ((_this$lastContainer11 = this.lastContainer) === null || _this$lastContainer11 === void 0 || (_this$lastContainer12 = _this$lastContainer11.getBoundingClientRect) === null || _this$lastContainer12 === void 0 ? void 0 : _this$lastContainer12.call(_this$lastContainer11).width) ?? ((_this$lastContainer13 = this.lastContainer) === null || _this$lastContainer13 === void 0 ? void 0 : _this$lastContainer13.clientWidth) ?? 0;
4523
+ return width > 0 && width <= breakpoint;
4524
+ }
3996
4525
  updateOriginal(newCode, codeLanguage) {
3997
4526
  if (!this.diffEditorView || !this.originalModel) return;
3998
4527
  if (codeLanguage) {
@@ -4001,8 +4530,10 @@ var DiffEditorManager = class DiffEditorManager {
4001
4530
  }
4002
4531
  const prev = this.lastKnownOriginalCode ?? this.originalModel.getValue();
4003
4532
  if (prev === newCode) return;
4533
+ const tailAppend = newCode.startsWith(prev) && prev.length < newCode.length;
4004
4534
  this.markDiffStreamingActivity();
4005
- if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
4535
+ this.preserveNativeDiffDecorationsOnStaleAppend = tailAppend;
4536
+ if (tailAppend) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
4006
4537
  else {
4007
4538
  this.flushOriginalAppendBufferSync();
4008
4539
  this.applyMinimalEditToModel(this.originalModel, prev, newCode);
@@ -4017,8 +4548,10 @@ var DiffEditorManager = class DiffEditorManager {
4017
4548
  }
4018
4549
  const prev = this.lastKnownModifiedCode ?? this.modifiedModel.getValue();
4019
4550
  if (prev === newCode) return;
4551
+ const tailAppend = newCode.startsWith(prev) && prev.length < newCode.length;
4020
4552
  this.markDiffStreamingActivity();
4021
- if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendModified(newCode.slice(prev.length), codeLanguage);
4553
+ this.preserveNativeDiffDecorationsOnStaleAppend = tailAppend;
4554
+ if (tailAppend) this.appendModified(newCode.slice(prev.length), codeLanguage);
4022
4555
  else {
4023
4556
  this.flushModifiedAppendBufferSync();
4024
4557
  const prevAfterFlush = this.modifiedModel.getValue();
@@ -4026,10 +4559,11 @@ var DiffEditorManager = class DiffEditorManager {
4026
4559
  this.applyMinimalEditToModel(this.modifiedModel, prevAfterFlush, newCode);
4027
4560
  const newLine = this.modifiedModel.getLineCount();
4028
4561
  if (newLine !== prevLine) {
4562
+ this.eagerlyGrowDiffContainerHeight();
4029
4563
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4030
4564
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4031
4565
  const computed$2 = this.computedHeight();
4032
- if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
4566
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4033
4567
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4034
4568
  this.lastContainer.style.overflow = "hidden";
4035
4569
  }
@@ -4042,6 +4576,7 @@ var DiffEditorManager = class DiffEditorManager {
4042
4576
  appendOriginal(appendText, codeLanguage) {
4043
4577
  if (!this.diffEditorView || !this.originalModel || !appendText) return;
4044
4578
  this.markDiffStreamingActivity();
4579
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4045
4580
  if (codeLanguage) {
4046
4581
  const lang = processedLanguage(codeLanguage);
4047
4582
  if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
@@ -4052,6 +4587,7 @@ var DiffEditorManager = class DiffEditorManager {
4052
4587
  appendModified(appendText, codeLanguage) {
4053
4588
  if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
4054
4589
  this.markDiffStreamingActivity();
4590
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4055
4591
  if (codeLanguage) {
4056
4592
  const lang = processedLanguage(codeLanguage);
4057
4593
  if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
@@ -4068,9 +4604,10 @@ var DiffEditorManager = class DiffEditorManager {
4068
4604
  if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
4069
4605
  }
4070
4606
  async setDiffModels(models, options = {}) {
4071
- var _this$originalModel2, _this$modifiedModel5, _this$diffEditorView$5, _this$diffEditorView$6, _this$diffEditorView$7, _this$diffEditorView$8;
4607
+ var _this$originalModel2, _this$modifiedModel5, _this$diffEditorView$6, _this$diffEditorView$7, _this$diffEditorView$8, _this$diffEditorView$9;
4072
4608
  if (!this.diffEditorView) return;
4073
4609
  const transitionRequestId = ++this.diffModelTransitionRequestId;
4610
+ this.preserveNativeDiffDecorationsOnStaleAppend = false;
4074
4611
  this.disposePendingPreparedDiffViewModel();
4075
4612
  const nextOriginal = models.original;
4076
4613
  const nextModified = models.modified;
@@ -4121,17 +4658,19 @@ var DiffEditorManager = class DiffEditorManager {
4121
4658
  this.pendingDiffUpdate = null;
4122
4659
  this.flushOriginalAppendBufferSync();
4123
4660
  this.flushModifiedAppendBufferSync();
4661
+ this.preserveNativeDiffDecorationsOnStaleAppend = false;
4124
4662
  const currentOriginal = this.originalModel;
4125
4663
  const currentModified = this.modifiedModel;
4126
4664
  const shouldRestorePersistedUnchangedState = preserveViewState && !sameContent;
4665
+ const shouldRestoreSavedModelState = options.preserveModelState ?? true;
4127
4666
  const preservedScrollPosition = preserveViewState ? this.captureDiffScrollPosition() : null;
4128
4667
  const preservedViewportAnchor = preserveViewState && sameContent ? this.captureModifiedViewportAnchor() : null;
4129
- const viewState = preserveViewState ? this.diffEditorView.saveViewState() : null;
4668
+ const viewState = preserveViewState && shouldRestoreSavedModelState ? this.diffEditorView.saveViewState() : null;
4130
4669
  this.queuePendingDiffScrollRestore(preservedScrollPosition, shouldRestorePersistedUnchangedState ? 2 : 0);
4131
4670
  if (shouldRestorePersistedUnchangedState) this.capturePersistedDiffUnchangedState();
4132
4671
  const applyModelSwap = () => {
4133
- var _this$diffEditorView35;
4134
- (_this$diffEditorView35 = this.diffEditorView) === null || _this$diffEditorView35 === void 0 || _this$diffEditorView35.setModel(nextModelTarget);
4672
+ var _this$diffEditorView33;
4673
+ (_this$diffEditorView33 = this.diffEditorView) === null || _this$diffEditorView33 === void 0 || _this$diffEditorView33.setModel(nextModelTarget);
4135
4674
  };
4136
4675
  if (preserveViewState) this.withLockedDiffScrollPosition(applyModelSwap);
4137
4676
  else applyModelSwap();
@@ -4146,8 +4685,8 @@ var DiffEditorManager = class DiffEditorManager {
4146
4685
  this.lastKnownModifiedLineCount = nextModified.getLineCount();
4147
4686
  this.lastKnownModifiedDirty = false;
4148
4687
  this._hasScrollBar = false;
4149
- this.cachedScrollHeightDiff = ((_this$diffEditorView$5 = (_this$diffEditorView$6 = this.diffEditorView.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView$5 === void 0 ? void 0 : _this$diffEditorView$5.call(_this$diffEditorView$6)) ?? null;
4150
- this.cachedLineHeightDiff = ((_this$diffEditorView$7 = (_this$diffEditorView$8 = this.diffEditorView.getModifiedEditor()).getOption) === null || _this$diffEditorView$7 === void 0 ? void 0 : _this$diffEditorView$7.call(_this$diffEditorView$8, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
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;
4151
4690
  this.cachedComputedHeightDiff = this.computedHeight();
4152
4691
  this.diffHunkLineChanges = this.getEffectiveLineChanges();
4153
4692
  this.hideDiffHunkActions();
@@ -4174,19 +4713,9 @@ var DiffEditorManager = class DiffEditorManager {
4174
4713
  }
4175
4714
  cleanup() {
4176
4715
  this.diffModelTransitionRequestId += 1;
4716
+ this.preserveNativeDiffDecorationsOnStaleAppend = false;
4177
4717
  this.disposePendingPreparedDiffViewModel();
4178
- this.rafScheduler.cancel("diff");
4179
- this.pendingDiffUpdate = null;
4180
- this.rafScheduler.cancel("appendDiff");
4181
- this.appendBufferDiffScheduled = false;
4182
- this.appendBufferOriginalDiff.length = 0;
4183
- this.appendBufferModifiedDiff.length = 0;
4184
- if (this.appendFlushThrottleTimerDiff != null) {
4185
- clearTimeout(this.appendFlushThrottleTimerDiff);
4186
- this.appendFlushThrottleTimerDiff = null;
4187
- }
4188
- this.rafScheduler.cancel("content-size-change-diff");
4189
- this.rafScheduler.cancel("sync-last-known-modified");
4718
+ this.clearAsyncWork();
4190
4719
  this.disposeDiffHunkInteractions();
4191
4720
  this.disposeDiffUnchangedRegionEnhancements();
4192
4721
  this.disposeDiffPresentationTracking();
@@ -4217,42 +4746,21 @@ var DiffEditorManager = class DiffEditorManager {
4217
4746
  this.lastContainer.innerHTML = "";
4218
4747
  this.lastContainer = null;
4219
4748
  }
4220
- if (this.revealDebounceIdDiff != null) {
4221
- clearTimeout(this.revealDebounceIdDiff);
4222
- this.revealDebounceIdDiff = null;
4223
- }
4224
- if (this.revealIdleTimerIdDiff != null) {
4225
- clearTimeout(this.revealIdleTimerIdDiff);
4226
- this.revealIdleTimerIdDiff = null;
4227
- }
4228
- if (this.diffScrollWatcherSuppressionTimer != null) {
4229
- clearTimeout(this.diffScrollWatcherSuppressionTimer);
4230
- this.diffScrollWatcherSuppressionTimer = null;
4231
- }
4232
4749
  this.revealTicketDiff = 0;
4233
4750
  this.lastRevealLineDiff = null;
4234
4751
  this.diffPersistedUnchangedModelState = null;
4752
+ this.diffPreviousUnchangedModelState = null;
4235
4753
  this.pendingDiffScrollRestorePosition = null;
4236
4754
  this.pendingDiffScrollRestoreBudget = 0;
4237
4755
  this.diffHideUnchangedRegionsResolved = null;
4238
4756
  this.diffHideUnchangedRegionsDeferred = false;
4239
- this.clearPendingDiffThemeSync();
4240
4757
  }
4241
4758
  safeClean() {
4242
4759
  this.diffModelTransitionRequestId += 1;
4760
+ this.preserveNativeDiffDecorationsOnStaleAppend = false;
4243
4761
  this.disposePendingPreparedDiffViewModel();
4244
- this.rafScheduler.cancel("diff");
4245
- this.pendingDiffUpdate = null;
4246
- this.rafScheduler.cancel("appendDiff");
4247
- this.appendBufferDiffScheduled = false;
4248
- this.appendBufferOriginalDiff.length = 0;
4249
- this.appendBufferModifiedDiff.length = 0;
4250
- if (this.appendFlushThrottleTimerDiff != null) {
4251
- clearTimeout(this.appendFlushThrottleTimerDiff);
4252
- this.appendFlushThrottleTimerDiff = null;
4253
- }
4762
+ this.clearAsyncWork();
4254
4763
  this.hideDiffHunkActions();
4255
- this.cancelScheduledHideDiffHunkActions();
4256
4764
  this.disposeDiffUnchangedRegionEnhancements();
4257
4765
  this.disposeDiffPresentationTracking();
4258
4766
  if (this.diffScrollWatcher) {
@@ -4266,25 +4774,14 @@ var DiffEditorManager = class DiffEditorManager {
4266
4774
  this.diffHeightManager.dispose();
4267
4775
  this.diffHeightManager = null;
4268
4776
  }
4269
- if (this.revealDebounceIdDiff != null) {
4270
- clearTimeout(this.revealDebounceIdDiff);
4271
- this.revealDebounceIdDiff = null;
4272
- }
4273
- if (this.revealIdleTimerIdDiff != null) {
4274
- clearTimeout(this.revealIdleTimerIdDiff);
4275
- this.revealIdleTimerIdDiff = null;
4276
- }
4277
- if (this.diffScrollWatcherSuppressionTimer != null) {
4278
- clearTimeout(this.diffScrollWatcherSuppressionTimer);
4279
- this.diffScrollWatcherSuppressionTimer = null;
4280
- }
4281
4777
  this.revealTicketDiff = 0;
4282
4778
  this.lastRevealLineDiff = null;
4283
4779
  this.diffPersistedUnchangedModelState = null;
4780
+ this.diffPreviousUnchangedModelState = null;
4284
4781
  this.diffHideUnchangedRegionsDeferred = false;
4285
- this.clearPendingDiffThemeSync();
4286
- this.rafScheduler.cancel("content-size-change-diff");
4287
- this.rafScheduler.cancel("sync-last-known-modified");
4782
+ this.clearInlineDiffStreamingPresentationIdleTimer();
4783
+ this.inlineDiffStreamingPresentationActive = false;
4784
+ this.resetInlineDiffStreamingHeightFloor();
4288
4785
  }
4289
4786
  syncLastKnownModified() {
4290
4787
  if (!this.diffEditorView || !this.lastKnownModifiedDirty) return;
@@ -4323,23 +4820,28 @@ var DiffEditorManager = class DiffEditorManager {
4323
4820
  if (this.lastKnownOriginalCode == null) this.lastKnownOriginalCode = o.getValue();
4324
4821
  if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = m.getValue();
4325
4822
  const prevO = this.lastKnownOriginalCode;
4823
+ const originalTailAppend = prevO !== original && original.startsWith(prevO) && prevO.length < original.length;
4326
4824
  if (prevO !== original) {
4327
- if (original.startsWith(prevO) && prevO.length < original.length) this.appendToModel(o, original.slice(prevO.length));
4825
+ if (originalTailAppend) this.appendToModel(o, original.slice(prevO.length));
4328
4826
  else this.applyMinimalEditToModel(o, prevO, original);
4329
4827
  this.lastKnownOriginalCode = original;
4330
4828
  }
4331
4829
  const prevM = m.getValue();
4332
4830
  const prevMLineCount = m.getLineCount();
4831
+ const modifiedTailAppend = prevM !== modified && modified.startsWith(prevM) && prevM.length < modified.length;
4832
+ const hasContentChange = prevO !== original || prevM !== modified;
4833
+ if (hasContentChange) this.preserveNativeDiffDecorationsOnStaleAppend = (prevO === original || originalTailAppend) && (prevM === modified || modifiedTailAppend);
4333
4834
  if (prevM !== modified) {
4334
- if (modified.startsWith(prevM) && prevM.length < modified.length) this.appendToModel(m, modified.slice(prevM.length));
4835
+ if (modifiedTailAppend) this.appendToModel(m, modified.slice(prevM.length));
4335
4836
  else this.applyMinimalEditToModel(m, prevM, modified);
4336
4837
  this.lastKnownModifiedCode = modified;
4337
4838
  const newMLineCount = m.getLineCount();
4338
4839
  if (newMLineCount !== prevMLineCount) {
4840
+ this.eagerlyGrowDiffContainerHeight();
4339
4841
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4340
4842
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4341
4843
  const computed$2 = this.computedHeight();
4342
- if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
4844
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4343
4845
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4344
4846
  this.lastContainer.style.overflow = "hidden";
4345
4847
  }
@@ -4356,6 +4858,7 @@ var DiffEditorManager = class DiffEditorManager {
4356
4858
  const text = this.appendBufferModifiedDiff.join("");
4357
4859
  this.appendBufferModifiedDiff.length = 0;
4358
4860
  if (!text) return;
4861
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4359
4862
  this.appendToModel(this.modifiedModel, text);
4360
4863
  }
4361
4864
  async flushAppendBufferDiff() {
@@ -4366,7 +4869,10 @@ var DiffEditorManager = class DiffEditorManager {
4366
4869
  if (this.originalModel && this.appendBufferOriginalDiff.length > 0) {
4367
4870
  const oText = this.appendBufferOriginalDiff.join("");
4368
4871
  this.appendBufferOriginalDiff.length = 0;
4369
- if (oText) this.appendToModel(this.originalModel, oText);
4872
+ if (oText) {
4873
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4874
+ this.appendToModel(this.originalModel, oText);
4875
+ }
4370
4876
  }
4371
4877
  const me = this.diffEditorView.getModifiedEditor();
4372
4878
  const model = me.getModel();
@@ -4415,6 +4921,7 @@ var DiffEditorManager = class DiffEditorManager {
4415
4921
  });
4416
4922
  const lastColumn$1 = model.getLineMaxColumn(prevLine);
4417
4923
  const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
4924
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4418
4925
  model.applyEdits([{
4419
4926
  range: range$1,
4420
4927
  text: part,
@@ -4424,6 +4931,7 @@ var DiffEditorManager = class DiffEditorManager {
4424
4931
  const newLine$1 = model.getLineCount();
4425
4932
  this.lastKnownModifiedLineCount = newLine$1;
4426
4933
  await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
4934
+ this.eagerlyGrowDiffContainerHeight();
4427
4935
  const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
4428
4936
  log("diff", "flushAppendBufferDiff chunk metrics", {
4429
4937
  idx,
@@ -4433,7 +4941,7 @@ var DiffEditorManager = class DiffEditorManager {
4433
4941
  });
4434
4942
  if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4435
4943
  const computed$3 = this.computedHeight();
4436
- if (computed$3 >= this.maxHeightValue - 1 && this.lastContainer) {
4944
+ if (computed$3 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) {
4437
4945
  this.lastContainer.style.height = `${this.maxHeightValue}px`;
4438
4946
  this.lastContainer.style.overflow = "hidden";
4439
4947
  }
@@ -4453,6 +4961,7 @@ var DiffEditorManager = class DiffEditorManager {
4453
4961
  prevLine = model.getLineCount();
4454
4962
  const lastColumn = model.getLineMaxColumn(prevLine);
4455
4963
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
4964
+ this.preserveNativeDiffDecorationsOnStaleAppend = true;
4456
4965
  model.applyEdits([{
4457
4966
  range,
4458
4967
  text,
@@ -4461,17 +4970,17 @@ var DiffEditorManager = class DiffEditorManager {
4461
4970
  this.lastKnownModifiedCode = model.getValue();
4462
4971
  const newLine = model.getLineCount();
4463
4972
  this.lastKnownModifiedLineCount = newLine;
4973
+ this.eagerlyGrowDiffContainerHeight();
4464
4974
  const shouldImmediate = this.shouldPerformImmediateRevealDiff();
4465
4975
  if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
4466
4976
  const computed$2 = this.computedHeight();
4467
- if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
4977
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer && !this.shouldAvoidOptimisticMaxHeightWriteDiff()) this.lastContainer.style.height = `${this.maxHeightValue}px`;
4468
4978
  if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
4469
4979
  else this.maybeScrollDiffToBottom(newLine, prevLine);
4470
4980
  if (suppressedByFlush) watcherApi.setSuppressed(false);
4471
4981
  try {
4472
- var _this$diffEditorView36, _this$diffEditorView37, _this$diffEditorView38;
4473
- this.shouldAutoScrollDiff = true;
4474
- this.lastScrollTopDiff = ((_this$diffEditorView36 = this.diffEditorView) === null || _this$diffEditorView36 === void 0 || (_this$diffEditorView38 = (_this$diffEditorView37 = _this$diffEditorView36.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView38 === void 0 ? void 0 : _this$diffEditorView38.call(_this$diffEditorView37)) ?? this.lastScrollTopDiff;
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;
4475
4984
  } catch {}
4476
4985
  }
4477
4986
  applyMinimalEditToModel(model, prev, next) {
@@ -4519,6 +5028,9 @@ var EditorManager = class {
4519
5028
  lastKnownCode = null;
4520
5029
  pendingUpdate = null;
4521
5030
  _hasScrollBar = false;
5031
+ updateThrottleMs = 50;
5032
+ lastUpdateFlushTime = 0;
5033
+ updateThrottleTimer = null;
4522
5034
  shouldAutoScroll = true;
4523
5035
  scrollWatcher = null;
4524
5036
  scrollWatcherSuppressionTimer = null;
@@ -4528,6 +5040,7 @@ var EditorManager = class {
4528
5040
  cachedComputedHeight = null;
4529
5041
  cachedLineCount = null;
4530
5042
  lastKnownCodeDirty = false;
5043
+ programmaticContentChangeDepth = 0;
4531
5044
  debug = false;
4532
5045
  measureViewport() {
4533
5046
  var _this$editorView$getL, _this$editorView, _this$editorView$getS, _this$editorView2, _this$editorView$getS2, _this$editorView3;
@@ -4560,7 +5073,7 @@ var EditorManager = class {
4560
5073
  revealStrategyOption;
4561
5074
  revealBatchOnIdleMsOption;
4562
5075
  scrollWatcherSuppressionMs = 500;
4563
- constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, revealDebounceMsOption) {
5076
+ constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, revealDebounceMsOption, updateThrottleMsOption) {
4564
5077
  this.options = options;
4565
5078
  this.maxHeightValue = maxHeightValue;
4566
5079
  this.maxHeightCSS = maxHeightCSS;
@@ -4569,6 +5082,47 @@ var EditorManager = class {
4569
5082
  this.autoScrollThresholdPx = autoScrollThresholdPx;
4570
5083
  this.autoScrollThresholdLines = autoScrollThresholdLines;
4571
5084
  this.revealDebounceMsOption = revealDebounceMsOption;
5085
+ this.updateThrottleMsOption = updateThrottleMsOption;
5086
+ this.updateThrottleMs = this.updateThrottleMsOption ?? this.options.updateThrottleMs ?? 50;
5087
+ }
5088
+ cancelRafs() {
5089
+ this.rafScheduler.cancel("update");
5090
+ this.rafScheduler.cancel("sync-last-known");
5091
+ this.rafScheduler.cancel("content-size-change");
5092
+ this.rafScheduler.cancel("maybe-scroll");
5093
+ this.rafScheduler.cancel("reveal");
5094
+ this.rafScheduler.cancel("immediate-reveal");
5095
+ this.rafScheduler.cancel("maybe-resume");
5096
+ this.rafScheduler.cancel("append");
5097
+ }
5098
+ clearRevealTimers() {
5099
+ if (this.revealDebounceId != null) {
5100
+ clearTimeout(this.revealDebounceId);
5101
+ this.revealDebounceId = null;
5102
+ }
5103
+ if (this.revealIdleTimerId != null) {
5104
+ clearTimeout(this.revealIdleTimerId);
5105
+ this.revealIdleTimerId = null;
5106
+ }
5107
+ }
5108
+ resetAppendState() {
5109
+ this.appendBufferScheduled = false;
5110
+ this.appendBuffer.length = 0;
5111
+ }
5112
+ clearAsyncWork() {
5113
+ this.cancelRafs();
5114
+ this.pendingUpdate = null;
5115
+ this.lastKnownCodeDirty = false;
5116
+ this.resetAppendState();
5117
+ this.clearRevealTimers();
5118
+ if (this.scrollWatcherSuppressionTimer != null) {
5119
+ clearTimeout(this.scrollWatcherSuppressionTimer);
5120
+ this.scrollWatcherSuppressionTimer = null;
5121
+ }
5122
+ if (this.updateThrottleTimer != null) {
5123
+ clearTimeout(this.updateThrottleTimer);
5124
+ this.updateThrottleTimer = null;
5125
+ }
4572
5126
  }
4573
5127
  initDebugFlag() {
4574
5128
  if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) {
@@ -4585,6 +5139,14 @@ var EditorManager = class {
4585
5139
  if (!this.debug) return;
4586
5140
  log("EditorManager", ...args);
4587
5141
  }
5142
+ runAsProgrammaticContentChange(fn) {
5143
+ this.programmaticContentChangeDepth += 1;
5144
+ try {
5145
+ return fn();
5146
+ } finally {
5147
+ this.programmaticContentChangeDepth -= 1;
5148
+ }
5149
+ }
4588
5150
  hasVerticalScrollbar() {
4589
5151
  if (!this.editorView) return false;
4590
5152
  if (this._hasScrollBar) return true;
@@ -4811,6 +5373,7 @@ var EditorManager = class {
4811
5373
  });
4812
5374
  });
4813
5375
  this.editorView.onDidChangeModelContent(() => {
5376
+ if (this.programmaticContentChangeDepth > 0) return;
4814
5377
  this.lastKnownCodeDirty = true;
4815
5378
  this.rafScheduler.schedule("sync-last-known", () => this.syncLastKnownCode());
4816
5379
  });
@@ -4905,7 +5468,24 @@ var EditorManager = class {
4905
5468
  code: newCode,
4906
5469
  lang: codeLanguage
4907
5470
  };
4908
- this.rafScheduler.schedule("update", () => this.flushPendingUpdate());
5471
+ this.rafScheduler.schedule("update", () => {
5472
+ if (!this.updateThrottleMs) {
5473
+ this.flushPendingUpdate();
5474
+ return;
5475
+ }
5476
+ const now = Date.now();
5477
+ const since = now - this.lastUpdateFlushTime;
5478
+ if (since >= this.updateThrottleMs) {
5479
+ this.flushPendingUpdate();
5480
+ return;
5481
+ }
5482
+ if (this.updateThrottleTimer != null) return;
5483
+ const wait = this.updateThrottleMs - since;
5484
+ this.updateThrottleTimer = setTimeout(() => {
5485
+ this.updateThrottleTimer = null;
5486
+ this.rafScheduler.schedule("update", () => this.flushPendingUpdate());
5487
+ }, wait);
5488
+ });
4909
5489
  }
4910
5490
  flushPendingUpdate() {
4911
5491
  if (!this.pendingUpdate || !this.editorView) return;
@@ -4913,12 +5493,15 @@ var EditorManager = class {
4913
5493
  if (!model) return;
4914
5494
  const { code: newCode, lang: codeLanguage } = this.pendingUpdate;
4915
5495
  this.pendingUpdate = null;
5496
+ this.lastUpdateFlushTime = Date.now();
4916
5497
  const processedCodeLanguage = processedLanguage(codeLanguage);
4917
5498
  const languageId = model.getLanguageId();
4918
5499
  if (languageId !== processedCodeLanguage) {
4919
5500
  if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
4920
5501
  const prevLineCount$1 = model.getLineCount();
4921
- model.setValue(newCode);
5502
+ this.runAsProgrammaticContentChange(() => {
5503
+ model.setValue(newCode);
5504
+ });
4922
5505
  this.lastKnownCode = newCode;
4923
5506
  const newLineCount$1 = model.getLineCount();
4924
5507
  this.cachedLineCount = newLineCount$1;
@@ -4931,8 +5514,21 @@ var EditorManager = class {
4931
5514
  }
4932
5515
  return;
4933
5516
  }
4934
- const buffered = this.appendBuffer.length > 0 ? this.appendBuffer.join("") : "";
4935
- const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() + buffered : this.lastKnownCode ?? this.editorView.getValue();
5517
+ let prevCode;
5518
+ if (this.appendBuffer.length > 0) {
5519
+ this.resetAppendState();
5520
+ this.rafScheduler.cancel("append");
5521
+ try {
5522
+ prevCode = model.getValue();
5523
+ this.lastKnownCode = prevCode;
5524
+ } catch {
5525
+ prevCode = this.lastKnownCode ?? "";
5526
+ }
5527
+ } else if (this.lastKnownCode != null) prevCode = this.lastKnownCode;
5528
+ else {
5529
+ prevCode = this.editorView.getValue();
5530
+ this.lastKnownCode = prevCode;
5531
+ }
4936
5532
  if (prevCode === newCode) return;
4937
5533
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
4938
5534
  const suffix = newCode.slice(prevCode.length);
@@ -4976,7 +5572,9 @@ var EditorManager = class {
4976
5572
  const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
4977
5573
  if (prev.length + next.length > maxChars || changeRatio > ratio) {
4978
5574
  const prevLineCount = model.getLineCount();
4979
- model.setValue(next);
5575
+ this.runAsProgrammaticContentChange(() => {
5576
+ model.setValue(next);
5577
+ });
4980
5578
  this.lastKnownCode = next;
4981
5579
  const newLineCount = model.getLineCount();
4982
5580
  this.cachedLineCount = newLineCount;
@@ -4995,8 +5593,10 @@ var EditorManager = class {
4995
5593
  text: replaceText,
4996
5594
  forceMoveMarkers: true
4997
5595
  }];
4998
- if (isReadOnly) model.applyEdits(edit);
4999
- else this.editorView.executeEdits("minimal-replace", edit);
5596
+ this.runAsProgrammaticContentChange(() => {
5597
+ if (isReadOnly) model.applyEdits(edit);
5598
+ else this.editorView.executeEdits("minimal-replace", edit);
5599
+ });
5000
5600
  }
5001
5601
  flushAppendBuffer() {
5002
5602
  if (!this.editorView) return;
@@ -5013,19 +5613,20 @@ var EditorManager = class {
5013
5613
  const lastColumn = model.getLineMaxColumn(lastLine);
5014
5614
  const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
5015
5615
  const isReadOnly = this.editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
5016
- if (isReadOnly) model.applyEdits([{
5017
- range,
5018
- text,
5019
- forceMoveMarkers: true
5020
- }]);
5021
- else this.editorView.executeEdits("append", [{
5022
- range,
5023
- text,
5024
- forceMoveMarkers: true
5025
- }]);
5026
- try {
5027
- this.lastKnownCode = model.getValue();
5028
- } catch {}
5616
+ this.runAsProgrammaticContentChange(() => {
5617
+ if (isReadOnly) model.applyEdits([{
5618
+ range,
5619
+ text,
5620
+ forceMoveMarkers: true
5621
+ }]);
5622
+ else this.editorView.executeEdits("append", [{
5623
+ range,
5624
+ text,
5625
+ forceMoveMarkers: true
5626
+ }]);
5627
+ });
5628
+ if (this.lastKnownCode != null) this.lastKnownCode = this.lastKnownCode + text;
5629
+ else this.lastKnownCode = model.getValue();
5029
5630
  const newLineCount = model.getLineCount();
5030
5631
  if (lastLine !== newLineCount) {
5031
5632
  this.cachedLineCount = newLineCount;
@@ -5050,30 +5651,19 @@ var EditorManager = class {
5050
5651
  getEditorView() {
5051
5652
  return this.editorView;
5052
5653
  }
5053
- cleanup() {
5054
- this.rafScheduler.cancel("update");
5055
- this.rafScheduler.cancel("sync-last-known");
5056
- this.rafScheduler.cancel("content-size-change");
5057
- this.rafScheduler.cancel("maybe-scroll");
5058
- this.rafScheduler.cancel("reveal");
5059
- this.rafScheduler.cancel("immediate-reveal");
5060
- this.rafScheduler.cancel("maybe-resume");
5061
- this.pendingUpdate = null;
5062
- this.rafScheduler.cancel("append");
5063
- this.appendBufferScheduled = false;
5064
- this.appendBuffer.length = 0;
5065
- if (this.revealDebounceId != null) {
5066
- clearTimeout(this.revealDebounceId);
5067
- this.revealDebounceId = null;
5068
- }
5069
- if (this.revealIdleTimerId != null) {
5070
- clearTimeout(this.revealIdleTimerId);
5071
- this.revealIdleTimerId = null;
5072
- }
5073
- if (this.scrollWatcherSuppressionTimer != null) {
5074
- clearTimeout(this.scrollWatcherSuppressionTimer);
5075
- this.scrollWatcherSuppressionTimer = null;
5654
+ setUpdateThrottleMs(ms) {
5655
+ this.updateThrottleMs = ms;
5656
+ if (!this.updateThrottleMs && this.updateThrottleTimer != null) {
5657
+ clearTimeout(this.updateThrottleTimer);
5658
+ this.updateThrottleTimer = null;
5659
+ this.rafScheduler.schedule("update", () => this.flushPendingUpdate());
5076
5660
  }
5661
+ }
5662
+ getUpdateThrottleMs() {
5663
+ return this.updateThrottleMs;
5664
+ }
5665
+ cleanup() {
5666
+ this.clearAsyncWork();
5077
5667
  if (this.editorView) {
5078
5668
  this.editorView.dispose();
5079
5669
  this.editorView = null;
@@ -5094,31 +5684,13 @@ var EditorManager = class {
5094
5684
  }
5095
5685
  }
5096
5686
  safeClean() {
5097
- this.rafScheduler.cancel("update");
5098
- this.pendingUpdate = null;
5099
- this.rafScheduler.cancel("sync-last-known");
5687
+ this.clearAsyncWork();
5100
5688
  if (this.scrollWatcher) {
5101
5689
  try {
5102
5690
  this.scrollWatcher.dispose();
5103
5691
  } catch {}
5104
5692
  this.scrollWatcher = null;
5105
5693
  }
5106
- if (this.revealDebounceId != null) {
5107
- clearTimeout(this.revealDebounceId);
5108
- this.revealDebounceId = null;
5109
- }
5110
- if (this.revealIdleTimerId != null) {
5111
- clearTimeout(this.revealIdleTimerId);
5112
- this.revealIdleTimerId = null;
5113
- }
5114
- if (this.scrollWatcherSuppressionTimer != null) {
5115
- clearTimeout(this.scrollWatcherSuppressionTimer);
5116
- this.scrollWatcherSuppressionTimer = null;
5117
- }
5118
- this.rafScheduler.cancel("maybe-scroll");
5119
- this.rafScheduler.cancel("reveal");
5120
- this.rafScheduler.cancel("immediate-reveal");
5121
- this.rafScheduler.cancel("maybe-resume");
5122
5694
  this._hasScrollBar = false;
5123
5695
  this.shouldAutoScroll = !!this.autoScrollInitial;
5124
5696
  this.lastScrollTop = 0;
@@ -5657,7 +6229,7 @@ function useMonaco(monacoOptions = {}) {
5657
6229
  }
5658
6230
  const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
5659
6231
  await ensureThemeRegistered(initialThemeName);
5660
- editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs);
6232
+ editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, updateThrottleMs);
5661
6233
  editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
5662
6234
  if (pendingUpdate && editorMgr) {
5663
6235
  const { code: queuedCode, lang: queuedLang } = pendingUpdate;
@@ -5699,6 +6271,23 @@ function useMonaco(monacoOptions = {}) {
5699
6271
  modifiedModel = models.modified;
5700
6272
  return diffEditorView;
5701
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
+ }
5702
6291
  function cleanupEditor() {
5703
6292
  if (editorMgr) {
5704
6293
  editorMgr.cleanup();
@@ -5708,11 +6297,7 @@ function useMonaco(monacoOptions = {}) {
5708
6297
  diffMgr.cleanup();
5709
6298
  diffMgr = null;
5710
6299
  }
5711
- rafScheduler.cancel("update");
5712
- pendingUpdate = null;
5713
- rafScheduler.cancel("append");
5714
- appendBufferScheduled = false;
5715
- appendBuffer.length = 0;
6300
+ clearFallbackAsyncWork();
5716
6301
  if (!editorMgr && editorView) {
5717
6302
  editorView.dispose();
5718
6303
  editorView = null;
@@ -5726,10 +6311,6 @@ function useMonaco(monacoOptions = {}) {
5726
6311
  themeWatcher();
5727
6312
  themeWatcher = null;
5728
6313
  }
5729
- if (updateThrottleTimer != null) {
5730
- clearTimeout(updateThrottleTimer);
5731
- updateThrottleTimer = null;
5732
- }
5733
6314
  diffEditorView = null;
5734
6315
  originalModel = null;
5735
6316
  modifiedModel = null;
@@ -5795,13 +6376,17 @@ function useMonaco(monacoOptions = {}) {
5795
6376
  pendingUpdate = null;
5796
6377
  const processedCodeLanguage = processedLanguage(codeLanguage);
5797
6378
  let prevCode = null;
5798
- if (appendBuffer.length > 0) try {
5799
- prevCode = model.getValue();
5800
- lastKnownCode = prevCode;
5801
- } catch {
5802
- prevCode = "";
5803
- }
5804
- else {
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 ?? "";
6388
+ }
6389
+ } else {
5805
6390
  prevCode = lastKnownCode;
5806
6391
  if (prevCode == null) try {
5807
6392
  prevCode = model.getValue();
@@ -5918,9 +6503,10 @@ function useMonaco(monacoOptions = {}) {
5918
6503
  }
5919
6504
  function setUpdateThrottleMs(ms) {
5920
6505
  updateThrottleMs = ms;
6506
+ editorMgr === null || editorMgr === void 0 || editorMgr.setUpdateThrottleMs(ms);
5921
6507
  }
5922
6508
  function getUpdateThrottleMs() {
5923
- return updateThrottleMs;
6509
+ return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? updateThrottleMs;
5924
6510
  }
5925
6511
  function updateDiff(originalCode, modifiedCode, codeLanguage) {
5926
6512
  if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
@@ -5952,8 +6538,7 @@ function useMonaco(monacoOptions = {}) {
5952
6538
  createDiffEditor,
5953
6539
  cleanupEditor,
5954
6540
  safeClean() {
5955
- rafScheduler.cancel("update");
5956
- pendingUpdate = null;
6541
+ clearFallbackAsyncWork();
5957
6542
  if (editorMgr) try {
5958
6543
  editorMgr.safeClean();
5959
6544
  } catch {}