@codemirror/view 6.36.3 → 6.36.4

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,9 @@
1
+ ## 6.36.4 (2025-03-03)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where scrolling down to a range higher than the viewport could in some situations fail to scroll to the proper position.
6
+
1
7
  ## 6.36.3 (2025-02-18)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -133,14 +133,14 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
133
133
  let moveX = 0, moveY = 0;
134
134
  if (y == "nearest") {
135
135
  if (rect.top < bounding.top) {
136
- moveY = -(bounding.top - rect.top + yMargin);
136
+ moveY = rect.top - (bounding.top + yMargin);
137
137
  if (side > 0 && rect.bottom > bounding.bottom + moveY)
138
- moveY = rect.bottom - bounding.bottom + moveY + yMargin;
138
+ moveY = rect.bottom - bounding.bottom + yMargin;
139
139
  }
140
140
  else if (rect.bottom > bounding.bottom) {
141
141
  moveY = rect.bottom - bounding.bottom + yMargin;
142
142
  if (side < 0 && (rect.top - moveY) < bounding.top)
143
- moveY = -(bounding.top + moveY - rect.top + yMargin);
143
+ moveY = rect.top - (bounding.top + yMargin);
144
144
  }
145
145
  }
146
146
  else {
@@ -152,14 +152,14 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
152
152
  }
153
153
  if (x == "nearest") {
154
154
  if (rect.left < bounding.left) {
155
- moveX = -(bounding.left - rect.left + xMargin);
155
+ moveX = rect.left - (bounding.left + xMargin);
156
156
  if (side > 0 && rect.right > bounding.right + moveX)
157
- moveX = rect.right - bounding.right + moveX + xMargin;
157
+ moveX = rect.right - bounding.right + xMargin;
158
158
  }
159
159
  else if (rect.right > bounding.right) {
160
160
  moveX = rect.right - bounding.right + xMargin;
161
161
  if (side < 0 && rect.left < bounding.left + moveX)
162
- moveX = -(bounding.left + moveX - rect.left + xMargin);
162
+ moveX = rect.left - (bounding.left + xMargin);
163
163
  }
164
164
  }
165
165
  else {
@@ -194,6 +194,10 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
194
194
  }
195
195
  if (top)
196
196
  break;
197
+ if (rect.top < bounding.top || rect.bottom > bounding.bottom ||
198
+ rect.left < bounding.left || rect.right > bounding.right)
199
+ rect = { left: Math.max(rect.left, bounding.left), right: Math.min(rect.right, bounding.right),
200
+ top: Math.max(rect.top, bounding.top), bottom: Math.min(rect.bottom, bounding.bottom) };
197
201
  cur = cur.assignedSlot || cur.parentNode;
198
202
  }
199
203
  else if (cur.nodeType == 11) { // A shadow root
package/dist/index.js CHANGED
@@ -131,14 +131,14 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
131
131
  let moveX = 0, moveY = 0;
132
132
  if (y == "nearest") {
133
133
  if (rect.top < bounding.top) {
134
- moveY = -(bounding.top - rect.top + yMargin);
134
+ moveY = rect.top - (bounding.top + yMargin);
135
135
  if (side > 0 && rect.bottom > bounding.bottom + moveY)
136
- moveY = rect.bottom - bounding.bottom + moveY + yMargin;
136
+ moveY = rect.bottom - bounding.bottom + yMargin;
137
137
  }
138
138
  else if (rect.bottom > bounding.bottom) {
139
139
  moveY = rect.bottom - bounding.bottom + yMargin;
140
140
  if (side < 0 && (rect.top - moveY) < bounding.top)
141
- moveY = -(bounding.top + moveY - rect.top + yMargin);
141
+ moveY = rect.top - (bounding.top + yMargin);
142
142
  }
143
143
  }
144
144
  else {
@@ -150,14 +150,14 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
150
150
  }
151
151
  if (x == "nearest") {
152
152
  if (rect.left < bounding.left) {
153
- moveX = -(bounding.left - rect.left + xMargin);
153
+ moveX = rect.left - (bounding.left + xMargin);
154
154
  if (side > 0 && rect.right > bounding.right + moveX)
155
- moveX = rect.right - bounding.right + moveX + xMargin;
155
+ moveX = rect.right - bounding.right + xMargin;
156
156
  }
157
157
  else if (rect.right > bounding.right) {
158
158
  moveX = rect.right - bounding.right + xMargin;
159
159
  if (side < 0 && rect.left < bounding.left + moveX)
160
- moveX = -(bounding.left + moveX - rect.left + xMargin);
160
+ moveX = rect.left - (bounding.left + xMargin);
161
161
  }
162
162
  }
163
163
  else {
@@ -192,6 +192,10 @@ function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
192
192
  }
193
193
  if (top)
194
194
  break;
195
+ if (rect.top < bounding.top || rect.bottom > bounding.bottom ||
196
+ rect.left < bounding.left || rect.right > bounding.right)
197
+ rect = { left: Math.max(rect.left, bounding.left), right: Math.min(rect.right, bounding.right),
198
+ top: Math.max(rect.top, bounding.top), bottom: Math.min(rect.bottom, bounding.bottom) };
195
199
  cur = cur.assignedSlot || cur.parentNode;
196
200
  }
197
201
  else if (cur.nodeType == 11) { // A shadow root
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.36.3",
3
+ "version": "6.36.4",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",