@codemirror/view 6.34.3 → 6.35.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,19 @@
1
+ ## 6.35.1 (2024-12-06)
2
+
3
+ ### Bug fixes
4
+
5
+ Work around another crash caused by incorrect composition positions reported by `EditContext`.
6
+
7
+ Stop disabling custom cursors on Safari version 11.4 and up, which support `caret-color`.
8
+
9
+ Fix an issue where a tooltip with wrapped content could, in some circumstances, fail to find a stable position due to a cyclic dependency between its width and its position.
10
+
11
+ ## 6.35.0 (2024-11-21)
12
+
13
+ ### New features
14
+
15
+ Tooltips can now use the `clip` option to control whether they are hidden when outside the visible editor content.
16
+
1
17
  ## 6.34.3 (2024-11-15)
2
18
 
3
19
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -7204,9 +7204,11 @@ class EditContextManager {
7204
7204
  for (let format of e.getTextFormats()) {
7205
7205
  let lineStyle = format.underlineStyle, thickness = format.underlineThickness;
7206
7206
  if (lineStyle != "None" && thickness != "None") {
7207
- let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
7208
- deco.push(Decoration.mark({ attributes: { style } })
7209
- .range(this.toEditorPos(format.rangeStart), this.toEditorPos(format.rangeEnd)));
7207
+ let from = this.toEditorPos(format.rangeStart), to = this.toEditorPos(format.rangeEnd);
7208
+ if (from < to) {
7209
+ let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
7210
+ deco.push(Decoration.mark({ attributes: { style } }).range(from, to));
7211
+ }
7210
7212
  }
7211
7213
  }
7212
7214
  view.dispatch({ effects: setEditContextFormatting.of(Decoration.set(deco)) });
@@ -7319,6 +7321,7 @@ class EditContextManager {
7319
7321
  this.to - this.from > 10000 /* CxVp.Margin */ * 3);
7320
7322
  }
7321
7323
  toEditorPos(contextPos) {
7324
+ contextPos = Math.min(contextPos, this.to - this.from);
7322
7325
  let c = this.composing;
7323
7326
  return c && c.drifted ? c.editorBase + (contextPos - c.contextBase) : contextPos + this.from;
7324
7327
  }
@@ -8983,7 +8986,7 @@ function layer(config) {
8983
8986
  ];
8984
8987
  }
8985
8988
 
