@codemirror/view 6.15.3 → 6.16.0

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,13 @@
1
+ ## 6.16.0 (2023-07-31)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue that made the gutter not stick in place when the editor was in a right-to-left context.
6
+
7
+ ### New features
8
+
9
+ The new `EditorView.coordsForChar` method returns the client rectangle for a given character in the editor.
10
+
1
11
  ## 6.15.3 (2023-07-18)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2823,6 +2823,28 @@ class DocView extends ContentView {
2823
2823
  off = start;
2824
2824
  }
2825
2825
  }
2826
+ coordsForChar(pos) {
2827
+ let { i, off } = this.childPos(pos, 1), child = this.children[i];
2828
+ if (!(child instanceof LineView))
2829
+ return null;
2830
+ while (child.children.length) {
2831
+ let { i, off: childOff } = child.childPos(off, 1);
2832
+ for (;; i++) {
2833
+ if (i == child.children.length)
2834
+ return null;
2835
+ if ((child = child.children[i]).length)
2836
+ break;
2837
+ }
2838
+ off = childOff;
2839
+ }
2840
+ if (!(child instanceof TextView))
2841
+ return null;
2842
+ let end = state.findClusterBreak(child.text, off);
2843
+ if (end == off)
2844
+ return null;
2845
+ let rects = textRange(child.dom, off, end).getClientRects();
2846
+ return !rects.length || rects[0].top >= rects[0].bottom ? null : rects[0];
2847
+ }
2826
2848
  measureVisibleLineHeights(viewport) {
2827
2849
  let result = [], { from, to } = viewport;
2828
2850
  let contentWidth = this.view.contentDOM.clientWidth;
@@ -5695,7 +5717,7 @@ const baseTheme$1 = buildTheme("." + baseThemeID, {
5695
5717
  display: "flex",
5696
5718
  height: "100%",
5697
5719
  boxSizing: "border-box",
5698
- left: 0,
5720
+ insetInlineStart: 0,
5699
5721
  zIndex: 200
5700
5722
  },
5701
5723
  "&light .cm-gutters": {
@@ -7159,6 +7181,17 @@ class EditorView {
7159
7181
  return flattenRect(rect, (span.dir == exports.Direction.LTR) == (side > 0));
7160
7182
  }
7161
7183
  /**
7184
+ Return the rectangle around a given character. If `pos` does not
7185
+ point in front of a character that is in the viewport and
7186
+ rendered (i.e. not replaced, not a line break), this will return
7187
+ null. For space characters that are a line wrap point, this will
7188
+ return the position before the line break.
7189
+ */
7190
+ coordsForChar(pos) {
7191
+ this.readMeasured();
7192
+ return this.docView.coordsForChar(pos);
7193
+ }
7194
+ /**
7162
7195
  The default width of a character in the editor. May not
7163
7196
  accurately reflect the width of all characters (given variable
7164
7197
  width fonts or styling of invididual ranges).
package/dist/index.d.cts CHANGED
@@ -907,6 +907,14 @@ declare class EditorView {
907
907
  */
908
908
  coordsAtPos(pos: number, side?: -1 | 1): Rect | null;
909
909
  /**
910
+ Return the rectangle around a given character. If `pos` does not
911
+ point in front of a character that is in the viewport and
912
+ rendered (i.e. not replaced, not a line break), this will return
913
+ null. For space characters that are a line wrap point, this will
914
+ return the position before the line break.
915
+ */
916
+ coordsForChar(pos: number): Rect | null;
917
+ /**
910
918
  The default width of a character in the editor. May not
911
919
  accurately reflect the width of all characters (given variable
912
920
  width fonts or styling of invididual ranges).
package/dist/index.d.ts CHANGED
@@ -907,6 +907,14 @@ declare class EditorView {
907
907
  */
908
908
  coordsAtPos(pos: number, side?: -1 | 1): Rect | null;
909
909
  /**
910
+ Return the rectangle around a given character. If `pos` does not
911
+ point in front of a character that is in the viewport and
912
+ rendered (i.e. not replaced, not a line break), this will return
913
+ null. For space characters that are a line wrap point, this will
914
+ return the position before the line break.
915
+ */
916
+ coordsForChar(pos: number): Rect | null;
917
+ /**
910
918
  The default width of a character in the editor. May not
911
919
  accurately reflect the width of all characters (given variable
912
920
  width fonts or styling of invididual ranges).
package/dist/index.js CHANGED
@@ -2817,6 +2817,28 @@ class DocView extends ContentView {
2817
2817
  off = start;
2818
2818
  }
2819
2819
  }
2820
+ coordsForChar(pos) {
2821
+ let { i, off } = this.childPos(pos, 1), child = this.children[i];
2822
+ if (!(child instanceof LineView))
2823
+ return null;
2824
+ while (child.children.length) {
2825
+ let { i, off: childOff } = child.childPos(off, 1);
2826
+ for (;; i++) {
2827
+ if (i == child.children.length)
2828
+ return null;
2829
+ if ((child = child.children[i]).length)
2830
+ break;
2831
+ }
2832
+ off = childOff;
2833
+ }
2834
+ if (!(child instanceof TextView))
2835
+ return null;
2836
+ let end = findClusterBreak(child.text, off);
2837
+ if (end == off)
2838
+ return null;
2839
+ let rects = textRange(child.dom, off, end).getClientRects();
2840
+ return !rects.length || rects[0].top >= rects[0].bottom ? null : rects[0];
2841
+ }
2820
2842
  measureVisibleLineHeights(viewport) {
2821
2843
  let result = [], { from, to } = viewport;
2822
2844
  let contentWidth = this.view.contentDOM.clientWidth;
@@ -5688,7 +5710,7 @@ const baseTheme$1 = /*@__PURE__*/buildTheme("." + baseThemeID, {
5688
5710
  display: "flex",
5689
5711
  height: "100%",
5690
5712
  boxSizing: "border-box",
5691
- left: 0,
5713
+ insetInlineStart: 0,
5692
5714
  zIndex: 200
5693
5715
  },
5694
5716
  "&light .cm-gutters": {
@@ -7152,6 +7174,17 @@ class EditorView {
7152
7174
  return flattenRect(rect, (span.dir == Direction.LTR) == (side > 0));
7153
7175
  }
7154
7176
  /**
7177
+ Return the rectangle around a given character. If `pos` does not
7178
+ point in front of a character that is in the viewport and
7179
+ rendered (i.e. not replaced, not a line break), this will return
7180
+ null. For space characters that are a line wrap point, this will
7181
+ return the position before the line break.
7182
+ */
7183
+ coordsForChar(pos) {
7184
+ this.readMeasured();
7185
+ return this.docView.coordsForChar(pos);
7186
+ }
7187
+ /**
7155
7188
  The default width of a character in the editor. May not
7156
7189
  accurately reflect the width of all characters (given variable
7157
7190
  width fonts or styling of invididual ranges).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.15.3",
3
+ "version": "6.16.0",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",