@codemirror/view 6.4.2 → 6.5.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.5.1 (2022-11-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused marked unnecessary splitting of mark decoration DOM elements in some cases.
6
+
7
+ ## 6.5.0 (2022-11-14)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue where key bindings were activated for the wrong key in some situations with non-US keyboards.
12
+
13
+ ### New features
14
+
15
+ A tooltip's `positioned` callback is now passed the available space for tooltips.
16
+
1
17
  ## 6.4.2 (2022-11-10)
2
18
 
3
19
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1669,7 +1669,7 @@ class ContentBuilder {
1669
1669
  }
1670
1670
  }
1671
1671
  let take = Math.min(this.text.length - this.textOff, length, 512 /* T.Chunk */);
1672
- this.flushBuffer(active.slice(0, openStart));
1672
+ this.flushBuffer(active.slice(active.length - openStart));
1673
1673
  this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
1674
1674
  this.atCursorPos = true;
1675
1675
  this.textOff += take;
@@ -4038,9 +4038,9 @@ handlers.beforeinput = (view, event) => {
4038
4038
 
4039
4039
  const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
4040
4040
  class HeightOracle {
4041
- constructor() {
4041
+ constructor(lineWrapping) {
4042
+ this.lineWrapping = lineWrapping;
4042
4043
  this.doc = state.Text.empty;
4043
- this.lineWrapping = false;
4044
4044
  this.heightSamples = {};
4045
4045
  this.lineHeight = 14;
4046
4046
  this.charWidth = 7;
@@ -4780,7 +4780,6 @@ class ViewState {
4780
4780
  this.contentDOMHeight = 0;
4781
4781
  this.editorHeight = 0;
4782
4782
  this.editorWidth = 0;
4783
- this.heightOracle = new HeightOracle;
4784
4783
  // See VP.MaxDOMHeight
4785
4784
  this.scaler = IdScaler;
4786
4785
  this.scrollTarget = null;
@@ -4800,6 +4799,8 @@ class ViewState {
4800
4799
  // boundary and, if so, reset it to make sure it is positioned in
4801
4800
  // the right place.
4802
4801
  this.mustEnforceCursorAssoc = false;
4802
+ let guessWrapping = state$1.facet(contentAttributes).some(v => typeof v != "function" && v.class == "cm-lineWrapping");
4803
+ this.heightOracle = new HeightOracle(guessWrapping);
4803
4804
  this.stateDeco = state$1.facet(decorations).filter(d => typeof d != "function");
4804
4805
  this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, state.Text.empty, this.heightOracle.setDoc(state$1.doc), [new ChangedRange(0, 0, 0, state$1.doc.length)]);
4805
4806
  this.viewport = this.getViewport(0, null);
@@ -5484,7 +5485,10 @@ class DOMChange {
5484
5485
  this.bounds = null;
5485
5486
  this.text = "";
5486
5487
  let { impreciseHead: iHead, impreciseAnchor: iAnchor } = view.docView;
5487
- if (view.state.readOnly && start > -1) ;
5488
+ if (view.state.readOnly && start > -1) {
5489
+ // Ignore changes when the editor is read-only
5490
+ this.newSel = null;
5491
+ }
5488
5492
  else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) {
5489
5493
  let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
5490
5494
  let reader = new DOMReader(selPoints, view.state);
@@ -7272,7 +7276,7 @@ function runHandlers(map, event, view, scope) {
7272
7276
  if (scopeObj) {
7273
7277
  if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
7274
7278
  return true;
7275
- if (isChar && (event.shiftKey || event.altKey || event.metaKey || charCode > 127) &&
7279
+ if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
7276
7280
  (baseName = w3cKeyname.base[event.keyCode]) && baseName != name) {
7277
7281
  if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
7278
7282
  return true;
@@ -8353,7 +8357,7 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
8353
8357
  dom.classList.toggle("cm-tooltip-above", above);
8354
8358
  dom.classList.toggle("cm-tooltip-below", !above);
8355
8359
  if (tView.positioned)
8356
- tView.positioned();
8360
+ tView.positioned(measured.space);
8357
8361
  }
8358
8362
  }
8359
8363
  maybeMeasure() {
@@ -8469,10 +8473,10 @@ class HoverTooltipHost {
8469
8473
  }
8470
8474
  this.mounted = true;
8471
8475
  }
8472
- positioned() {
8476
+ positioned(space) {
8473
8477
  for (let hostedView of this.manager.tooltipViews) {
8474
8478
  if (hostedView.positioned)
8475
- hostedView.positioned();
8479
+ hostedView.positioned(space);
8476
8480
  }
8477
8481
  }
8478
8482
  update(update) {
package/dist/index.d.ts CHANGED
@@ -1491,12 +1491,7 @@ declare function tooltips(config?: {
1491
1491
  for showing tooltips. You can provide a function here that
1492
1492
  returns an alternative rectangle.
1493
1493
  */
1494
- tooltipSpace?: (view: EditorView) => {
1495
- top: number;
1496
- left: number;
1497
- bottom: number;
1498
- right: number;
1499
- };
1494
+ tooltipSpace?: (view: EditorView) => Rect;
1500
1495
  }): Extension;
1501
1496
  /**
1502
1497
  Describes a tooltip. Values of this type, when provided through
@@ -1584,9 +1579,11 @@ interface TooltipView {
1584
1579
  */
1585
1580
  destroy?(): void;
1586
1581
  /**
1587
- Called when the tooltip has been (re)positioned.
1582
+ Called when the tooltip has been (re)positioned. The argument is
1583
+ the [space](https://codemirror.net/6/docs/ref/#view.tooltips^config.tooltipSpace) available to the
1584
+ tooltip.
1588
1585
  */
1589
- positioned?(): void;
1586
+ positioned?(space: Rect): void;
1590
1587
  }
1591
1588
  /**
1592
1589
  Facet to which an extension can add a value to show a tooltip.
package/dist/index.js CHANGED
@@ -1664,7 +1664,7 @@ class ContentBuilder {
1664
1664
  }
1665
1665
  }
1666
1666
  let take = Math.min(this.text.length - this.textOff, length, 512 /* T.Chunk */);
1667
- this.flushBuffer(active.slice(0, openStart));
1667
+ this.flushBuffer(active.slice(active.length - openStart));
1668
1668
  this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
1669
1669
  this.atCursorPos = true;
1670
1670
  this.textOff += take;
@@ -4032,9 +4032,9 @@ handlers.beforeinput = (view, event) => {
4032
4032
 
4033
4033
  const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
4034
4034
  class HeightOracle {
4035
- constructor() {
4035
+ constructor(lineWrapping) {
4036
+ this.lineWrapping = lineWrapping;
4036
4037
  this.doc = Text.empty;
4037
- this.lineWrapping = false;
4038
4038
  this.heightSamples = {};
4039
4039
  this.lineHeight = 14;
4040
4040
  this.charWidth = 7;
@@ -4773,7 +4773,6 @@ class ViewState {
4773
4773
  this.contentDOMHeight = 0;
4774
4774
  this.editorHeight = 0;
4775
4775
  this.editorWidth = 0;
4776
- this.heightOracle = new HeightOracle;
4777
4776
  // See VP.MaxDOMHeight
4778
4777
  this.scaler = IdScaler;
4779
4778
  this.scrollTarget = null;
@@ -4793,6 +4792,8 @@ class ViewState {
4793
4792
  // boundary and, if so, reset it to make sure it is positioned in
4794
4793
  // the right place.
4795
4794
  this.mustEnforceCursorAssoc = false;
4795
+ let guessWrapping = state.facet(contentAttributes).some(v => typeof v != "function" && v.class == "cm-lineWrapping");
4796
+ this.heightOracle = new HeightOracle(guessWrapping);
4796
4797
  this.stateDeco = state.facet(decorations).filter(d => typeof d != "function");
4797
4798
  this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle.setDoc(state.doc), [new ChangedRange(0, 0, 0, state.doc.length)]);
4798
4799
  this.viewport = this.getViewport(0, null);
@@ -5477,7 +5478,10 @@ class DOMChange {
5477
5478
  this.bounds = null;
5478
5479
  this.text = "";
5479
5480
  let { impreciseHead: iHead, impreciseAnchor: iAnchor } = view.docView;
5480
- if (view.state.readOnly && start > -1) ;
5481
+ if (view.state.readOnly && start > -1) {
5482
+ // Ignore changes when the editor is read-only
5483
+ this.newSel = null;
5484
+ }
5481
5485
  else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) {
5482
5486
  let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
5483
5487
  let reader = new DOMReader(selPoints, view.state);
@@ -7265,7 +7269,7 @@ function runHandlers(map, event, view, scope) {
7265
7269
  if (scopeObj) {
7266
7270
  if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
7267
7271
  return true;
7268
- if (isChar && (event.shiftKey || event.altKey || event.metaKey || charCode > 127) &&
7272
+ if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
7269
7273
  (baseName = base[event.keyCode]) && baseName != name) {
7270
7274
  if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
7271
7275
  return true;
@@ -8346,7 +8350,7 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
8346
8350
  dom.classList.toggle("cm-tooltip-above", above);
8347
8351
  dom.classList.toggle("cm-tooltip-below", !above);
8348
8352
  if (tView.positioned)
8349
- tView.positioned();
8353
+ tView.positioned(measured.space);
8350
8354
  }
8351
8355
  }
8352
8356
  maybeMeasure() {
@@ -8462,10 +8466,10 @@ class HoverTooltipHost {
8462
8466
  }
8463
8467
  this.mounted = true;
8464
8468
  }
8465
- positioned() {
8469
+ positioned(space) {
8466
8470
  for (let hostedView of this.manager.tooltipViews) {
8467
8471
  if (hostedView.positioned)
8468
- hostedView.positioned();
8472
+ hostedView.positioned(space);
8469
8473
  }
8470
8474
  }
8471
8475
  update(update) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.4.2",
3
+ "version": "6.5.1",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@codemirror/state": "^6.0.0",
29
+ "@codemirror/state": "^6.1.4",
30
30
  "style-mod": "^4.0.0",
31
31
  "w3c-keyname": "^2.2.4"
32
32
  },