@codemirror/view 6.20.1 → 6.20.2

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.20.2 (2023-09-25)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue in the way the DOM selection is being read that could break backspacing of widgets on Android.
6
+
7
+ Fix a bug where the editor could incorrectly computate its transform scale when it was small.
8
+
1
9
  ## 6.20.1 (2023-09-22)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -5335,9 +5335,9 @@ class ViewState {
5335
5335
  if (domRect.width && domRect.height) {
5336
5336
  let scaleX = domRect.width / dom.offsetWidth;
5337
5337
  let scaleY = domRect.height / dom.offsetHeight;
5338
- if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX))
5338
+ if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX) || Math.abs(domRect.width - dom.offsetWidth) < 1)
5339
5339
  scaleX = 1;
5340
- if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY))
5340
+ if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY) || Math.abs(domRect.height - dom.offsetHeight) < 1)
5341
5341
  scaleY = 1;
5342
5342
  if (this.scaleX != scaleX || this.scaleY != scaleY) {
5343
5343
  this.scaleX = scaleX;
@@ -6075,10 +6075,20 @@ class DOMReader {
6075
6075
  if (point.node == node && node.childNodes[point.offset] == next)
6076
6076
  point.pos = this.text.length;
6077
6077
  }
6078
- findPointInside(node, maxLen) {
6078
+ findPointInside(node, length) {
6079
6079
  for (let point of this.points)
6080
6080
  if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
6081
- point.pos = this.text.length + Math.min(maxLen, point.offset);
6081
+ point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ? length : 0);
6082
+ }
6083
+ }
6084
+ function isAtEnd(parent, node, offset) {
6085
+ for (;;) {
6086
+ if (!node || offset < maxOffset(node))
6087
+ return false;
6088
+ if (node == parent)
6089
+ return true;
6090
+ offset = domIndex(node) + 1;
6091
+ node = node.parentNode;
6082
6092
  }
6083
6093
  }
6084
6094
  function isBlockElement(node) {
@@ -10023,14 +10033,14 @@ class UpdateContext {
10023
10033
  this.cursor = state.RangeSet.iter(gutter.markers, viewport.from);
10024
10034
  }
10025
10035
  addElement(view, block, markers) {
10026
- let { gutter } = this, above = block.top - this.height;
10036
+ let { gutter } = this, above = (block.top - this.height) / view.scaleY, height = block.height / view.scaleY;
10027
10037
  if (this.i == gutter.elements.length) {
10028
- let newElt = new GutterElement(view, block.height, above, markers);
10038
+ let newElt = new GutterElement(view, height, above, markers);
10029
10039
  gutter.elements.push(newElt);
10030
10040
  gutter.dom.appendChild(newElt.dom);
10031
10041
  }
10032
10042
  else {
10033
- gutter.elements[this.i].update(view, block.height, above, markers);
10043
+ gutter.elements[this.i].update(view, height, above, markers);
10034
10044
  }
10035
10045
  this.height = block.bottom;
10036
10046
  this.i++;
@@ -10123,10 +10133,10 @@ class GutterElement {
10123
10133
  update(view, height, above, markers) {
10124
10134
  if (this.height != height) {
10125
10135
  this.height = height;
10126
- this.dom.style.height = height / view.scaleY + "px";
10136
+ this.dom.style.height = height + "px";
10127
10137
  }
10128
10138
  if (this.above != above)
10129
- this.dom.style.marginTop = (this.above = above) ? above / view.scaleY + "px" : "";
10139
+ this.dom.style.marginTop = (this.above = above) ? above + "px" : "";
10130
10140
  if (!sameMarkers(this.markers, markers))
10131
10141
  this.setMarkers(view, markers);
10132
10142
  }
package/dist/index.js CHANGED
@@ -5330,9 +5330,9 @@ class ViewState {
5330
5330
  if (domRect.width && domRect.height) {
5331
5331
  let scaleX = domRect.width / dom.offsetWidth;
5332
5332
  let scaleY = domRect.height / dom.offsetHeight;
5333
- if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX))
5333
+ if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX) || Math.abs(domRect.width - dom.offsetWidth) < 1)
5334
5334
  scaleX = 1;
5335
- if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY))
5335
+ if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY) || Math.abs(domRect.height - dom.offsetHeight) < 1)
5336
5336
  scaleY = 1;
5337
5337
  if (this.scaleX != scaleX || this.scaleY != scaleY) {
5338
5338
  this.scaleX = scaleX;
@@ -6070,10 +6070,20 @@ class DOMReader {
6070
6070
  if (point.node == node && node.childNodes[point.offset] == next)
6071
6071
  point.pos = this.text.length;
6072
6072
  }
6073
- findPointInside(node, maxLen) {
6073
+ findPointInside(node, length) {
6074
6074
  for (let point of this.points)
6075
6075
  if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
6076
- point.pos = this.text.length + Math.min(maxLen, point.offset);
6076
+ point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ? length : 0);
6077
+ }
6078
+ }
6079
+ function isAtEnd(parent, node, offset) {
6080
+ for (;;) {
6081
+ if (!node || offset < maxOffset(node))
6082
+ return false;
6083
+ if (node == parent)
6084
+ return true;
6085
+ offset = domIndex(node) + 1;
6086
+ node = node.parentNode;
6077
6087
  }
6078
6088
  }
6079
6089
  function isBlockElement(node) {
@@ -10018,14 +10028,14 @@ class UpdateContext {
10018
10028
  this.cursor = RangeSet.iter(gutter.markers, viewport.from);
10019
10029
  }
10020
10030
  addElement(view, block, markers) {
10021
- let { gutter } = this, above = block.top - this.height;
10031
+ let { gutter } = this, above = (block.top - this.height) / view.scaleY, height = block.height / view.scaleY;
10022
10032
  if (this.i == gutter.elements.length) {
10023
- let newElt = new GutterElement(view, block.height, above, markers);
10033
+ let newElt = new GutterElement(view, height, above, markers);
10024
10034
  gutter.elements.push(newElt);
10025
10035
  gutter.dom.appendChild(newElt.dom);
10026
10036
  }
10027
10037
  else {
10028
- gutter.elements[this.i].update(view, block.height, above, markers);
10038
+ gutter.elements[this.i].update(view, height, above, markers);
10029
10039
  }
10030
10040
  this.height = block.bottom;
10031
10041
  this.i++;
@@ -10118,10 +10128,10 @@ class GutterElement {
10118
10128
  update(view, height, above, markers) {
10119
10129
  if (this.height != height) {
10120
10130
  this.height = height;
10121
- this.dom.style.height = height / view.scaleY + "px";
10131
+ this.dom.style.height = height + "px";
10122
10132
  }
10123
10133
  if (this.above != above)
10124
- this.dom.style.marginTop = (this.above = above) ? above / view.scaleY + "px" : "";
10134
+ this.dom.style.marginTop = (this.above = above) ? above + "px" : "";
10125
10135
  if (!sameMarkers(this.markers, markers))
10126
10136
  this.setMarkers(view, markers);
10127
10137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.20.1",
3
+ "version": "6.20.2",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",