@codemirror/view 6.39.4 → 6.39.5

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,11 @@
1
+ ## 6.39.5 (2025-12-22)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where replaced widgets alone on a line weren't reused and didn't get their `updateDOM` method called.
6
+
7
+ Fix a bug where, when selecting full lines at the end of the document and inserting a character on Chrome, an inappropriate extra newline was inserted.
8
+
1
9
  ## 6.39.4 (2025-12-12)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2573,6 +2573,16 @@ class TileUpdate {
2573
2573
  this.builder = new TileBuilder(this.cache, new DocTile(view, view.contentDOM), state.RangeSet.iter(blockWrappers));
2574
2574
  this.cache.reused.set(old, 2 /* Reused.DOM */);
2575
2575
  this.old = new TilePointer(old);
2576
+ this.reuseWalker = {
2577
+ skip: (tile, from, to) => {
2578
+ this.cache.add(tile);
2579
+ if (tile.isComposite())
2580
+ return false;
2581
+ },
2582
+ enter: tile => this.cache.add(tile),
2583
+ leave: () => { },
2584
+ break: () => { }
2585
+ };
2576
2586
  }
2577
2587
  run(changes, composition) {
2578
2588
  let compositionContext = composition && this.getCompositionContext(composition.text);
@@ -2747,15 +2757,14 @@ class TileUpdate {
2747
2757
  this.openMarks = openEnd;
2748
2758
  }
2749
2759
  forward(from, to) {
2750
- this.old.advance(to - from, 1, {
2751
- skip: (tile, from, to) => {
2752
- if (tile.isText() || to == tile.length)
2753
- this.cache.add(tile);
2754
- },
2755
- enter: tile => this.cache.add(tile),
2756
- leave: () => { },
2757
- break: () => { }
2758
- });
2760
+ if (to - from <= 10) {
2761
+ this.old.advance(to - from, 1, this.reuseWalker);
2762
+ }
2763
+ else {
2764
+ this.old.advance(5, -1, this.reuseWalker);
2765
+ this.old.advance(to - from - 10, -1);
2766
+ this.old.advance(5, 1, this.reuseWalker);
2767
+ }
2759
2768
  }
2760
2769
  getCompositionContext(text) {
2761
2770
  let marks = [], line = null;
@@ -3827,10 +3836,11 @@ function dirAt(view, pos) {
3827
3836
 
3828
3837
  const LineBreakPlaceholder = "\uffff";
3829
3838
  class DOMReader {
3830
- constructor(points, state$1) {
3839
+ constructor(points, view) {
3831
3840
  this.points = points;
3841
+ this.view = view;
3832
3842
  this.text = "";
3833
- this.lineSeparator = state$1.facet(state.EditorState.lineSeparator);
3843
+ this.lineSeparator = view.state.facet(state.EditorState.lineSeparator);
3834
3844
  }
3835
3845
  append(text) {
3836
3846
  this.text += text;
@@ -3848,7 +3858,7 @@ class DOMReader {
3848
3858
  this.readNode(cur);
3849
3859
  let tile = Tile.get(cur), next = cur.nextSibling;
3850
3860
  if (next == end) {
3851
- if ((tile === null || tile === void 0 ? void 0 : tile.breakAfter) && !next)
3861
+ if ((tile === null || tile === void 0 ? void 0 : tile.breakAfter) && !next && parent != this.view.contentDOM)
3852
3862
  this.lineBreak();
3853
3863
  break;
3854
3864
  }
@@ -3973,7 +3983,7 @@ class DOMChange {
3973
3983
  }
3974
3984
  else if (start > -1 && (this.bounds = domBoundsAround(view.docView.tile, start, end, 0))) {
3975
3985
  let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
3976
- let reader = new DOMReader(selPoints, view.state);
3986
+ let reader = new DOMReader(selPoints, view);
3977
3987
  reader.readRange(this.bounds.startDOM, this.bounds.endDOM);
3978
3988
  this.text = reader.text;
3979
3989
  this.newSel = selectionFromPoints(selPoints, this.bounds.from);
package/dist/index.js CHANGED
@@ -2569,6 +2569,16 @@ class TileUpdate {
2569
2569
  this.builder = new TileBuilder(this.cache, new DocTile(view, view.contentDOM), RangeSet.iter(blockWrappers));
2570
2570
  this.cache.reused.set(old, 2 /* Reused.DOM */);
2571
2571
  this.old = new TilePointer(old);
2572
+ this.reuseWalker = {
2573
+ skip: (tile, from, to) => {
2574
+ this.cache.add(tile);
2575
+ if (tile.isComposite())
2576
+ return false;
2577
+ },
2578
+ enter: tile => this.cache.add(tile),
2579
+ leave: () => { },
2580
+ break: () => { }
2581
+ };
2572
2582
  }
2573
2583
  run(changes, composition) {
2574
2584
  let compositionContext = composition && this.getCompositionContext(composition.text);
@@ -2743,15 +2753,14 @@ class TileUpdate {
2743
2753
  this.openMarks = openEnd;
2744
2754
  }
2745
2755
  forward(from, to) {
2746
- this.old.advance(to - from, 1, {
2747
- skip: (tile, from, to) => {
2748
- if (tile.isText() || to == tile.length)
2749
- this.cache.add(tile);
2750
- },
2751
- enter: tile => this.cache.add(tile),
2752
- leave: () => { },
2753
- break: () => { }
2754
- });
2756
+ if (to - from <= 10) {
2757
+ this.old.advance(to - from, 1, this.reuseWalker);
2758
+ }
2759
+ else {
2760
+ this.old.advance(5, -1, this.reuseWalker);
2761
+ this.old.advance(to - from - 10, -1);
2762
+ this.old.advance(5, 1, this.reuseWalker);
2763
+ }
2755
2764
  }
2756
2765
  getCompositionContext(text) {
2757
2766
  let marks = [], line = null;
@@ -3823,10 +3832,11 @@ function dirAt(view, pos) {
3823
3832
 
3824
3833
  const LineBreakPlaceholder = "\uffff";
3825
3834
  class DOMReader {
3826
- constructor(points, state) {
3835
+ constructor(points, view) {
3827
3836
  this.points = points;
3837
+ this.view = view;
3828
3838
  this.text = "";
3829
- this.lineSeparator = state.facet(EditorState.lineSeparator);
3839
+ this.lineSeparator = view.state.facet(EditorState.lineSeparator);
3830
3840
  }
3831
3841
  append(text) {
3832
3842
  this.text += text;
@@ -3844,7 +3854,7 @@ class DOMReader {
3844
3854
  this.readNode(cur);
3845
3855
  let tile = Tile.get(cur), next = cur.nextSibling;
3846
3856
  if (next == end) {
3847
- if ((tile === null || tile === void 0 ? void 0 : tile.breakAfter) && !next)
3857
+ if ((tile === null || tile === void 0 ? void 0 : tile.breakAfter) && !next && parent != this.view.contentDOM)
3848
3858
  this.lineBreak();
3849
3859
  break;
3850
3860
  }
@@ -3969,7 +3979,7 @@ class DOMChange {
3969
3979
  }
3970
3980
  else if (start > -1 && (this.bounds = domBoundsAround(view.docView.tile, start, end, 0))) {
3971
3981
  let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
3972
- let reader = new DOMReader(selPoints, view.state);
3982
+ let reader = new DOMReader(selPoints, view);
3973
3983
  reader.readRange(this.bounds.startDOM, this.bounds.endDOM);
3974
3984
  this.text = reader.text;
3975
3985
  this.newSel = selectionFromPoints(selPoints, this.bounds.from);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.39.4",
3
+ "version": "6.39.5",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",