stream-monaco 0.0.39 → 0.0.41

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.
@@ -269,32 +269,45 @@ function error(tag, ...args) {
269
269
 
270
270
  //#endregion
271
271
  //#region src/utils/height.ts
272
- function createHeightManager(container, computeNext) {
272
+ const DEFAULT_TRANSITION_MS = 120;
273
+ const DEFAULT_TRANSITION_EASING = "cubic-bezier(0.4, 0, 0.2, 1)";
274
+ const DEFAULT_HYSTERESIS_PX = 12;
275
+ const DEFAULT_DEBOUNCE_MS = 0;
276
+ function prefersReducedMotion() {
277
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
278
+ }
279
+ function createHeightManager(container, computeNext, options = {}) {
280
+ const transitionMs = Math.max(0, options.transitionMs ?? DEFAULT_TRANSITION_MS);
281
+ const transitionEasing = options.transitionEasing ?? DEFAULT_TRANSITION_EASING;
282
+ const hysteresisPx = Math.max(0, options.hysteresisPx ?? DEFAULT_HYSTERESIS_PX);
283
+ const debounceMs = Math.max(0, options.debounceMs ?? DEFAULT_DEBOUNCE_MS);
284
+ const transitionEnabled = options.smooth === true && transitionMs > 0 && !prefersReducedMotion();
285
+ const previousTransition = container.style.transition || "";
286
+ const heightTransition = `height ${transitionMs}ms ${transitionEasing}`;
287
+ if (transitionEnabled) container.style.transition = previousTransition ? `${previousTransition}, ${heightTransition}` : heightTransition;
273
288
  let raf = null;
274
289
  let debounceTimer = null;
275
290
  let lastApplied = -1;
276
291
  let suppressed = false;
277
- const HYSTERESIS_PX = 12;
278
- const DEBOUNCE_MS = 0;
279
292
  function apply() {
280
293
  var _container$getBoundin;
281
294
  const next = computeNext();
282
- if (next == null) return;
295
+ if (next == null) return null;
283
296
  log("heightManager", "computeNext ->", {
284
297
  next,
285
298
  lastApplied
286
299
  });
287
300
  if (!Number.isFinite(next) || next <= 0) {
288
301
  log("heightManager", "invalid next height, ignoring", next);
289
- return;
302
+ return null;
290
303
  }
291
304
  const currentHeight = Number.parseFloat(container.style.height || "") || ((_container$getBoundin = container.getBoundingClientRect) === null || _container$getBoundin === void 0 ? void 0 : _container$getBoundin.call(container).height) || 0;
292
- if (currentHeight > 0 && Math.abs(next - currentHeight) <= HYSTERESIS_PX) {
305
+ if (currentHeight > 0 && Math.abs(next - currentHeight) <= hysteresisPx) {
293
306
  lastApplied = next;
294
- return;
307
+ return next;
295
308
  }
296
- if (lastApplied !== -1 && Math.abs(next - lastApplied) <= HYSTERESIS_PX) return;
297
- if (next === lastApplied) return;
309
+ if (lastApplied !== -1 && Math.abs(next - lastApplied) <= hysteresisPx) return next;
310
+ if (next === lastApplied) return next;
298
311
  suppressed = true;
299
312
  container.style.height = `${next}px`;
300
313
  lastApplied = next;
@@ -302,13 +315,14 @@ function createHeightManager(container, computeNext) {
302
315
  queueMicrotask(() => {
303
316
  suppressed = false;
304
317
  });
318
+ return next;
305
319
  }
306
320
  function scheduleApply() {
307
321
  if (debounceTimer != null) {
308
322
  clearTimeout(debounceTimer);
309
323
  debounceTimer = null;
310
324
  }
311
- if (DEBOUNCE_MS === 0) {
325
+ if (debounceMs === 0) {
312
326
  if (raf != null) return;
313
327
  raf = requestAnimationFrame(() => {
314
328
  raf = null;
@@ -323,11 +337,22 @@ function createHeightManager(container, computeNext) {
323
337
  raf = null;
324
338
  apply();
325
339
  });
326
- }, DEBOUNCE_MS);
340
+ }, debounceMs);
327
341
  }
328
342
  function update() {
329
343
  scheduleApply();
330
344
  }
345
+ function updateNow() {
346
+ if (raf != null) {
347
+ cancelAnimationFrame(raf);
348
+ raf = null;
349
+ }
350
+ if (debounceTimer != null) {
351
+ clearTimeout(debounceTimer);
352
+ debounceTimer = null;
353
+ }
354
+ return apply();
355
+ }
331
356
  function dispose() {
332
357
  if (raf != null) {
333
358
  cancelAnimationFrame(raf);
@@ -337,6 +362,10 @@ function createHeightManager(container, computeNext) {
337
362
  clearTimeout(debounceTimer);
338
363
  debounceTimer = null;
339
364
  }
365
+ if (transitionEnabled) {
366
+ const currentTransition = container.style.transition || "";
367
+ if (currentTransition.includes(heightTransition)) container.style.transition = currentTransition.replace(heightTransition, "").replace(/\s*,\s*,\s*/g, ", ").replace(/^\s*,\s*|\s*,\s*$/g, "").trim();
368
+ }
340
369
  }
341
370
  function isSuppressed() {
342
371
  return suppressed;
@@ -344,11 +373,16 @@ function createHeightManager(container, computeNext) {
344
373
  function getLastApplied() {
345
374
  return lastApplied;
346
375
  }
376
+ function getTransitionMs() {
377
+ return transitionEnabled ? transitionMs : 0;
378
+ }
347
379
  return {
348
380
  update,
381
+ updateNow,
349
382
  dispose,
350
383
  isSuppressed,
351
- getLastApplied
384
+ getLastApplied,
385
+ getTransitionMs
352
386
  };
353
387
  }
354
388
 
@@ -1439,6 +1473,7 @@ var DiffEditorManager = class DiffEditorManager {
1439
1473
  }
1440
1474
  }
1441
1475
  clearAsyncWork() {
1476
+ this.revealTicketDiff += 1;
1442
1477
  this.cancelRafs();
1443
1478
  this.pendingDiffUpdate = null;
1444
1479
  this.lastKnownModifiedDirty = false;
@@ -3423,6 +3458,7 @@ var DiffEditorManager = class DiffEditorManager {
3423
3458
  refreshDiffPresentation() {
3424
3459
  var _this$diffHideUnchang, _this$diffHeightManag;
3425
3460
  if (!this.diffEditorView) return;
3461
+ this.flushPendingDiffContentSync();
3426
3462
  const hideUnchangedRegions = this.resolveDiffHideUnchangedRegionsOption();
3427
3463
  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;
3428
3464
  const presentationOptions = this.resolveDiffPresentationEditorOptions(hideUnchangedRegions);
@@ -4975,7 +5011,6 @@ var DiffEditorManager = class DiffEditorManager {
4975
5011
  this.lastContainer.innerHTML = "";
4976
5012
  this.lastContainer = null;
4977
5013
  }
4978
- this.revealTicketDiff = 0;
4979
5014
  this.lastRevealLineDiff = null;
4980
5015
  this.diffPersistedUnchangedModelState = null;
4981
5016
  this.diffPreviousUnchangedModelState = null;
@@ -5003,7 +5038,6 @@ var DiffEditorManager = class DiffEditorManager {
5003
5038
  this.diffHeightManager.dispose();
5004
5039
  this.diffHeightManager = null;
5005
5040
  }
5006
- this.revealTicketDiff = 0;
5007
5041
  this.lastRevealLineDiff = null;
5008
5042
  this.diffPersistedUnchangedModelState = null;
5009
5043
  this.diffPreviousUnchangedModelState = null;
@@ -5079,6 +5113,12 @@ var DiffEditorManager = class DiffEditorManager {
5079
5113
  }
5080
5114
  }
5081
5115
  }
5116
+ flushPendingDiffContentSync() {
5117
+ this.rafScheduler.cancel("diff");
5118
+ this.flushPendingDiffUpdate();
5119
+ this.flushOriginalAppendBufferSync();
5120
+ this.flushModifiedAppendBufferSync();
5121
+ }
5082
5122
  flushModifiedAppendBufferSync() {
5083
5123
  if (!this.modifiedModel) return;
5084
5124
  if (this.appendBufferModifiedDiff.length === 0) return;
@@ -5276,6 +5316,12 @@ var DiffEditorManager = class DiffEditorManager {
5276
5316
 
5277
5317
  //#endregion
5278
5318
  //#region src/core/EditorManager.ts
5319
+ const defaultHeightTransitionMs = 120;
5320
+ const defaultHeightTransitionEasing = "cubic-bezier(0.4, 0, 0.2, 1)";
5321
+ const smoothHeightTolerancePx = 1;
5322
+ const legacyHeightTolerancePx = 12;
5323
+ const smoothHeightDebounceMs = 16;
5324
+ const legacyHeightDebounceMs = 0;
5279
5325
  var EditorManager = class {
5280
5326
  editorView = null;
5281
5327
  lastContainer = null;
@@ -5322,10 +5368,12 @@ var EditorManager = class {
5322
5368
  appendBufferScheduled = false;
5323
5369
  rafScheduler = createRafScheduler();
5324
5370
  editorHeightManager = null;
5371
+ previousScrollbarGutter = null;
5325
5372
  revealDebounceId = null;
5326
5373
  revealDebounceMs = defaultRevealDebounceMs;
5327
5374
  revealIdleTimerId = null;
5328
5375
  revealTicket = 0;
5376
+ layoutTicket = 0;
5329
5377
  revealStrategyOption;
5330
5378
  revealBatchOnIdleMsOption;
5331
5379
  scrollWatcherSuppressionMs = 500;
@@ -5350,6 +5398,7 @@ var EditorManager = class {
5350
5398
  this.rafScheduler.cancel("maybe-scroll");
5351
5399
  this.rafScheduler.cancel("reveal");
5352
5400
  this.rafScheduler.cancel("immediate-reveal");
5401
+ this.rafScheduler.cancel("layout-after-height");
5353
5402
  this.rafScheduler.cancel("maybe-resume");
5354
5403
  this.rafScheduler.cancel("append");
5355
5404
  }
@@ -5368,6 +5417,8 @@ var EditorManager = class {
5368
5417
  this.appendBuffer.length = 0;
5369
5418
  }
5370
5419
  clearAsyncWork() {
5420
+ this.revealTicket += 1;
5421
+ this.layoutTicket += 1;
5371
5422
  this.cancelRafs();
5372
5423
  this.pendingUpdate = null;
5373
5424
  this.lastKnownCodeDirty = false;
@@ -5412,6 +5463,37 @@ var EditorManager = class {
5412
5463
  if (!m) return false;
5413
5464
  return this._hasScrollBar = m.scrollHeight > m.computedHeight + padding / 2;
5414
5465
  }
5466
+ isSmoothHeightTransitionEnabled() {
5467
+ return this.options.smoothHeightTransition ?? false;
5468
+ }
5469
+ isAutomaticLayoutEnabled() {
5470
+ return this.options.automaticLayout !== false;
5471
+ }
5472
+ getHeightChangeTolerancePx() {
5473
+ return this.options.heightChangeTolerancePx ?? (this.isSmoothHeightTransitionEnabled() ? smoothHeightTolerancePx : legacyHeightTolerancePx);
5474
+ }
5475
+ getHeightManagerOptions() {
5476
+ const smooth = this.isSmoothHeightTransitionEnabled();
5477
+ return {
5478
+ smooth,
5479
+ transitionMs: this.options.heightTransitionMs ?? defaultHeightTransitionMs,
5480
+ transitionEasing: this.options.heightTransitionEasing ?? defaultHeightTransitionEasing,
5481
+ debounceMs: this.options.heightUpdateDebounceMs ?? (smooth ? smoothHeightDebounceMs : legacyHeightDebounceMs),
5482
+ hysteresisPx: this.getHeightChangeTolerancePx()
5483
+ };
5484
+ }
5485
+ setOverflowForHeight(computed$1) {
5486
+ if (!this.lastContainer) return null;
5487
+ const next = computed$1 >= this.maxHeightValue - 1 ? "auto" : "hidden";
5488
+ const prev = this.lastContainer.style.overflow;
5489
+ if (prev !== next) this.lastContainer.style.overflow = next;
5490
+ if (next === "hidden") this._hasScrollBar = false;
5491
+ return {
5492
+ prev,
5493
+ next,
5494
+ changed: prev !== next
5495
+ };
5496
+ }
5415
5497
  userIsNearBottom() {
5416
5498
  if (!this.editorView) return true;
5417
5499
  const m = this.measureViewport();
@@ -5546,46 +5628,89 @@ var EditorManager = class {
5546
5628
  this.lastScrollTop = ((_this$editorView4 = this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4$get = _this$editorView4.getScrollTop) === null || _this$editorView4$get === void 0 ? void 0 : _this$editorView4$get.call(_this$editorView4)) ?? this.lastScrollTop;
5547
5629
  } catch {}
5548
5630
  }
5549
- isOverflowAuto() {
5550
- try {
5551
- return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
5552
- } catch {
5553
- return false;
5554
- }
5555
- }
5556
- shouldPerformImmediateReveal() {
5557
- return this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar() && this.isOverflowAuto();
5631
+ shouldRevealAfterLayout() {
5632
+ return this.autoScrollOnUpdate && this.shouldAutoScroll;
5633
+ }
5634
+ getRevealSuppressionMs() {
5635
+ var _this$editorHeightMan, _this$editorHeightMan2;
5636
+ const transitionMs = ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 || (_this$editorHeightMan2 = _this$editorHeightMan.getTransitionMs) === null || _this$editorHeightMan2 === void 0 ? void 0 : _this$editorHeightMan2.call(_this$editorHeightMan)) ?? 0;
5637
+ return Math.max(this.scrollWatcherSuppressionMs, transitionMs + 100);
5638
+ }
5639
+ syncHeightAndRevealAfterContentChange(targetLine) {
5640
+ const shouldReveal = this.shouldRevealAfterLayout();
5641
+ const willReveal = !!(shouldReveal && this.editorView && this.computedHeight(this.editorView) >= this.maxHeightValue - 1);
5642
+ if (willReveal) this.suppressScrollWatcher(this.getRevealSuppressionMs());
5643
+ const computed$1 = this.syncNonOverflowingLayout();
5644
+ if (computed$1 != null && computed$1 >= this.maxHeightValue - 1 && shouldReveal) {
5645
+ var _this$editorView5;
5646
+ const line = targetLine ?? ((_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || (_this$editorView5 = _this$editorView5.getModel()) === null || _this$editorView5 === void 0 ? void 0 : _this$editorView5.getLineCount()) ?? 1;
5647
+ if (this.isSmoothHeightTransitionEnabled()) this.scheduleImmediateRevealAfterLayout(line);
5648
+ else this.forceReveal(line);
5649
+ } else if (!shouldReveal && targetLine != null) this.maybeScrollToBottom(targetLine);
5650
+ return computed$1;
5558
5651
  }
5559
5652
  syncNonOverflowingLayout() {
5560
- var _this$lastContainer$g, _this$lastContainer;
5653
+ var _this$editorHeightMan3, _this$editorHeightMan4;
5561
5654
  if (!this.editorView || !this.lastContainer) return null;
5562
5655
  const computed$1 = this.computedHeight(this.editorView);
5656
+ const needsRevealSync = computed$1 >= this.maxHeightValue - 1 && this.shouldRevealAfterLayout();
5657
+ const useSmoothHeightTransition = this.isSmoothHeightTransitionEnabled();
5658
+ if (needsRevealSync || !useSmoothHeightTransition) (_this$editorHeightMan3 = this.editorHeightManager) === null || _this$editorHeightMan3 === void 0 || _this$editorHeightMan3.updateNow();
5659
+ else (_this$editorHeightMan4 = this.editorHeightManager) === null || _this$editorHeightMan4 === void 0 || _this$editorHeightMan4.update();
5660
+ this.setOverflowForHeight(computed$1);
5563
5661
  if (computed$1 >= this.maxHeightValue - 1) {
5564
- this.lastContainer.style.height = `${this.maxHeightValue}px`;
5662
+ if (useSmoothHeightTransition) this.scheduleLayoutAfterHeightApplied(computed$1);
5565
5663
  return computed$1;
5566
5664
  }
5567
- const currentHeight = Number.parseFloat(this.lastContainer.style.height || "") || ((_this$lastContainer$g = (_this$lastContainer = this.lastContainer).getBoundingClientRect) === null || _this$lastContainer$g === void 0 ? void 0 : _this$lastContainer$g.call(_this$lastContainer).height) || 0;
5568
- if (currentHeight <= 0 || Math.abs(computed$1 - currentHeight) > 12) this.lastContainer.style.height = `${computed$1}px`;
5569
- this.lastContainer.style.overflow = "hidden";
5570
5665
  this._hasScrollBar = false;
5666
+ if (useSmoothHeightTransition) {
5667
+ this.scheduleLayoutAfterHeightApplied(computed$1);
5668
+ try {
5669
+ var _this$editorView$getS3, _this$editorView6, _this$editorView$setS, _this$editorView7;
5670
+ if ((((_this$editorView$getS3 = (_this$editorView6 = this.editorView).getScrollTop) === null || _this$editorView$getS3 === void 0 ? void 0 : _this$editorView$getS3.call(_this$editorView6)) ?? 0) !== 0) (_this$editorView$setS = (_this$editorView7 = this.editorView).setScrollTop) === null || _this$editorView$setS === void 0 || _this$editorView$setS.call(_this$editorView7, 0);
5671
+ this.lastScrollTop = 0;
5672
+ } catch {}
5673
+ return computed$1;
5674
+ }
5571
5675
  try {
5572
- var _this$editorView$layo, _this$editorView5;
5573
- (_this$editorView$layo = (_this$editorView5 = this.editorView).layout) === null || _this$editorView$layo === void 0 || _this$editorView$layo.call(_this$editorView5);
5676
+ var _this$editorView$layo, _this$editorView8;
5677
+ (_this$editorView$layo = (_this$editorView8 = this.editorView).layout) === null || _this$editorView$layo === void 0 || _this$editorView$layo.call(_this$editorView8);
5574
5678
  } catch {}
5575
5679
  try {
5576
- var _this$editorView$getS3, _this$editorView6, _this$editorView$setS, _this$editorView7;
5577
- if ((((_this$editorView$getS3 = (_this$editorView6 = this.editorView).getScrollTop) === null || _this$editorView$getS3 === void 0 ? void 0 : _this$editorView$getS3.call(_this$editorView6)) ?? 0) !== 0) (_this$editorView$setS = (_this$editorView7 = this.editorView).setScrollTop) === null || _this$editorView$setS === void 0 || _this$editorView$setS.call(_this$editorView7, 0);
5680
+ var _this$editorView$getS4, _this$editorView9, _this$editorView$setS2, _this$editorView10;
5681
+ if ((((_this$editorView$getS4 = (_this$editorView9 = this.editorView).getScrollTop) === null || _this$editorView$getS4 === void 0 ? void 0 : _this$editorView$getS4.call(_this$editorView9)) ?? 0) !== 0) (_this$editorView$setS2 = (_this$editorView10 = this.editorView).setScrollTop) === null || _this$editorView$setS2 === void 0 || _this$editorView$setS2.call(_this$editorView10, 0);
5578
5682
  this.lastScrollTop = 0;
5579
5683
  } catch {}
5580
5684
  return computed$1;
5581
5685
  }
5686
+ scheduleLayoutAfterHeightApplied(target) {
5687
+ if (this.isAutomaticLayoutEnabled() || !this.editorView) return;
5688
+ const editor = this.editorView;
5689
+ const ticket = ++this.layoutTicket;
5690
+ this.rafScheduler.schedule("layout-after-height", async () => {
5691
+ try {
5692
+ var _editor$layout;
5693
+ await this.waitForHeightApplied(target, 500);
5694
+ if (ticket !== this.layoutTicket || this.editorView !== editor) return;
5695
+ (_editor$layout = editor.layout) === null || _editor$layout === void 0 || _editor$layout.call(editor);
5696
+ this.measureViewport();
5697
+ } catch (err) {
5698
+ error("EditorManager", "scheduleLayoutAfterHeightApplied error", err);
5699
+ }
5700
+ });
5701
+ }
5582
5702
  async createEditor(container, code, language, currentTheme) {
5583
- var _this$editorView$getS4, _this$editorView8, _this$editorView$getO, _this$editorView9, _this$editorView$getM, _this$editorView$onDi, _this$editorView10;
5703
+ var _this$editorView$getS5, _this$editorView11, _this$editorView$getO, _this$editorView12, _this$editorView$getM, _this$editorView$onDi, _this$editorView13;
5584
5704
  this.cleanup();
5585
5705
  this.lastContainer = container;
5586
5706
  this.initDebugFlag();
5587
5707
  this.dlog("createEditor container, maxHeight", this.maxHeightValue);
5588
5708
  container.style.overflow = "hidden";
5709
+ this.previousScrollbarGutter = null;
5710
+ if (this.isSmoothHeightTransitionEnabled()) {
5711
+ this.previousScrollbarGutter = container.style.scrollbarGutter || "";
5712
+ container.style.scrollbarGutter = "stable";
5713
+ }
5589
5714
  container.style.maxHeight = this.maxHeightCSS;
5590
5715
  this.editorView = monaco_shim_exports.editor.create(container, {
5591
5716
  value: code,
@@ -5619,43 +5744,29 @@ var EditorManager = class {
5619
5744
  this.editorHeightManager = createHeightManager(container, () => {
5620
5745
  const computed$1 = this.computedHeight(this.editorView);
5621
5746
  return Math.min(computed$1, this.maxHeightValue);
5622
- });
5623
- this.editorHeightManager.update();
5624
- const initialComputed = this.computedHeight(this.editorView);
5625
- if (initialComputed >= this.maxHeightValue - 1) {
5626
- container.style.height = `${this.maxHeightValue}px`;
5627
- container.style.overflow = "auto";
5628
- this.dlog("applied immediate maxHeight on createEditor", this.maxHeightValue);
5629
- }
5630
- this.cachedScrollHeight = ((_this$editorView$getS4 = (_this$editorView8 = this.editorView).getScrollHeight) === null || _this$editorView$getS4 === void 0 ? void 0 : _this$editorView$getS4.call(_this$editorView8)) ?? null;
5631
- this.cachedLineHeight = ((_this$editorView$getO = (_this$editorView9 = this.editorView).getOption) === null || _this$editorView$getO === void 0 ? void 0 : _this$editorView$getO.call(_this$editorView9, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
5747
+ }, this.getHeightManagerOptions());
5748
+ const initialComputed = this.editorHeightManager.updateNow();
5749
+ if (initialComputed != null) this.setOverflowForHeight(initialComputed);
5750
+ this.cachedScrollHeight = ((_this$editorView$getS5 = (_this$editorView11 = this.editorView).getScrollHeight) === null || _this$editorView$getS5 === void 0 ? void 0 : _this$editorView$getS5.call(_this$editorView11)) ?? null;
5751
+ this.cachedLineHeight = ((_this$editorView$getO = (_this$editorView12 = this.editorView).getOption) === null || _this$editorView$getO === void 0 ? void 0 : _this$editorView$getO.call(_this$editorView12, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
5632
5752
  this.cachedComputedHeight = this.computedHeight(this.editorView);
5633
5753
  this.cachedLineCount = ((_this$editorView$getM = this.editorView.getModel()) === null || _this$editorView$getM === void 0 ? void 0 : _this$editorView$getM.getLineCount()) ?? null;
5634
- (_this$editorView$onDi = (_this$editorView10 = this.editorView).onDidContentSizeChange) === null || _this$editorView$onDi === void 0 || _this$editorView$onDi.call(_this$editorView10, () => {
5754
+ (_this$editorView$onDi = (_this$editorView13 = this.editorView).onDidContentSizeChange) === null || _this$editorView$onDi === void 0 || _this$editorView$onDi.call(_this$editorView13, () => {
5635
5755
  this._hasScrollBar = false;
5636
5756
  this.rafScheduler.schedule("content-size-change", () => {
5637
5757
  try {
5638
- var _this$editorView11, _this$editorHeightMan, _this$editorHeightMan2;
5758
+ var _this$editorView14, _this$editorHeightMan5;
5639
5759
  this.dlog("content-size-change frame");
5640
- this.cachedLineCount = ((_this$editorView11 = this.editorView) === null || _this$editorView11 === void 0 || (_this$editorView11 = _this$editorView11.getModel()) === null || _this$editorView11 === void 0 ? void 0 : _this$editorView11.getLineCount()) ?? this.cachedLineCount;
5760
+ this.cachedLineCount = ((_this$editorView14 = this.editorView) === null || _this$editorView14 === void 0 || (_this$editorView14 = _this$editorView14.getModel()) === null || _this$editorView14 === void 0 ? void 0 : _this$editorView14.getLineCount()) ?? this.cachedLineCount;
5641
5761
  this.cachedComputedHeight = null;
5642
5762
  const m = this.measureViewport();
5643
5763
  this.dlog("content-size-change measure", m);
5644
- if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
5764
+ if ((_this$editorHeightMan5 = this.editorHeightManager) === null || _this$editorHeightMan5 === void 0 ? void 0 : _this$editorHeightMan5.isSuppressed()) {
5645
5765
  this.dlog("content-size-change skipped height update (suppressed)");
5646
5766
  return;
5647
5767
  }
5648
- this.dlog("content-size-change calling heightManager.update");
5649
- (_this$editorHeightMan2 = this.editorHeightManager) === null || _this$editorHeightMan2 === void 0 || _this$editorHeightMan2.update();
5650
- const computed$1 = this.computedHeight(this.editorView);
5651
- if (this.lastContainer) {
5652
- const prevOverflow = this.lastContainer.style.overflow;
5653
- const newOverflow = computed$1 >= this.maxHeightValue - 1 ? "auto" : "hidden";
5654
- if (prevOverflow !== newOverflow) {
5655
- this.lastContainer.style.overflow = newOverflow;
5656
- if (newOverflow === "auto" && this.shouldAutoScroll) this.maybeScrollToBottom();
5657
- }
5658
- }
5768
+ this.dlog("content-size-change syncing height/reveal");
5769
+ this.syncHeightAndRevealAfterContentChange();
5659
5770
  } catch (err) {
5660
5771
  error("EditorManager", "content-size-change error", err);
5661
5772
  }
@@ -5723,6 +5834,11 @@ var EditorManager = class {
5723
5834
  if (target !== -1 && this.editorHeightManager) await this.waitForHeightApplied(target, 500);
5724
5835
  else await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r())));
5725
5836
  this.dlog("running delayed immediate reveal", "ticket=", ticket, "line=", line);
5837
+ if (ticket !== this.revealTicket) {
5838
+ this.dlog("delayed immediate reveal skipped, stale ticket", ticket, "current", this.revealTicket);
5839
+ return;
5840
+ }
5841
+ this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5726
5842
  this.performImmediateReveal(line, ticket);
5727
5843
  } catch (err) {
5728
5844
  error("EditorManager", "scheduleImmediateRevealAfterLayout error", err);
@@ -5731,20 +5847,33 @@ var EditorManager = class {
5731
5847
  }
5732
5848
  waitForHeightApplied(target, timeoutMs = 500) {
5733
5849
  return new Promise((resolve) => {
5850
+ var _this$editorHeightMan6, _this$editorHeightMan7;
5734
5851
  const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
5852
+ const tolerance = this.getHeightChangeTolerancePx();
5853
+ const transitionMs = ((_this$editorHeightMan6 = this.editorHeightManager) === null || _this$editorHeightMan6 === void 0 || (_this$editorHeightMan7 = _this$editorHeightMan6.getTransitionMs) === null || _this$editorHeightMan7 === void 0 ? void 0 : _this$editorHeightMan7.call(_this$editorHeightMan6)) ?? 0;
5854
+ let settled = false;
5855
+ const resolveAfterSettle = () => {
5856
+ if (settled) return;
5857
+ settled = true;
5858
+ if (transitionMs > 0) {
5859
+ setTimeout(resolve, transitionMs);
5860
+ return;
5861
+ }
5862
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
5863
+ };
5735
5864
  const check = () => {
5736
5865
  try {
5737
- var _this$editorHeightMan3, _this$editorHeightMan4;
5738
- const last = ((_this$editorHeightMan3 = this.editorHeightManager) === null || _this$editorHeightMan3 === void 0 || (_this$editorHeightMan4 = _this$editorHeightMan3.getLastApplied) === null || _this$editorHeightMan4 === void 0 ? void 0 : _this$editorHeightMan4.call(_this$editorHeightMan3)) ?? -1;
5739
- if (last !== -1 && Math.abs(last - target) <= 12) {
5866
+ var _this$editorHeightMan8, _this$editorHeightMan9;
5867
+ const last = ((_this$editorHeightMan8 = this.editorHeightManager) === null || _this$editorHeightMan8 === void 0 || (_this$editorHeightMan9 = _this$editorHeightMan8.getLastApplied) === null || _this$editorHeightMan9 === void 0 ? void 0 : _this$editorHeightMan9.call(_this$editorHeightMan8)) ?? -1;
5868
+ if (last !== -1 && Math.abs(last - target) <= tolerance) {
5740
5869
  this.dlog("waitForHeightApplied satisfied", last, "target=", target);
5741
- resolve();
5870
+ resolveAfterSettle();
5742
5871
  return;
5743
5872
  }
5744
5873
  const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
5745
5874
  if (now - start > timeoutMs) {
5746
5875
  log("EditorManager", "waitForHeightApplied timeout", last, "target=", target);
5747
- resolve();
5876
+ resolveAfterSettle();
5748
5877
  return;
5749
5878
  }
5750
5879
  } catch {}
@@ -5796,12 +5925,7 @@ var EditorManager = class {
5796
5925
  const newLineCount$1 = model.getLineCount();
5797
5926
  this.cachedLineCount = newLineCount$1;
5798
5927
  this.cachedComputedHeight = null;
5799
- if (newLineCount$1 !== prevLineCount$1) {
5800
- const shouldImmediate = this.shouldPerformImmediateReveal();
5801
- if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5802
- const computed$1 = this.syncNonOverflowingLayout();
5803
- if (computed$1 != null && computed$1 >= this.maxHeightValue - 1) this.forceReveal(newLineCount$1);
5804
- }
5928
+ if (newLineCount$1 !== prevLineCount$1) this.syncHeightAndRevealAfterContentChange(newLineCount$1);
5805
5929
  return;
5806
5930
  }
5807
5931
  let prevCode;
@@ -5831,13 +5955,7 @@ var EditorManager = class {
5831
5955
  const newLineCount = model.getLineCount();
5832
5956
  this.cachedLineCount = newLineCount;
5833
5957
  this.cachedComputedHeight = null;
5834
- if (newLineCount !== prevLineCount) {
5835
- const shouldImmediate = this.shouldPerformImmediateReveal();
5836
- if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5837
- this.syncNonOverflowingLayout();
5838
- if (shouldImmediate) this.scheduleImmediateRevealAfterLayout(newLineCount);
5839
- else this.maybeScrollToBottom(newLineCount);
5840
- }
5958
+ if (newLineCount !== prevLineCount) this.syncHeightAndRevealAfterContentChange(newLineCount);
5841
5959
  }
5842
5960
  appendCode(appendText, codeLanguage) {
5843
5961
  if (!this.editorView) return;
@@ -5869,10 +5987,7 @@ var EditorManager = class {
5869
5987
  this.lastKnownCode = next;
5870
5988
  const newLineCount = model.getLineCount();
5871
5989
  this.cachedLineCount = newLineCount;
5872
- if (newLineCount !== prevLineCount) {
5873
- this.syncNonOverflowingLayout();
5874
- this.maybeScrollToBottom(newLineCount);
5875
- }
5990
+ if (newLineCount !== prevLineCount) this.syncHeightAndRevealAfterContentChange(newLineCount);
5876
5991
  return;
5877
5992
  }
5878
5993
  const res = computeMinimalEdit(prev, next);
@@ -5925,13 +6040,7 @@ var EditorManager = class {
5925
6040
  if (lastLine !== newLineCount) {
5926
6041
  this.cachedLineCount = newLineCount;
5927
6042
  this.cachedComputedHeight = null;
5928
- const shouldImmediate = this.shouldPerformImmediateReveal();
5929
- if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
5930
- this.syncNonOverflowingLayout();
5931
- if (shouldImmediate) try {
5932
- this.forceReveal(newLineCount);
5933
- } catch {}
5934
- else this.maybeScrollToBottom(newLineCount);
6043
+ this.syncHeightAndRevealAfterContentChange(newLineCount);
5935
6044
  }
5936
6045
  }
5937
6046
  setLanguage(language, languages$1) {
@@ -5946,8 +6055,8 @@ var EditorManager = class {
5946
6055
  return this.editorView;
5947
6056
  }
5948
6057
  getCode() {
5949
- var _this$editorView12;
5950
- return ((_this$editorView12 = this.editorView) === null || _this$editorView12 === void 0 || (_this$editorView12 = _this$editorView12.getModel()) === null || _this$editorView12 === void 0 ? void 0 : _this$editorView12.getValue()) ?? null;
6058
+ var _this$editorView15;
6059
+ return ((_this$editorView15 = this.editorView) === null || _this$editorView15 === void 0 || (_this$editorView15 = _this$editorView15.getModel()) === null || _this$editorView15 === void 0 ? void 0 : _this$editorView15.getValue()) ?? null;
5951
6060
  }
5952
6061
  setUpdateThrottleMs(ms) {
5953
6062
  this.updateThrottleMs = ms;
@@ -5968,6 +6077,8 @@ var EditorManager = class {
5968
6077
  }
5969
6078
  this.lastKnownCode = null;
5970
6079
  if (this.lastContainer) {
6080
+ if (this.previousScrollbarGutter != null) this.lastContainer.style.scrollbarGutter = this.previousScrollbarGutter;
6081
+ this.previousScrollbarGutter = null;
5971
6082
  this.lastContainer.style.minHeight = "";
5972
6083
  this.lastContainer.innerHTML = "";
5973
6084
  this.lastContainer = null;
@@ -5992,6 +6103,8 @@ var EditorManager = class {
5992
6103
  this._hasScrollBar = false;
5993
6104
  this.shouldAutoScroll = !!this.autoScrollInitial;
5994
6105
  this.lastScrollTop = 0;
6106
+ if (this.lastContainer && this.previousScrollbarGutter != null) this.lastContainer.style.scrollbarGutter = this.previousScrollbarGutter;
6107
+ this.previousScrollbarGutter = null;
5995
6108
  if (this.editorHeightManager) {
5996
6109
  this.editorHeightManager.dispose();
5997
6110
  this.editorHeightManager = null;
@@ -6298,7 +6411,7 @@ let globalAppliedThemeName = null;
6298
6411
  * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
6299
6412
  * @param {string} [monacoOptions.theme] - 初始主题名称
6300
6413
  * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
6301
- * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
6414
+ * @param {(monaco: typeof import('monaco-editor/esm/vs/editor/editor.api')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
6302
6415
  *
6303
6416
  * @returns {{
6304
6417
  * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,