@codemirror/view 6.36.5 → 6.36.6

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.36.6 (2025-04-24)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where `drawSelection` would draw selections starting at a block widget not at a line break in an odd way.
6
+
7
+ Fix an issue where the editor would inappropriately scroll when editing near the bottom of the document with line wrapping enabled, in some cases.
8
+
9
+ Fix an issue that caused unnecessary transactions on focus change.
10
+
1
11
  ## 6.36.5 (2025-03-29)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -3660,17 +3660,26 @@ function isSuspiciousChromeCaretResult(node, offset, x) {
3660
3660
  : textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
3661
3661
  return x - rect.left > 5;
3662
3662
  }
3663
- function blockAt(view, pos) {
3663
+ function blockAt(view, pos, side) {
3664
3664
  let line = view.lineBlockAt(pos);
3665
- if (Array.isArray(line.type))
3665
+ if (Array.isArray(line.type)) {
3666
+ let best;
3666
3667
  for (let l of line.type) {
3667
- if (l.to > pos || l.to == pos && (l.to == line.to || l.type == exports.BlockType.Text))
3668
+ if (l.from > pos)
3669
+ break;
3670
+ if (l.to < pos)
3671
+ continue;
3672
+ if (l.from < pos && l.to > pos)
3668
3673
  return l;
3674
+ if (!best || (l.type == exports.BlockType.Text && (best.type != l.type || (side < 0 ? l.from < pos : l.to > pos))))
3675
+ best = l;
3669
3676
  }
3677
+ return best || line;
3678
+ }
3670
3679
  return line;
3671
3680
  }
3672
3681
  function moveToLineBoundary(view, start, forward, includeWrap) {
3673
- let line = blockAt(view, start.head);
3682
+ let line = blockAt(view, start.head, start.assoc || -1);
3674
3683
  let coords = !includeWrap || line.type != exports.BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null
3675
3684
  : view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
3676
3685
  if (coords) {
@@ -4905,7 +4914,7 @@ function focusChangeTransaction(state, focus) {
4905
4914
  if (effect)
4906
4915
  effects.push(effect);
4907
4916
  }
4908
- return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
4917
+ return effects.length ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
4909
4918
  }
4910
4919
  function updateForFocusChange(view) {
4911
4920
  setTimeout(() => {
@@ -5941,7 +5950,7 @@ class ViewState {
5941
5950
  }
5942
5951
  else {
5943
5952
  this.scrollAnchorPos = -1;
5944
- this.scrollAnchorHeight = this.heightMap.height;
5953
+ this.scrollAnchorHeight = prevHeight;
5945
5954
  }
5946
5955
  let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
5947
5956
  if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) ||
@@ -8871,7 +8880,7 @@ function rectanglesForRange(view, className, range) {
8871
8880
  let leftSide = contentRect.left +
8872
8881
  (lineStyle ? parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent)) : 0);
8873
8882
  let rightSide = contentRect.right - (lineStyle ? parseInt(lineStyle.paddingRight) : 0);
8874
- let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
8883
+ let startBlock = blockAt(view, from, 1), endBlock = blockAt(view, to, -1);
8875
8884
  let visualStart = startBlock.type == exports.BlockType.Text ? startBlock : null;
8876
8885
  let visualEnd = endBlock.type == exports.BlockType.Text ? endBlock : null;
8877
8886
  if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
package/dist/index.js CHANGED
@@ -3656,17 +3656,26 @@ function isSuspiciousChromeCaretResult(node, offset, x) {
3656
3656
  : textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
3657
3657
  return x - rect.left > 5;
3658
3658
  }
3659
- function blockAt(view, pos) {
3659
+ function blockAt(view, pos, side) {
3660
3660
  let line = view.lineBlockAt(pos);
3661
- if (Array.isArray(line.type))
3661
+ if (Array.isArray(line.type)) {
3662
+ let best;
3662
3663
  for (let l of line.type) {
3663
- if (l.to > pos || l.to == pos && (l.to == line.to || l.type == BlockType.Text))
3664
+ if (l.from > pos)
3665
+ break;
3666
+ if (l.to < pos)
3667
+ continue;
3668
+ if (l.from < pos && l.to > pos)
3664
3669
  return l;
3670
+ if (!best || (l.type == BlockType.Text && (best.type != l.type || (side < 0 ? l.from < pos : l.to > pos))))
3671
+ best = l;
3665
3672
  }
3673
+ return best || line;
3674
+ }
3666
3675
  return line;
3667
3676
  }
3668
3677
  function moveToLineBoundary(view, start, forward, includeWrap) {
3669
- let line = blockAt(view, start.head);
3678
+ let line = blockAt(view, start.head, start.assoc || -1);
3670
3679
  let coords = !includeWrap || line.type != BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null
3671
3680
  : view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
3672
3681
  if (coords) {
@@ -4901,7 +4910,7 @@ function focusChangeTransaction(state, focus) {
4901
4910
  if (effect)
4902
4911
  effects.push(effect);
4903
4912
  }
4904
- return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
4913
+ return effects.length ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
4905
4914
  }
4906
4915
  function updateForFocusChange(view) {
4907
4916
  setTimeout(() => {
@@ -5936,7 +5945,7 @@ class ViewState {
5936
5945
  }
5937
5946
  else {
5938
5947
  this.scrollAnchorPos = -1;
5939
- this.scrollAnchorHeight = this.heightMap.height;
5948
+ this.scrollAnchorHeight = prevHeight;
5940
5949
  }
5941
5950
  let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
5942
5951
  if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) ||
@@ -8866,7 +8875,7 @@ function rectanglesForRange(view, className, range) {
8866
8875
  let leftSide = contentRect.left +
8867
8876
  (lineStyle ? parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent)) : 0);
8868
8877
  let rightSide = contentRect.right - (lineStyle ? parseInt(lineStyle.paddingRight) : 0);
8869
- let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
8878
+ let startBlock = blockAt(view, from, 1), endBlock = blockAt(view, to, -1);
8870
8879
  let visualStart = startBlock.type == BlockType.Text ? startBlock : null;
8871
8880
  let visualEnd = endBlock.type == BlockType.Text ? endBlock : null;
8872
8881
  if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.36.5",
3
+ "version": "6.36.6",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",