@codemirror/view 6.42.0 → 6.43.0

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,17 @@
1
+ ## 6.43.0 (2026-05-14)
2
+
3
+ ### New features
4
+
5
+ Block wrappers can now be given a rank to set a specific nesting order for wrappers coming from the same source.
6
+
7
+ ## 6.42.1 (2026-05-07)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix a bug where block wrappers could be applied incorrectly during composition.
12
+
13
+ Fix an issue leading to constant text geometry resets in variable-width fonts.
14
+
1
15
  ## 6.42.0 (2026-05-06)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -395,10 +395,23 @@ widget that starts inside its range, including blocks starting
395
395
  directly at `from` but not including `to`.
396
396
  */
397
397
  class BlockWrapper extends state.RangeValue {
398
- constructor(tagName, attributes) {
398
+ constructor(
399
+ /**
400
+ @internal
401
+ */
402
+ tagName,
403
+ /**
404
+ @internal
405
+ */
406
+ attributes,
407
+ /**
408
+ @internal
409
+ */
410
+ rank) {
399
411
  super();
400
412
  this.tagName = tagName;
401
413
  this.attributes = attributes;
414
+ this.rank = rank;
402
415
  }
403
416
  eq(other) {
404
417
  return other == this ||
@@ -409,7 +422,7 @@ class BlockWrapper extends state.RangeValue {
409
422
  attributes.
410
423
  */
411
424
  static create(spec) {
412
- return new BlockWrapper(spec.tagName, spec.attributes || noAttrs);
425
+ return new BlockWrapper(spec.tagName, spec.attributes || noAttrs, spec.rank == null ? 50 : Math.max(0, Math.min(spec.rank, 100)));
413
426
  }
414
427
  /**
415
428
  Create a range set from the given block wrapper ranges.
@@ -2311,6 +2324,7 @@ class TileBuilder {
2311
2324
  this.cache.reused.set(oldTile, 2 /* Reused.DOM */);
2312
2325
  let text = new TextTile(composition.text, composition.text.nodeValue);
2313
2326
  text.flags |= 8 /* TileFlag.Composition */;
2327
+ this.pos = composition.range.toB;
2314
2328
  head.append(text);
2315
2329
  }
2316
2330
  addInlineWidget(widget, marks, openStart) {
@@ -2409,7 +2423,8 @@ class TileBuilder {
2409
2423
  this.wrappers.splice(i, 1);
2410
2424
  for (let cur = this.blockWrappers; cur.value && cur.from <= this.pos; cur.next())
2411
2425
  if (cur.to >= this.pos) {
2412
- let wrap = new OpenWrapper(cur.from, cur.to, cur.value, cur.rank), i = this.wrappers.length;
2426
+ let rank = (cur.rank * 102) + cur.value.rank;
2427
+ let wrap = new OpenWrapper(cur.from, cur.to, cur.value, rank), i = this.wrappers.length;
2413
2428
  while (i > 0 && (this.wrappers[i - 1].rank - wrap.rank || this.wrappers[i - 1].to - wrap.to) < 0)
2414
2429
  i--;
2415
2430
  this.wrappers.splice(i, 0, wrap);
@@ -5345,8 +5360,7 @@ class HeightOracle {
5345
5360
  }
5346
5361
  refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) {
5347
5362
  let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1;
5348
- let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping ||
5349
- Math.abs(charWidth - this.charWidth) > 0.1;
5363
+ let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping;
5350
5364
  this.lineWrapping = lineWrapping;
5351
5365
  this.lineHeight = lineHeight;
5352
5366
  this.charWidth = charWidth;
package/dist/index.d.cts CHANGED
@@ -366,6 +366,13 @@ interface BlockWrapperSpec {
366
366
  attributes?: {
367
367
  [key: string]: string;
368
368
  };
369
+ /**
370
+ When multiple overlapping block wrappers are produced by the
371
+ same source, this determines their relative precedence. Lower
372
+ rank wrappers are nested inside higher-rank ones. Should be
373
+ a number between 0 and 100.
374
+ */
375
+ rank?: number;
369
376
  }
370
377
  /**
371
378
  A block wrapper defines a DOM node that wraps lines or other block
@@ -374,8 +381,6 @@ widget that starts inside its range, including blocks starting
374
381
  directly at `from` but not including `to`.
375
382
  */
376
383
  declare class BlockWrapper extends RangeValue {
377
- readonly tagName: string;
378
- readonly attributes: Attrs;
379
384
  private constructor();
380
385
  eq(other: RangeValue): boolean;
381
386
  /**
package/dist/index.d.ts CHANGED
@@ -366,6 +366,13 @@ interface BlockWrapperSpec {
366
366
  attributes?: {
367
367
  [key: string]: string;
368
368
  };
369
+ /**
370
+ When multiple overlapping block wrappers are produced by the
371
+ same source, this determines their relative precedence. Lower
372
+ rank wrappers are nested inside higher-rank ones. Should be
373
+ a number between 0 and 100.
374
+ */
375
+ rank?: number;
369
376
  }
370
377
  /**
371
378
  A block wrapper defines a DOM node that wraps lines or other block
@@ -374,8 +381,6 @@ widget that starts inside its range, including blocks starting
374
381
  directly at `from` but not including `to`.
375
382
  */
376
383
  declare class BlockWrapper extends RangeValue {
377
- readonly tagName: string;
378
- readonly attributes: Attrs;
379
384
  private constructor();
380
385
  eq(other: RangeValue): boolean;
381
386
  /**
package/dist/index.js CHANGED
@@ -392,10 +392,23 @@ widget that starts inside its range, including blocks starting
392
392
  directly at `from` but not including `to`.
393
393
  */
394
394
  class BlockWrapper extends RangeValue {
395
- constructor(tagName, attributes) {
395
+ constructor(
396
+ /**
397
+ @internal
398
+ */
399
+ tagName,
400
+ /**
401
+ @internal
402
+ */
403
+ attributes,
404
+ /**
405
+ @internal
406
+ */
407
+ rank) {
396
408
  super();
397
409
  this.tagName = tagName;
398
410
  this.attributes = attributes;
411
+ this.rank = rank;
399
412
  }
400
413
  eq(other) {
401
414
  return other == this ||
@@ -406,7 +419,7 @@ class BlockWrapper extends RangeValue {
406
419
  attributes.
407
420
  */
408
421
  static create(spec) {
409
- return new BlockWrapper(spec.tagName, spec.attributes || noAttrs);
422
+ return new BlockWrapper(spec.tagName, spec.attributes || noAttrs, spec.rank == null ? 50 : Math.max(0, Math.min(spec.rank, 100)));
410
423
  }
411
424
  /**
412
425
  Create a range set from the given block wrapper ranges.
@@ -2307,6 +2320,7 @@ class TileBuilder {
2307
2320
  this.cache.reused.set(oldTile, 2 /* Reused.DOM */);
2308
2321
  let text = new TextTile(composition.text, composition.text.nodeValue);
2309
2322
  text.flags |= 8 /* TileFlag.Composition */;
2323
+ this.pos = composition.range.toB;
2310
2324
  head.append(text);
2311
2325
  }
2312
2326
  addInlineWidget(widget, marks, openStart) {
@@ -2405,7 +2419,8 @@ class TileBuilder {
2405
2419
  this.wrappers.splice(i, 1);
2406
2420
  for (let cur = this.blockWrappers; cur.value && cur.from <= this.pos; cur.next())
2407
2421
  if (cur.to >= this.pos) {
2408
- let wrap = new OpenWrapper(cur.from, cur.to, cur.value, cur.rank), i = this.wrappers.length;
2422
+ let rank = (cur.rank * 102) + cur.value.rank;
2423
+ let wrap = new OpenWrapper(cur.from, cur.to, cur.value, rank), i = this.wrappers.length;
2409
2424
  while (i > 0 && (this.wrappers[i - 1].rank - wrap.rank || this.wrappers[i - 1].to - wrap.to) < 0)
2410
2425
  i--;
2411
2426
  this.wrappers.splice(i, 0, wrap);
@@ -5341,8 +5356,7 @@ class HeightOracle {
5341
5356
  }
5342
5357
  refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) {
5343
5358
  let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1;
5344
- let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping ||
5345
- Math.abs(charWidth - this.charWidth) > 0.1;
5359
+ let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping;
5346
5360
  this.lineWrapping = lineWrapping;
5347
5361
  this.lineHeight = lineHeight;
5348
5362
  this.charWidth = charWidth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.42.0",
3
+ "version": "6.43.0",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",