@codemirror/view 6.34.0 → 6.34.1

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.34.1 (2024-09-27)
2
+
3
+ ### Bug fixes
4
+
5
+ Avoid a stack overflow that could happen when updating a line with a lot of text tokens.
6
+
7
+ Improve the way enormously long (non-wrapped) lines are displayed by making sure they stay shorter than the maximal pixel size the browser's CSS engine can handle.
8
+
1
9
  ## 6.34.0 (2024-09-25)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -561,7 +561,10 @@ class ContentView {
561
561
  if (child.parent == this && children.indexOf(child) < 0)
562
562
  child.destroy();
563
563
  }
564
- this.children.splice(from, to - from, ...children);
564
+ if (children.length < 250)
565
+ this.children.splice(from, to - from, ...children);
566
+ else
567
+ this.children = [].concat(this.children.slice(0, from), children, this.children.slice(to));
565
568
  for (let i = 0; i < children.length; i++)
566
569
  children[i].setParent(this);
567
570
  }
@@ -5770,10 +5773,11 @@ function fullPixelRange(dom, paddingTop) {
5770
5773
  // lines within the viewport, as a kludge to keep the editor
5771
5774
  // responsive when a ridiculously long line is loaded into it.
5772
5775
  class LineGap {
5773
- constructor(from, to, size) {
5776
+ constructor(from, to, size, displaySize) {
5774
5777
  this.from = from;
5775
5778
  this.to = to;
5776
5779
  this.size = size;
5780
+ this.displaySize = displaySize;
5777
5781
  }
5778
5782
  static same(a, b) {
5779
5783
  if (a.length != b.length)
@@ -5787,7 +5791,7 @@ class LineGap {
5787
5791
  }
5788
5792
  draw(viewState, wrapping) {
5789
5793
  return Decoration.replace({
5790
- widget: new LineGapWidget(this.size * (wrapping ? viewState.scaleY : viewState.scaleX), wrapping)
5794
+ widget: new LineGapWidget(this.displaySize * (wrapping ? viewState.scaleY : viewState.scaleX), wrapping)
5791
5795
  }).range(this.from, this.to);
5792
5796
  }
5793
5797
  }
@@ -6089,7 +6093,7 @@ class ViewState {
6089
6093
  let mapped = [];
6090
6094
  for (let gap of gaps)
6091
6095
  if (!changes.touchesRange(gap.from, gap.to))
6092
- mapped.push(new LineGap(changes.mapPos(gap.from), changes.mapPos(gap.to), gap.size));
6096
+ mapped.push(new LineGap(changes.mapPos(gap.from), changes.mapPos(gap.to), gap.size, gap.displaySize));
6093
6097
  return mapped;
6094
6098
  }
6095
6099
  // Computes positions in the viewport where the start or end of a
@@ -6130,7 +6134,9 @@ class ViewState {
6130
6134
  if (lineStart > from)
6131
6135
  to = lineStart;
6132
6136
  }
6133
- gap = new LineGap(from, to, this.gapSize(line, from, to, structure));
6137
+ let size = this.gapSize(line, from, to, structure);
6138
+ let displaySize = wrapping || size < 2000000 /* VP.MaxHorizGap */ ? size : 2000000 /* VP.MaxHorizGap */;
6139
+ gap = new LineGap(from, to, size, displaySize);
6134
6140
  }
6135
6141
  gaps.push(gap);
6136
6142
  };
@@ -6161,16 +6167,24 @@ class ViewState {
6161
6167
  else {
6162
6168
  let totalWidth = structure.total * this.heightOracle.charWidth;
6163
6169
  let marginWidth = margin * this.heightOracle.charWidth;
6170
+ let horizOffset = 0;
6171
+ if (totalWidth > 2000000 /* VP.MaxHorizGap */)
6172
+ for (let old of current) {
6173
+ if (old.from >= line.from && old.from < line.to && old.size != old.displaySize &&
6174
+ old.from * this.heightOracle.charWidth + horizOffset < this.pixelViewport.left)
6175
+ horizOffset = old.size - old.displaySize;
6176
+ }
6177
+ let pxLeft = this.pixelViewport.left + horizOffset, pxRight = this.pixelViewport.right + horizOffset;
6164
6178
  let left, right;
6165
6179
  if (target != null) {
6166
6180
  let targetFrac = findFraction(structure, target);
6167
- let spaceFrac = ((this.pixelViewport.right - this.pixelViewport.left) / 2 + marginWidth) / totalWidth;
6181
+ let spaceFrac = ((pxRight - pxLeft) / 2 + marginWidth) / totalWidth;
6168
6182
  left = targetFrac - spaceFrac;
6169
6183
  right = targetFrac + spaceFrac;
6170
6184
  }
6171
6185
  else {
6172
- left = (this.pixelViewport.left - marginWidth) / totalWidth;
6173
- right = (this.pixelViewport.right + marginWidth) / totalWidth;
6186
+ left = (pxLeft - marginWidth) / totalWidth;
6187
+ right = (pxRight + marginWidth) / totalWidth;
6174
6188
  }
6175
6189
  viewFrom = findPosition(structure, left);
6176
6190
  viewTo = findPosition(structure, right);
package/dist/index.js CHANGED
@@ -559,7 +559,10 @@ class ContentView {
559
559
  if (child.parent == this && children.indexOf(child) < 0)
560
560
  child.destroy();
561
561
  }
562
- this.children.splice(from, to - from, ...children);
562
+ if (children.length < 250)
563
+ this.children.splice(from, to - from, ...children);
564
+ else
565
+ this.children = [].concat(this.children.slice(0, from), children, this.children.slice(to));
563
566
  for (let i = 0; i < children.length; i++)
564
567
  children[i].setParent(this);
565
568
  }
@@ -5765,10 +5768,11 @@ function fullPixelRange(dom, paddingTop) {
5765
5768
  // lines within the viewport, as a kludge to keep the editor
5766
5769
  // responsive when a ridiculously long line is loaded into it.
5767
5770
  class LineGap {
5768
- constructor(from, to, size) {
5771
+ constructor(from, to, size, displaySize) {
5769
5772
  this.from = from;
5770
5773
  this.to = to;
5771
5774
  this.size = size;
5775
+ this.displaySize = displaySize;
5772
5776
  }
5773
5777
  static same(a, b) {
5774
5778
  if (a.length != b.length)
@@ -5782,7 +5786,7 @@ class LineGap {
5782
5786
  }
5783
5787
  draw(viewState, wrapping) {
5784
5788
  return Decoration.replace({
5785
- widget: new LineGapWidget(this.size * (wrapping ? viewState.scaleY : viewState.scaleX), wrapping)
5789
+ widget: new LineGapWidget(this.displaySize * (wrapping ? viewState.scaleY : viewState.scaleX), wrapping)
5786
5790
  }).range(this.from, this.to);
5787
5791
  }
5788
5792
  }
@@ -6084,7 +6088,7 @@ class ViewState {
6084
6088
  let mapped = [];
6085
6089
  for (let gap of gaps)
6086
6090
  if (!changes.touchesRange(gap.from, gap.to))
6087
- mapped.push(new LineGap(changes.mapPos(gap.from), changes.mapPos(gap.to), gap.size));
6091
+ mapped.push(new LineGap(changes.mapPos(gap.from), changes.mapPos(gap.to), gap.size, gap.displaySize));
6088
6092
  return mapped;
6089
6093
  }
6090
6094
  // Computes positions in the viewport where the start or end of a
@@ -6125,7 +6129,9 @@ class ViewState {
6125
6129
  if (lineStart > from)
6126
6130
  to = lineStart;
6127
6131
  }
6128
- gap = new LineGap(from, to, this.gapSize(line, from, to, structure));
6132
+ let size = this.gapSize(line, from, to, structure);
6133
+ let displaySize = wrapping || size < 2000000 /* VP.MaxHorizGap */ ? size : 2000000 /* VP.MaxHorizGap */;
6134
+ gap = new LineGap(from, to, size, displaySize);
6129
6135
  }
6130
6136
  gaps.push(gap);
6131
6137
  };
@@ -6156,16 +6162,24 @@ class ViewState {
6156
6162
  else {
6157
6163
  let totalWidth = structure.total * this.heightOracle.charWidth;
6158
6164
  let marginWidth = margin * this.heightOracle.charWidth;
6165
+ let horizOffset = 0;
6166
+ if (totalWidth > 2000000 /* VP.MaxHorizGap */)
6167
+ for (let old of current) {
6168
+ if (old.from >= line.from && old.from < line.to && old.size != old.displaySize &&
6169
+ old.from * this.heightOracle.charWidth + horizOffset < this.pixelViewport.left)
6170
+ horizOffset = old.size - old.displaySize;
6171
+ }
6172
+ let pxLeft = this.pixelViewport.left + horizOffset, pxRight = this.pixelViewport.right + horizOffset;
6159
6173
  let left, right;
6160
6174
  if (target != null) {
6161
6175
  let targetFrac = findFraction(structure, target);
6162
- let spaceFrac = ((this.pixelViewport.right - this.pixelViewport.left) / 2 + marginWidth) / totalWidth;
6176
+ let spaceFrac = ((pxRight - pxLeft) / 2 + marginWidth) / totalWidth;
6163
6177
  left = targetFrac - spaceFrac;
6164
6178
  right = targetFrac + spaceFrac;
6165
6179
  }
6166
6180
  else {
6167
- left = (this.pixelViewport.left - marginWidth) / totalWidth;
6168
- right = (this.pixelViewport.right + marginWidth) / totalWidth;
6181
+ left = (pxLeft - marginWidth) / totalWidth;
6182
+ right = (pxRight + marginWidth) / totalWidth;
6169
6183
  }
6170
6184
  viewFrom = findPosition(structure, left);
6171
6185
  viewTo = findPosition(structure, right);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.34.0",
3
+ "version": "6.34.1",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",