@codemirror/view 6.19.0 → 6.20.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,21 @@
1
+ ## 6.20.0 (2023-09-20)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue that caused `repositionTooltips` to crash when it was called on an editor without tooltips.
6
+
7
+ Fix an issue that caused the tooltip system to leave empty nodes in the DOM when an editor using the `parent` option to `tooltips` is destroyed.
8
+
9
+ Fix a bug that regression mouse interaction with the area of a fixed-size editor that isn't covered by the content.
10
+
11
+ Fix some issues with the way `moveVertically` behaved for positions on line wrap points.
12
+
13
+ Fix a bug that could cause the document DOM to be incorrectly updated on some types of viewport changes.
14
+
15
+ ### New features
16
+
17
+ The new `getDrawSelectionConfig` function returns the `drawSelection` configuration for a given state.
18
+
1
19
  ## 6.19.0 (2023-09-14)
2
20
 
3
21
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -581,7 +581,7 @@ function replaceRange(parent, fromI, fromOff, toI, toOff, insert, breakAtStart,
581
581
  if (toI < children.length) {
582
582
  let after = children[toI];
583
583
  // Make sure the end of the child after the update is preserved in `after`
584
- if (after && toOff < after.length) {
584
+ if (after && (toOff < after.length || after.breakAfter && (last === null || last === void 0 ? void 0 : last.breakAfter))) {
585
585
  // If we're splitting a child, separate part of it to avoid that
586
586
  // being mangled when updating the child before the update.
587
587
  if (fromI == toI) {
@@ -3544,7 +3544,7 @@ function moveVertically(view, start, forward, distance) {
3544
3544
  return state.EditorSelection.cursor(startPos, start.assoc);
3545
3545
  let goal = start.goalColumn, startY;
3546
3546
  let rect = view.contentDOM.getBoundingClientRect();
3547
- let startCoords = view.coordsAtPos(startPos), docTop = view.documentTop;
3547
+ let startCoords = view.coordsAtPos(startPos, start.assoc || -1), docTop = view.documentTop;
3548
3548
  if (startCoords) {
3549
3549
  if (goal == null)
3550
3550
  goal = startCoords.left - rect.left;
@@ -3561,8 +3561,11 @@ function moveVertically(view, start, forward, distance) {
3561
3561
  for (let extra = 0;; extra += 10) {
3562
3562
  let curY = startY + (dist + extra) * dir;
3563
3563
  let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
3564
- if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos))
3565
- return state.EditorSelection.cursor(pos, start.assoc, undefined, goal);
3564
+ if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos)) {
3565
+ let charRect = view.docView.coordsForChar(pos);
3566
+ let assoc = !charRect || curY < charRect.top ? -1 : 1;
3567
+ return state.EditorSelection.cursor(pos, assoc, undefined, goal);
3568
+ }
3566
3569
  }
3567
3570
  }
3568
3571
  function skipAtomicRanges(atoms, pos, bias) {
@@ -3633,7 +3636,7 @@ class InputState {
3633
3636
  this.handleEvent = this.handleEvent.bind(this);
3634
3637
  view.scrollDOM.addEventListener("mousedown", (event) => {
3635
3638
  if (event.target == view.scrollDOM && event.clientY > view.contentDOM.getBoundingClientRect().bottom) {
3636
- this.handleEvent(event);
3639
+ this.runHandlers("mousedown", event);
3637
3640
  if (!event.defaultPrevented && event.button == 2) {
3638
3641
  // Make sure the content covers the entire scroller height, in order
3639
3642
  // to catch a native context menu click below it
@@ -3645,7 +3648,7 @@ class InputState {
3645
3648
  });
3646
3649
  view.scrollDOM.addEventListener("drop", (event) => {
3647
3650
  if (event.target == view.scrollDOM && event.clientY > view.contentDOM.getBoundingClientRect().bottom)
3648
- this.handleEvent(event);
3651
+ this.runHandlers("drop", event);
3649
3652
  });
3650
3653
  this.notifiedFocused = view.hasFocus;
3651
3654
  // On Safari adding an input event handler somehow prevents an
@@ -8346,6 +8349,14 @@ function drawSelection(config = {}) {
8346
8349
  nativeSelectionHidden.of(true)
8347
8350
  ];
8348
8351
  }
8352
+ /**
8353
+ Retrieve the [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) configuration
8354
+ for this state. (Note that this will return a set of defaults even
8355
+ if `drawSelection` isn't enabled.)
8356
+ */
8357
+ function getDrawSelectionConfig(state) {
8358
+ return state.facet(selectionConfig);
8359
+ }
8349
8360
  function configChanged(update) {
8350
8361
  return update.startState.facet(selectionConfig) != update.state.facet(selectionConfig);
8351
8362
  }
@@ -9170,6 +9181,8 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
9170
9181
  tooltipView.dom.remove();
9171
9182
  (_a = tooltipView.destroy) === null || _a === void 0 ? void 0 : _a.call(tooltipView);
9172
9183
  }
9184
+ if (this.parent)
9185
+ this.container.remove();
9173
9186
  (_b = this.intersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9174
9187
  clearTimeout(this.measureTimeout);
9175
9188
  }
@@ -9611,8 +9624,9 @@ re-positioning or CSS change affecting the editor) that could
9611
9624
  invalidate the existing tooltip positions.
9612
9625
  */
9613
9626
  function repositionTooltips(view) {
9614
- var _a;
9615
- (_a = view.plugin(tooltipPlugin)) === null || _a === void 0 ? void 0 : _a.maybeMeasure();
9627
+ let plugin = view.plugin(tooltipPlugin);
9628
+ if (plugin)
9629
+ plugin.maybeMeasure();
9616
9630
  }
9617
9631
 
9618
9632
  const panelConfig = state.Facet.define({
@@ -10330,6 +10344,7 @@ exports.closeHoverTooltips = closeHoverTooltips;
10330
10344
  exports.crosshairCursor = crosshairCursor;
10331
10345
  exports.drawSelection = drawSelection;
10332
10346
  exports.dropCursor = dropCursor;
10347
+ exports.getDrawSelectionConfig = getDrawSelectionConfig;
10333
10348
  exports.getPanel = getPanel;
10334
10349
  exports.getTooltip = getTooltip;
10335
10350
  exports.gutter = gutter;
package/dist/index.d.cts CHANGED
@@ -1414,6 +1414,12 @@ layout information that's only available after laying out the
1414
1414
  content).
1415
1415
  */
1416
1416
  declare function drawSelection(config?: SelectionConfig): Extension;
1417
+ /**
1418
+ Retrieve the [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) configuration
1419
+ for this state. (Note that this will return a set of defaults even
1420
+ if `drawSelection` isn't enabled.)
1421
+ */
1422
+ declare function getDrawSelectionConfig(state: EditorState): SelectionConfig;
1417
1423
 
1418
1424
  /**
1419
1425
  Draws a cursor at the current drop position when something is
@@ -2050,4 +2056,4 @@ trailing whitespace.
2050
2056
  */
2051
2057
  declare function highlightTrailingWhitespace(): Extension;
2052
2058
 
2053
- export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, EditorViewConfig, GutterMarker, KeyBinding, LayerMarker, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, RectangleMarker, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
2059
+ export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, EditorViewConfig, GutterMarker, KeyBinding, LayerMarker, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, RectangleMarker, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
package/dist/index.d.ts CHANGED
@@ -1414,6 +1414,12 @@ layout information that's only available after laying out the
1414
1414
  content).
1415
1415
  */
1416
1416
  declare function drawSelection(config?: SelectionConfig): Extension;
1417
+ /**
1418
+ Retrieve the [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) configuration
1419
+ for this state. (Note that this will return a set of defaults even
1420
+ if `drawSelection` isn't enabled.)
1421
+ */
1422
+ declare function getDrawSelectionConfig(state: EditorState): SelectionConfig;
1417
1423
 
1418
1424
  /**
1419
1425
  Draws a cursor at the current drop position when something is
@@ -2050,4 +2056,4 @@ trailing whitespace.
2050
2056
  */
2051
2057
  declare function highlightTrailingWhitespace(): Extension;
2052
2058
 
2053
- export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, EditorViewConfig, GutterMarker, KeyBinding, LayerMarker, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, RectangleMarker, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
2059
+ export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, EditorViewConfig, GutterMarker, KeyBinding, LayerMarker, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, RectangleMarker, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
package/dist/index.js CHANGED
@@ -579,7 +579,7 @@ function replaceRange(parent, fromI, fromOff, toI, toOff, insert, breakAtStart,
579
579
  if (toI < children.length) {
580
580
  let after = children[toI];
581
581
  // Make sure the end of the child after the update is preserved in `after`
582
- if (after && toOff < after.length) {
582
+ if (after && (toOff < after.length || after.breakAfter && (last === null || last === void 0 ? void 0 : last.breakAfter))) {
583
583
  // If we're splitting a child, separate part of it to avoid that
584
584
  // being mangled when updating the child before the update.
585
585
  if (fromI == toI) {
@@ -3540,7 +3540,7 @@ function moveVertically(view, start, forward, distance) {
3540
3540
  return EditorSelection.cursor(startPos, start.assoc);
3541
3541
  let goal = start.goalColumn, startY;
3542
3542
  let rect = view.contentDOM.getBoundingClientRect();
3543
- let startCoords = view.coordsAtPos(startPos), docTop = view.documentTop;
3543
+ let startCoords = view.coordsAtPos(startPos, start.assoc || -1), docTop = view.documentTop;
3544
3544
  if (startCoords) {
3545
3545
  if (goal == null)
3546
3546
  goal = startCoords.left - rect.left;
@@ -3557,8 +3557,11 @@ function moveVertically(view, start, forward, distance) {
3557
3557
  for (let extra = 0;; extra += 10) {
3558
3558
  let curY = startY + (dist + extra) * dir;
3559
3559
  let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
3560
- if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos))
3561
- return EditorSelection.cursor(pos, start.assoc, undefined, goal);
3560
+ if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos)) {
3561
+ let charRect = view.docView.coordsForChar(pos);
3562
+ let assoc = !charRect || curY < charRect.top ? -1 : 1;
3563
+ return EditorSelection.cursor(pos, assoc, undefined, goal);
3564
+ }
3562
3565
  }
3563
3566
  }
3564
3567
  function skipAtomicRanges(atoms, pos, bias) {
@@ -3629,7 +3632,7 @@ class InputState {
3629
3632
  this.handleEvent = this.handleEvent.bind(this);
3630
3633
  view.scrollDOM.addEventListener("mousedown", (event) => {
3631
3634
  if (event.target == view.scrollDOM && event.clientY > view.contentDOM.getBoundingClientRect().bottom) {
3632
- this.handleEvent(event);
3635
+ this.runHandlers("mousedown", event);
3633
3636
  if (!event.defaultPrevented && event.button == 2) {
3634
3637
  // Make sure the content covers the entire scroller height, in order
3635
3638
  // to catch a native context menu click below it
@@ -3641,7 +3644,7 @@ class InputState {
3641
3644
  });
3642
3645
  view.scrollDOM.addEventListener("drop", (event) => {
3643
3646
  if (event.target == view.scrollDOM && event.clientY > view.contentDOM.getBoundingClientRect().bottom)
3644
- this.handleEvent(event);
3647
+ this.runHandlers("drop", event);
3645
3648
  });
3646
3649
  this.notifiedFocused = view.hasFocus;
3647
3650
  // On Safari adding an input event handler somehow prevents an
@@ -8341,6 +8344,14 @@ function drawSelection(config = {}) {
8341
8344
  nativeSelectionHidden.of(true)
8342
8345
  ];
8343
8346
  }
8347
+ /**
8348
+ Retrieve the [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) configuration
8349
+ for this state. (Note that this will return a set of defaults even
8350
+ if `drawSelection` isn't enabled.)
8351
+ */
8352
+ function getDrawSelectionConfig(state) {
8353
+ return state.facet(selectionConfig);
8354
+ }
8344
8355
  function configChanged(update) {
8345
8356
  return update.startState.facet(selectionConfig) != update.state.facet(selectionConfig);
8346
8357
  }
@@ -9165,6 +9176,8 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
9165
9176
  tooltipView.dom.remove();
9166
9177
  (_a = tooltipView.destroy) === null || _a === void 0 ? void 0 : _a.call(tooltipView);
9167
9178
  }
9179
+ if (this.parent)
9180
+ this.container.remove();
9168
9181
  (_b = this.intersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
9169
9182
  clearTimeout(this.measureTimeout);
9170
9183
  }
@@ -9606,8 +9619,9 @@ re-positioning or CSS change affecting the editor) that could
9606
9619
  invalidate the existing tooltip positions.
9607
9620
  */
9608
9621
  function repositionTooltips(view) {
9609
- var _a;
9610
- (_a = view.plugin(tooltipPlugin)) === null || _a === void 0 ? void 0 : _a.maybeMeasure();
9622
+ let plugin = view.plugin(tooltipPlugin);
9623
+ if (plugin)
9624
+ plugin.maybeMeasure();
9611
9625
  }
9612
9626
 
9613
9627
  const panelConfig = /*@__PURE__*/Facet.define({
@@ -10310,4 +10324,4 @@ function highlightTrailingWhitespace() {
10310
10324
  */
10311
10325
  const __test = { HeightMap, HeightOracle, MeasuredHeights, QueryType, ChangedRange, computeOrder, moveVisually };
10312
10326
 
10313
- export { BidiSpan, BlockInfo, BlockType, Decoration, Direction, EditorView, GutterMarker, MatchDecorator, RectangleMarker, ViewPlugin, ViewUpdate, WidgetType, __test, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
10327
+ export { BidiSpan, BlockInfo, BlockType, Decoration, Direction, EditorView, GutterMarker, MatchDecorator, RectangleMarker, ViewPlugin, ViewUpdate, WidgetType, __test, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.19.0",
3
+ "version": "6.20.0",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",