@codemirror/view 6.39.9 → 6.39.10

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 6.39.10 (2026-01-13)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a regression in the way widget are reused when content next to them changes.
6
+
7
+ Make sure font metrics get recomputed on `fonts.ready` even if the line height doesn't change.
8
+
9
+ Fix an issue where compositions next to a widget that create a new text node could get needlessly interrupted during an editor update.
10
+
1
11
  ## 6.39.9 (2026-01-06)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2502,8 +2502,6 @@ class TileCache {
2502
2502
  }
2503
2503
  // Put a tile in the cache.
2504
2504
  add(tile) {
2505
- if (tile.demo)
2506
- console.log("Add widget to cache");
2507
2505
  let i = tile.constructor.bucket, bucket = this.buckets[i];
2508
2506
  if (bucket.length < 6 /* C.Bucket */)
2509
2507
  bucket.push(tile);
@@ -2528,8 +2526,6 @@ class TileCache {
2528
2526
  }
2529
2527
  findWidget(widget, length, flags) {
2530
2528
  let widgets = this.buckets[0];
2531
- if (widget.demo)
2532
- console.log("looking for widget", widget, "in cache", widgets.slice());
2533
2529
  if (widgets.length)
2534
2530
  for (let i = 0, pass = 0;; i++) {
2535
2531
  if (i == widgets.length) {
@@ -2545,7 +2541,7 @@ class TileCache {
2545
2541
  widgets.splice(i, 1);
2546
2542
  if (i < this.index[0])
2547
2543
  this.index[0]--;
2548
- if (tile.length == length && (tile.flags & (496 /* TileFlag.Widget */ | 1 /* TileFlag.BreakAfter */)) == flags) {
2544
+ if (tile.widget == widget && tile.length == length && (tile.flags & (496 /* TileFlag.Widget */ | 1 /* TileFlag.BreakAfter */)) == flags) {
2549
2545
  this.reused.set(tile, 1 /* Reused.Full */);
2550
2546
  return tile;
2551
2547
  }
@@ -2616,7 +2612,7 @@ class TileUpdate {
2616
2612
  // focused text node and its parent nodes to remain stable at
2617
2613
  // that point in the document.
2618
2614
  if (composition && next.fromA <= composition.range.fromA && next.toA >= composition.range.toA) {
2619
- this.forward(next.fromA, composition.range.fromA);
2615
+ this.forward(next.fromA, composition.range.fromA, composition.range.fromA < composition.range.toA ? 1 : -1);
2620
2616
  this.emit(posB, composition.range.fromB);
2621
2617
  this.cache.clear(); // Must not reuse DOM across composition
2622
2618
  this.builder.addComposition(composition, compositionContext);
@@ -2775,14 +2771,14 @@ class TileUpdate {
2775
2771
  this.openWidget = openEnd > markCount;
2776
2772
  this.openMarks = openEnd;
2777
2773
  }
2778
- forward(from, to) {
2774
+ forward(from, to, side = 1) {
2779
2775
  if (to - from <= 10) {
2780
- this.old.advance(to - from, 1, this.reuseWalker);
2776
+ this.old.advance(to - from, side, this.reuseWalker);
2781
2777
  }
2782
2778
  else {
2783
2779
  this.old.advance(5, -1, this.reuseWalker);
2784
2780
  this.old.advance(to - from - 10, -1);
2785
- this.old.advance(5, 1, this.reuseWalker);
2781
+ this.old.advance(5, side, this.reuseWalker);
2786
2782
  }
2787
2783
  }
2788
2784
  getCompositionContext(text) {
@@ -5204,7 +5200,8 @@ class HeightOracle {
5204
5200
  }
5205
5201
  refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) {
5206
5202
  let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1;
5207
- let changed = Math.round(lineHeight) != Math.round(this.lineHeight) || this.lineWrapping != lineWrapping;
5203
+ let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping ||
5204
+ Math.abs(charWidth - this.charWidth) > 0.1;
5208
5205
  this.lineWrapping = lineWrapping;
5209
5206
  this.lineHeight = lineHeight;
5210
5207
  this.charWidth = charWidth;
@@ -6118,7 +6115,7 @@ class ViewState {
6118
6115
  let oracle = this.heightOracle;
6119
6116
  let whiteSpace = style.whiteSpace;
6120
6117
  this.defaultTextDirection = style.direction == "rtl" ? exports.Direction.RTL : exports.Direction.LTR;
6121
- let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace);
6118
+ let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace) || this.mustMeasureContent;
6122
6119
  let domRect = dom.getBoundingClientRect();
6123
6120
  let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != domRect.height;
6124
6121
  this.contentDOMHeight = domRect.height;
@@ -7694,7 +7691,10 @@ class EditorView {
7694
7691
  this.updateState = 0 /* UpdateState.Idle */;
7695
7692
  this.requestMeasure();
7696
7693
  if ((_a = document.fonts) === null || _a === void 0 ? void 0 : _a.ready)
7697
- document.fonts.ready.then(() => this.requestMeasure());
7694
+ document.fonts.ready.then(() => {
7695
+ this.viewState.mustMeasureContent = true;
7696
+ this.requestMeasure();
7697
+ });
7698
7698
  }
7699
7699
  dispatch(...input) {
7700
7700
  let trs = input.length == 1 && input[0] instanceof state.Transaction ? input
package/dist/index.js CHANGED
@@ -2498,8 +2498,6 @@ class TileCache {
2498
2498
  }
2499
2499
  // Put a tile in the cache.
2500
2500
  add(tile) {
2501
- if (tile.demo)
2502
- console.log("Add widget to cache");
2503
2501
  let i = tile.constructor.bucket, bucket = this.buckets[i];
2504
2502
  if (bucket.length < 6 /* C.Bucket */)
2505
2503
  bucket.push(tile);
@@ -2524,8 +2522,6 @@ class TileCache {
2524
2522
  }
2525
2523
  findWidget(widget, length, flags) {
2526
2524
  let widgets = this.buckets[0];
2527
- if (widget.demo)
2528
- console.log("looking for widget", widget, "in cache", widgets.slice());
2529
2525
  if (widgets.length)
2530
2526
  for (let i = 0, pass = 0;; i++) {
2531
2527
  if (i == widgets.length) {
@@ -2541,7 +2537,7 @@ class TileCache {
2541
2537
  widgets.splice(i, 1);
2542
2538
  if (i < this.index[0])
2543
2539
  this.index[0]--;
2544
- if (tile.length == length && (tile.flags & (496 /* TileFlag.Widget */ | 1 /* TileFlag.BreakAfter */)) == flags) {
2540
+ if (tile.widget == widget && tile.length == length && (tile.flags & (496 /* TileFlag.Widget */ | 1 /* TileFlag.BreakAfter */)) == flags) {
2545
2541
  this.reused.set(tile, 1 /* Reused.Full */);
2546
2542
  return tile;
2547
2543
  }
@@ -2612,7 +2608,7 @@ class TileUpdate {
2612
2608
  // focused text node and its parent nodes to remain stable at
2613
2609
  // that point in the document.
2614
2610
  if (composition && next.fromA <= composition.range.fromA && next.toA >= composition.range.toA) {
2615
- this.forward(next.fromA, composition.range.fromA);
2611
+ this.forward(next.fromA, composition.range.fromA, composition.range.fromA < composition.range.toA ? 1 : -1);
2616
2612
  this.emit(posB, composition.range.fromB);
2617
2613
  this.cache.clear(); // Must not reuse DOM across composition
2618
2614
  this.builder.addComposition(composition, compositionContext);
@@ -2771,14 +2767,14 @@ class TileUpdate {
2771
2767
  this.openWidget = openEnd > markCount;
2772
2768
  this.openMarks = openEnd;
2773
2769
  }
2774
- forward(from, to) {
2770
+ forward(from, to, side = 1) {
2775
2771
  if (to - from <= 10) {
2776
- this.old.advance(to - from, 1, this.reuseWalker);
2772
+ this.old.advance(to - from, side, this.reuseWalker);
2777
2773
  }
2778
2774
  else {
2779
2775
  this.old.advance(5, -1, this.reuseWalker);
2780
2776
  this.old.advance(to - from - 10, -1);
2781
- this.old.advance(5, 1, this.reuseWalker);
2777
+ this.old.advance(5, side, this.reuseWalker);
2782
2778
  }
2783
2779
  }
2784
2780
  getCompositionContext(text) {
@@ -5200,7 +5196,8 @@ class HeightOracle {
5200
5196
  }
5201
5197
  refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) {
5202
5198
  let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1;
5203
- let changed = Math.round(lineHeight) != Math.round(this.lineHeight) || this.lineWrapping != lineWrapping;
5199
+ let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping ||
5200
+ Math.abs(charWidth - this.charWidth) > 0.1;
5204
5201
  this.lineWrapping = lineWrapping;
5205
5202
  this.lineHeight = lineHeight;
5206
5203
  this.charWidth = charWidth;
@@ -6113,7 +6110,7 @@ class ViewState {
6113
6110
  let oracle = this.heightOracle;
6114
6111
  let whiteSpace = style.whiteSpace;
6115
6112
  this.defaultTextDirection = style.direction == "rtl" ? Direction.RTL : Direction.LTR;
6116
- let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace);
6113
+ let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace) || this.mustMeasureContent;
6117
6114
  let domRect = dom.getBoundingClientRect();
6118
6115
  let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != domRect.height;
6119
6116
  this.contentDOMHeight = domRect.height;
@@ -7689,7 +7686,10 @@ class EditorView {
7689
7686
  this.updateState = 0 /* UpdateState.Idle */;
7690
7687
  this.requestMeasure();
7691
7688
  if ((_a = document.fonts) === null || _a === void 0 ? void 0 : _a.ready)
7692
- document.fonts.ready.then(() => this.requestMeasure());
7689
+ document.fonts.ready.then(() => {
7690
+ this.viewState.mustMeasureContent = true;
7691
+ this.requestMeasure();
7692
+ });
7693
7693
  }
7694
7694
  dispatch(...input) {
7695
7695
  let trs = input.length == 1 && input[0] instanceof Transaction ? input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.39.9",
3
+ "version": "6.39.10",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",