@codemirror/view 6.20.0 → 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,19 @@
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
+
9
+ ## 6.20.1 (2023-09-22)
10
+
11
+ ### Bug fixes
12
+
13
+ Fix a crash in plugin event handlers after dynamic reconfiguration.
14
+
15
+ Fix an issue where, on Chrome, tooltips would no longer use fixed positioning.
16
+
1
17
  ## 6.20.0 (2023-09-20)
2
18
 
3
19
  ### 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)
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)
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) {
@@ -7084,7 +7094,6 @@ class EditorView {
7084
7094
  plugin.destroy(this);
7085
7095
  this.plugins = newPlugins;
7086
7096
  this.pluginMap.clear();
7087
- this.inputState.ensureHandlers(this.plugins);
7088
7097
  }
7089
7098
  else {
7090
7099
  for (let p of this.plugins)
@@ -7092,6 +7101,8 @@ class EditorView {
7092
7101
  }
7093
7102
  for (let i = 0; i < this.plugins.length; i++)
7094
7103
  this.plugins[i].update(this);
7104
+ if (prevSpecs != specs)
7105
+ this.inputState.ensureHandlers(this.plugins);
7095
7106
  }
7096
7107
  /**
7097
7108
  @internal
@@ -9189,13 +9200,13 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9189
9200
  readMeasure() {
9190
9201
  let editor = this.view.dom.getBoundingClientRect();
9191
9202
  let scaleX = 1, scaleY = 1, makeAbsolute = false;
9192
- if (this.position == "fixed") {
9193
- let views = this.manager.tooltipViews;
9194
- // When the dialog's offset parent isn't the body, we are
9195
- // probably in a transformed container, and should use absolute
9196
- // positioning instead, since fixed positioning inside a
9197
- // transform works in a very broken way.
9198
- makeAbsolute = views.length > 0 && views[0].dom.offsetParent != this.container.ownerDocument.body;
9203
+ if (this.position == "fixed" && this.manager.tooltipViews.length) {
9204
+ // When the dialog's offset parent isn't the body (Firefox) or
9205
+ // null (Webkit), we are probably in a transformed container,
9206
+ // and should use absolute positioning instead, since fixed
9207
+ // positioning inside a transform works in a very broken way.
9208
+ let { offsetParent } = this.manager.tooltipViews[0].dom;
9209
+ makeAbsolute = !!(offsetParent && offsetParent != this.container.ownerDocument.body);
9199
9210
  }
9200
9211
  if (makeAbsolute || this.position == "absolute") {
9201
9212
  if (this.parent) {
@@ -10022,14 +10033,14 @@ class UpdateContext {
10022
10033
  this.cursor = state.RangeSet.iter(gutter.markers, viewport.from);
10023
10034
  }
10024
10035
  addElement(view, block, markers) {
10025
- let { gutter } = this, above = block.top - this.height;
10036
+ let { gutter } = this, above = (block.top - this.height) / view.scaleY, height = block.height / view.scaleY;
10026
10037
  if (this.i == gutter.elements.length) {
10027
- let newElt = new GutterElement(view, block.height, above, markers);
10038
+ let newElt = new GutterElement(view, height, above, markers);
10028
10039
  gutter.elements.push(newElt);
10029
10040
  gutter.dom.appendChild(newElt.dom);
10030
10041
  }
10031
10042
  else {
10032
- gutter.elements[this.i].update(view, block.height, above, markers);
10043
+ gutter.elements[this.i].update(view, height, above, markers);
10033
10044
  }
10034
10045
  this.height = block.bottom;
10035
10046
  this.i++;
@@ -10122,10 +10133,10 @@ class GutterElement {
10122
10133
  update(view, height, above, markers) {
10123
10134
  if (this.height != height) {
10124
10135
  this.height = height;
10125
- this.dom.style.height = height / view.scaleY + "px";
10136
+ this.dom.style.height = height + "px";
10126
10137
  }
10127
10138
  if (this.above != above)
10128
- this.dom.style.marginTop = (this.above = above) ? above / view.scaleY + "px" : "";
10139
+ this.dom.style.marginTop = (this.above = above) ? above + "px" : "";
10129
10140
  if (!sameMarkers(this.markers, markers))
10130
10141
  this.setMarkers(view, markers);
10131
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)
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)
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) {
@@ -7079,7 +7089,6 @@ class EditorView {
7079
7089
  plugin.destroy(this);
7080
7090
  this.plugins = newPlugins;
7081
7091
  this.pluginMap.clear();
7082
- this.inputState.ensureHandlers(this.plugins);
7083
7092
  }
7084
7093
  else {
7085
7094
  for (let p of this.plugins)
@@ -7087,6 +7096,8 @@ class EditorView {
7087
7096
  }
7088
7097
  for (let i = 0; i < this.plugins.length; i++)
7089
7098
  this.plugins[i].update(this);
7099
+ if (prevSpecs != specs)
7100
+ this.inputState.ensureHandlers(this.plugins);
7090
7101
  }
7091
7102
  /**
7092
7103
  @internal
@@ -9184,13 +9195,13 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9184
9195
  readMeasure() {
9185
9196
  let editor = this.view.dom.getBoundingClientRect();
9186
9197
  let scaleX = 1, scaleY = 1, makeAbsolute = false;
9187
- if (this.position == "fixed") {
9188
- let views = this.manager.tooltipViews;
9189
- // When the dialog's offset parent isn't the body, we are
9190
- // probably in a transformed container, and should use absolute
9191
- // positioning instead, since fixed positioning inside a
9192
- // transform works in a very broken way.
9193
- makeAbsolute = views.length > 0 && views[0].dom.offsetParent != this.container.ownerDocument.body;
9198
+ if (this.position == "fixed" && this.manager.tooltipViews.length) {
9199
+ // When the dialog's offset parent isn't the body (Firefox) or
9200
+ // null (Webkit), we are probably in a transformed container,
9201
+ // and should use absolute positioning instead, since fixed
9202
+ // positioning inside a transform works in a very broken way.
9203
+ let { offsetParent } = this.manager.tooltipViews[0].dom;
9204
+ makeAbsolute = !!(offsetParent && offsetParent != this.container.ownerDocument.body);
9194
9205
  }
9195
9206
  if (makeAbsolute || this.position == "absolute") {
9196
9207
  if (this.parent) {
@@ -10017,14 +10028,14 @@ class UpdateContext {
10017
10028
  this.cursor = RangeSet.iter(gutter.markers, viewport.from);
10018
10029
  }
10019
10030
  addElement(view, block, markers) {
10020
- let { gutter } = this, above = block.top - this.height;
10031
+ let { gutter } = this, above = (block.top - this.height) / view.scaleY, height = block.height / view.scaleY;
10021
10032
  if (this.i == gutter.elements.length) {
10022
- let newElt = new GutterElement(view, block.height, above, markers);
10033
+ let newElt = new GutterElement(view, height, above, markers);
10023
10034
  gutter.elements.push(newElt);
10024
10035
  gutter.dom.appendChild(newElt.dom);
10025
10036
  }
10026
10037
  else {
10027
- gutter.elements[this.i].update(view, block.height, above, markers);
10038
+ gutter.elements[this.i].update(view, height, above, markers);
10028
10039
  }
10029
10040
  this.height = block.bottom;
10030
10041
  this.i++;
@@ -10117,10 +10128,10 @@ class GutterElement {
10117
10128
  update(view, height, above, markers) {
10118
10129
  if (this.height != height) {
10119
10130
  this.height = height;
10120
- this.dom.style.height = height / view.scaleY + "px";
10131
+ this.dom.style.height = height + "px";
10121
10132
  }
10122
10133
  if (this.above != above)
10123
- this.dom.style.marginTop = (this.above = above) ? above / view.scaleY + "px" : "";
10134
+ this.dom.style.marginTop = (this.above = above) ? above + "px" : "";
10124
10135
  if (!sameMarkers(this.markers, markers))
10125
10136
  this.setMarkers(view, markers);
10126
10137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.20.0",
3
+ "version": "6.20.2",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",