@codemirror/view 6.1.2 → 6.1.3

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.1.3 (2022-08-03)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug where a document that contains only non-printing characters would lead to bogus text measurements (and, from those, to crashing).
6
+
7
+ Make sure differences between estimated and actual block heights don't cause visible scroll glitches.
8
+
1
9
  ## 6.1.2 (2022-07-27)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1473,15 +1473,17 @@ class LineView extends ContentView {
1473
1473
  return null;
1474
1474
  let totalWidth = 0;
1475
1475
  for (let child of this.children) {
1476
- if (!(child instanceof TextView))
1476
+ if (!(child instanceof TextView) || /[^ -~]/.test(child.text))
1477
1477
  return null;
1478
1478
  let rects = clientRectsFor(child.dom);
1479
1479
  if (rects.length != 1)
1480
1480
  return null;
1481
1481
  totalWidth += rects[0].width;
1482
1482
  }
1483
- return { lineHeight: this.dom.getBoundingClientRect().height,
1484
- charWidth: totalWidth / this.length };
1483
+ return !totalWidth ? null : {
1484
+ lineHeight: this.dom.getBoundingClientRect().height,
1485
+ charWidth: totalWidth / this.length
1486
+ };
1485
1487
  }
1486
1488
  coordsAt(pos, side) {
1487
1489
  return coordsInChildren(this, pos, side);
@@ -4675,7 +4677,7 @@ function visiblePixelRange(dom, paddingTop) {
4675
4677
  left = Math.max(left, parentRect.left);
4676
4678
  right = Math.min(right, parentRect.right);
4677
4679
  top = Math.max(top, parentRect.top);
4678
- bottom = Math.min(bottom, parentRect.bottom);
4680
+ bottom = parent == dom.parentNode ? parentRect.bottom : Math.min(bottom, parentRect.bottom);
4679
4681
  }
4680
4682
  parent = style.position == "absolute" || style.position == "fixed" ? elt.offsetParent : elt.parentNode;
4681
4683
  }
@@ -6284,10 +6286,13 @@ class EditorView {
6284
6286
  if (flush)
6285
6287
  this.observer.forceFlush();
6286
6288
  let updated = null;
6289
+ let { scrollHeight, scrollTop, clientHeight } = this.scrollDOM;
6290
+ let refHeight = scrollTop > scrollHeight - clientHeight - 4 ? scrollHeight : scrollTop;
6287
6291
  try {
6288
6292
  for (let i = 0;; i++) {
6289
6293
  this.updateState = 1 /* Measuring */;
6290
6294
  let oldViewport = this.viewport;
6295
+ let refBlock = this.viewState.lineBlockAtHeight(refHeight);
6291
6296
  let changed = this.viewState.measure(this);
6292
6297
  if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
6293
6298
  break;
@@ -6339,6 +6344,13 @@ class EditorView {
6339
6344
  this.viewState.scrollTarget = null;
6340
6345
  scrolled = true;
6341
6346
  }
6347
+ else {
6348
+ let diff = this.viewState.lineBlockAt(refBlock.from).top - refBlock.top;
6349
+ if (diff > 1 || diff < -1) {
6350
+ this.scrollDOM.scrollTop += diff;
6351
+ scrolled = true;
6352
+ }
6353
+ }
6342
6354
  if (redrawn)
6343
6355
  this.docView.updateSelection(true);
6344
6356
  if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to &&
package/dist/index.js CHANGED
@@ -1468,15 +1468,17 @@ class LineView extends ContentView {
1468
1468
  return null;
1469
1469
  let totalWidth = 0;
1470
1470
  for (let child of this.children) {
1471
- if (!(child instanceof TextView))
1471
+ if (!(child instanceof TextView) || /[^ -~]/.test(child.text))
1472
1472
  return null;
1473
1473
  let rects = clientRectsFor(child.dom);
1474
1474
  if (rects.length != 1)
1475
1475
  return null;
1476
1476
  totalWidth += rects[0].width;
1477
1477
  }
1478
- return { lineHeight: this.dom.getBoundingClientRect().height,
1479
- charWidth: totalWidth / this.length };
1478
+ return !totalWidth ? null : {
1479
+ lineHeight: this.dom.getBoundingClientRect().height,
1480
+ charWidth: totalWidth / this.length
1481
+ };
1480
1482
  }
1481
1483
  coordsAt(pos, side) {
1482
1484
  return coordsInChildren(this, pos, side);
@@ -4668,7 +4670,7 @@ function visiblePixelRange(dom, paddingTop) {
4668
4670
  left = Math.max(left, parentRect.left);
4669
4671
  right = Math.min(right, parentRect.right);
4670
4672
  top = Math.max(top, parentRect.top);
4671
- bottom = Math.min(bottom, parentRect.bottom);
4673
+ bottom = parent == dom.parentNode ? parentRect.bottom : Math.min(bottom, parentRect.bottom);
4672
4674
  }
4673
4675
  parent = style.position == "absolute" || style.position == "fixed" ? elt.offsetParent : elt.parentNode;
4674
4676
  }
@@ -6277,10 +6279,13 @@ class EditorView {
6277
6279
  if (flush)
6278
6280
  this.observer.forceFlush();
6279
6281
  let updated = null;
6282
+ let { scrollHeight, scrollTop, clientHeight } = this.scrollDOM;
6283
+ let refHeight = scrollTop > scrollHeight - clientHeight - 4 ? scrollHeight : scrollTop;
6280
6284
  try {
6281
6285
  for (let i = 0;; i++) {
6282
6286
  this.updateState = 1 /* Measuring */;
6283
6287
  let oldViewport = this.viewport;
6288
+ let refBlock = this.viewState.lineBlockAtHeight(refHeight);
6284
6289
  let changed = this.viewState.measure(this);
6285
6290
  if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
6286
6291
  break;
@@ -6332,6 +6337,13 @@ class EditorView {
6332
6337
  this.viewState.scrollTarget = null;
6333
6338
  scrolled = true;
6334
6339
  }
6340
+ else {
6341
+ let diff = this.viewState.lineBlockAt(refBlock.from).top - refBlock.top;
6342
+ if (diff > 1 || diff < -1) {
6343
+ this.scrollDOM.scrollTop += diff;
6344
+ scrolled = true;
6345
+ }
6346
+ }
6335
6347
  if (redrawn)
6336
6348
  this.docView.updateSelection(true);
6337
6349
  if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.1.2",
3
+ "version": "6.1.3",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",