8986
- const CanHidePrimary = !browser.ios; // FIXME test IE
8989
+ const CanHidePrimary = !(browser.ios && browser.webkit && browser.webkit_version < 534);
8987
8990
  const selectionConfig = state.Facet.define({
8988
8991
  combine(configs) {
8989
8992
  return state.combineConfig(configs, {
@@ -9949,10 +9952,10 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9949
9952
  let tooltip = this.manager.tooltips[i], tView = this.manager.tooltipViews[i], { dom } = tView;
9950
9953
  let pos = measured.pos[i], size = measured.size[i];
9951
9954
  // Hide tooltips that are outside of the editor.
9952
- if (!pos || pos.bottom <= Math.max(visible.top, space.top) ||
9955
+ if (!pos || tooltip.clip !== false && (pos.bottom <= Math.max(visible.top, space.top) ||
9953
9956
  pos.top >= Math.min(visible.bottom, space.bottom) ||
9954
9957
  pos.right < Math.max(visible.left, space.left) - .1 ||
9955
- pos.left > Math.min(visible.right, space.right) + .1) {
9958
+ pos.left > Math.min(visible.right, space.right) + .1)) {
9956
9959
  dom.style.top = Outside;
9957
9960
  continue;
9958
9961
  }
@@ -9990,11 +9993,11 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9990
9993
  top = above ? r.top - height - 2 - arrowHeight : r.bottom + arrowHeight + 2;
9991
9994
  if (this.position == "absolute") {
9992
9995
  dom.style.top = (top - measured.parent.top) / scaleY + "px";
9993
- dom.style.left = (left - measured.parent.left) / scaleX + "px";
9996
+ setLeftStyle(dom, (left - measured.parent.left) / scaleX);
9994
9997
  }
9995
9998
  else {
9996
9999
  dom.style.top = top / scaleY + "px";
9997
- dom.style.left = left / scaleX + "px";
10000
+ setLeftStyle(dom, left / scaleX);
9998
10001
  }
9999
10002
  if (arrow) {
10000
10003
  let arrowLeft = pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Arrow.Offset */ - 7 /* Arrow.Size */);
@@ -10025,6 +10028,11 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
10025
10028
  scroll() { this.maybeMeasure(); }
10026
10029
  }
10027
10030
  });
10031
+ function setLeftStyle(elt, value) {
10032
+ let current = parseInt(elt.style.left, 10);
10033
+ if (isNaN(current) || Math.abs(value - current) > 1)
10034
+ elt.style.left = value + "px";
10035
+ }
10028
10036
  const baseTheme = EditorView.baseTheme({
10029
10037
  ".cm-tooltip": {
10030
10038
  zIndex: 500,
package/dist/index.d.cts CHANGED
@@ -1876,6 +1876,12 @@ interface Tooltip {
1876
1876
  to position `pos`.
1877
1877
  */
1878
1878
  arrow?: boolean;
1879
+ /**
1880
+ By default, tooltips are hidden when their position is outside
1881
+ of the visible editor content. Set this to false to turn that
1882
+ off.
1883
+ */
1884
+ clip?: boolean;
1879
1885
  }
1880
1886
  /**
1881
1887
  Describes the way a tooltip is displayed.
package/dist/index.d.ts CHANGED
@@ -1876,6 +1876,12 @@ interface Tooltip {
1876
1876
  to position `pos`.
1877
1877
  */
1878
1878
  arrow?: boolean;
1879
+ /**
1880
+ By default, tooltips are hidden when their position is outside
1881
+ of the visible editor content. Set this to false to turn that
1882
+ off.
1883
+ */
1884
+ clip?: boolean;
1879
1885
  }
1880
1886
  /**
1881
1887
  Describes the way a tooltip is displayed.
package/dist/index.js CHANGED
@@ -7199,9 +7199,11 @@ class EditContextManager {
7199
7199
  for (let format of e.getTextFormats()) {
7200
7200
  let lineStyle = format.underlineStyle, thickness = format.underlineThickness;
7201
7201
  if (lineStyle != "None" && thickness != "None") {
7202
- let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
7203
- deco.push(Decoration.mark({ attributes: { style } })
7204
- .range(this.toEditorPos(format.rangeStart), this.toEditorPos(format.rangeEnd)));
7202
+ let from = this.toEditorPos(format.rangeStart), to = this.toEditorPos(format.rangeEnd);
7203
+ if (from < to) {
7204
+ let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
7205
+ deco.push(Decoration.mark({ attributes: { style } }).range(from, to));
7206
+ }
7205
7207
  }
7206
7208
  }
7207
7209
  view.dispatch({ effects: setEditContextFormatting.of(Decoration.set(deco)) });
@@ -7314,6 +7316,7 @@ class EditContextManager {
7314
7316
  this.to - this.from > 10000 /* CxVp.Margin */ * 3);
7315
7317
  }
7316
7318
  toEditorPos(contextPos) {
7319
+ contextPos = Math.min(contextPos, this.to - this.from);
7317
7320
  let c = this.composing;
7318
7321
  return c && c.drifted ? c.editorBase + (contextPos - c.contextBase) : contextPos + this.from;
7319
7322
  }
@@ -8978,7 +8981,7 @@ function layer(config) {
8978
8981
  ];
8979
8982
  }
8980
8983
 
8981
- const CanHidePrimary = !browser.ios; // FIXME test IE
8984
+ const CanHidePrimary = !(browser.ios && browser.webkit && browser.webkit_version < 534);
8982
8985
  const selectionConfig = /*@__PURE__*/Facet.define({
8983
8986
  combine(configs) {
8984
8987
  return combineConfig(configs, {
@@ -9944,10 +9947,10 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9944
9947
  let tooltip = this.manager.tooltips[i], tView = this.manager.tooltipViews[i], { dom } = tView;
9945
9948
  let pos = measured.pos[i], size = measured.size[i];
9946
9949
  // Hide tooltips that are outside of the editor.
9947
- if (!pos || pos.bottom <= Math.max(visible.top, space.top) ||
9950
+ if (!pos || tooltip.clip !== false && (pos.bottom <= Math.max(visible.top, space.top) ||
9948
9951
  pos.top >= Math.min(visible.bottom, space.bottom) ||
9949
9952
  pos.right < Math.max(visible.left, space.left) - .1 ||
9950
- pos.left > Math.min(visible.right, space.right) + .1) {
9953
+ pos.left > Math.min(visible.right, space.right) + .1)) {
9951
9954
  dom.style.top = Outside;
9952
9955
  continue;
9953
9956
  }
@@ -9985,11 +9988,11 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9985
9988
  top = above ? r.top - height - 2 - arrowHeight : r.bottom + arrowHeight + 2;
9986
9989
  if (this.position == "absolute") {
9987
9990
  dom.style.top = (top - measured.parent.top) / scaleY + "px";
9988
- dom.style.left = (left - measured.parent.left) / scaleX + "px";
9991
+ setLeftStyle(dom, (left - measured.parent.left) / scaleX);
9989
9992
  }
9990
9993
  else {
9991
9994
  dom.style.top = top / scaleY + "px";
9992
- dom.style.left = left / scaleX + "px";
9995
+ setLeftStyle(dom, left / scaleX);
9993
9996
  }
9994
9997
  if (arrow) {
9995
9998
  let arrowLeft = pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Arrow.Offset */ - 7 /* Arrow.Size */);
@@ -10020,6 +10023,11 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
10020
10023
  scroll() { this.maybeMeasure(); }
10021
10024
  }
10022
10025
  });
10026
+ function setLeftStyle(elt, value) {
10027
+ let current = parseInt(elt.style.left, 10);
10028
+ if (isNaN(current) || Math.abs(value - current) > 1)
10029
+ elt.style.left = value + "px";
10030
+ }
10023
10031
  const baseTheme = /*@__PURE__*/EditorView.baseTheme({
10024
10032
  ".cm-tooltip": {
10025
10033
  zIndex: 500,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.34.3",
3
+ "version": "6.35.1",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",