@codemirror/view 6.7.1 → 6.7.3

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,29 @@
1
+ ## 6.7.3 (2023-01-12)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug in `posAtCoords` that could cause incorrect results for positions to the left of a wrapped line.
6
+
7
+ ## 6.7.2 (2023-01-04)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix a regression where the cursor didn't restart its blink cycle when moving it with the pointer.
12
+
13
+ Even without a `key` property, measure request objects that are already scheduled will not be scheduled again by `requestMeasure`.
14
+
15
+ Fix an issue where keymaps incorrectly interpreted key events that used Ctrl+Alt modifiers to simulate AltGr on Windows.
16
+
17
+ Fix a bug where line decorations with a different `class` property would be treated as equal.
18
+
19
+ Fix a bug that caused `drawSelection` to not notice when it was reconfigured.
20
+
21
+ Fix a crash in the gutter extension caused by sharing of mutable arrays.
22
+
23
+ Fix a regression that caused touch selection on mobile platforms to not work in an uneditable editor.
24
+
25
+ Fix a bug where DOM events on the boundary between lines could get assigned to the wrong line.
26
+
1
27
  ## 6.7.1 (2022-12-12)
2
28
 
3
29
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1348,7 +1348,9 @@ class LineDecoration extends Decoration {
1348
1348
  super(-200000000 /* Side.Line */, -200000000 /* Side.Line */, null, spec);
1349
1349
  }
1350
1350
  eq(other) {
1351
- return other instanceof LineDecoration && attrsEq(this.spec.attributes, other.spec.attributes);
1351
+ return other instanceof LineDecoration &&
1352
+ this.spec.class == other.spec.class &&
1353
+ attrsEq(this.spec.attributes, other.spec.attributes);
1352
1354
  }
1353
1355
  range(from, to = from) {
1354
1356
  if (to != from)
@@ -3100,7 +3102,8 @@ function domPosAtCoords(parent, x, y) {
3100
3102
  closestRect = rect;
3101
3103
  closestX = dx;
3102
3104
  closestY = dy;
3103
- closestOverlap = !dx || (dx > 0 ? i < rects.length - 1 : i > 0);
3105
+ let side = dy ? (y < rect.top ? -1 : 1) : dx ? (x < rect.left ? -1 : 1) : 0;
3106
+ closestOverlap = !side || (side > 0 ? i < rects.length - 1 : i > 0);
3104
3107
  }
3105
3108
  if (dx == 0) {
3106
3109
  if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
@@ -5325,7 +5328,7 @@ function buildTheme(main, spec, scopes) {
5325
5328
  });
5326
5329
  }
5327
5330
  const baseTheme$1 = buildTheme("." + baseThemeID, {
5328
- "&.cm-editor": {
5331
+ "&": {
5329
5332
  position: "relative !important",
5330
5333
  boxSizing: "border-box",
5331
5334
  "&.cm-focused": {
@@ -5609,7 +5612,7 @@ function applyDOMChange(view, domChange) {
5609
5612
  insert: state.Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder)) };
5610
5613
  }
5611
5614
  }
5612
- else if (newSel && (!view.hasFocus || !view.state.facet(editable) || newSel.main.eq(sel))) {
5615
+ else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel.main.eq(sel))) {
5613
5616
  newSel = null;
5614
5617
  }
5615
5618
  if (!change && !newSel)
@@ -6673,6 +6676,8 @@ class EditorView {
6673
6676
  if (this.measureScheduled < 0)
6674
6677
  this.measureScheduled = this.win.requestAnimationFrame(() => this.measure());
6675
6678
  if (request) {
6679
+ if (this.measureRequests.indexOf(request) > -1)
6680
+ return;
6676
6681
  if (request.key != null)
6677
6682
  for (let i = 0; i < this.measureRequests.length; i++) {
6678
6683
  if (this.measureRequests[i].key === request.key) {
@@ -7356,6 +7361,8 @@ function runHandlers(map, event, view, scope) {
7356
7361
  if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
7357
7362
  return true;
7358
7363
  if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
7364
+ // Ctrl-Alt may be used for AltGr on Windows
7365
+ !(browser.windows && event.ctrlKey && event.altKey) &&
7359
7366
  (baseName = w3cKeyname.base[event.keyCode]) && baseName != name) {
7360
7367
  if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
7361
7368
  return true;
@@ -7650,7 +7657,7 @@ function drawSelection(config = {}) {
7650
7657
  ];
7651
7658
  }
7652
7659
  function configChanged(update) {
7653
- return update.startState.facet(selectionConfig) != update.startState.facet(selectionConfig);
7660
+ return update.startState.facet(selectionConfig) != update.state.facet(selectionConfig);
7654
7661
  }
7655
7662
  const cursorLayer = layer({
7656
7663
  above: true,
@@ -7669,7 +7676,7 @@ const cursorLayer = layer({
7669
7676
  return cursors;
7670
7677
  },
7671
7678
  update(update, dom) {
7672
- if (update.transactions.some(tr => tr.scrollIntoView))
7679
+ if (update.transactions.some(tr => tr.selection))
7673
7680
  dom.style.animationName = dom.style.animationName == "cm-blink" ? "cm-blink2" : "cm-blink";
7674
7681
  let confChange = configChanged(update);
7675
7682
  if (confChange)
@@ -9235,15 +9242,14 @@ class UpdateContext {
9235
9242
  constructor(gutter, viewport, height) {
9236
9243
  this.gutter = gutter;
9237
9244
  this.height = height;
9238
- this.localMarkers = [];
9239
9245
  this.i = 0;
9240
9246
  this.cursor = state.RangeSet.iter(gutter.markers, viewport.from);
9241
9247
  }
9242
9248
  line(view, line, extraMarkers) {
9243
- if (this.localMarkers.length)
9244
- this.localMarkers = [];
9245
- advanceCursor(this.cursor, this.localMarkers, line.from);
9246
- let localMarkers = extraMarkers.length ? this.localMarkers.concat(extraMarkers) : this.localMarkers;
9249
+ let localMarkers = [];
9250
+ advanceCursor(this.cursor, localMarkers, line.from);
9251
+ if (extraMarkers.length)
9252
+ localMarkers = localMarkers.concat(extraMarkers);
9247
9253
  let forLine = this.gutter.config.lineMarker(view, line, localMarkers);
9248
9254
  if (forLine)
9249
9255
  localMarkers.unshift(forLine);
@@ -9281,7 +9287,17 @@ class SingleGutterView {
9281
9287
  this.dom.className = "cm-gutter" + (this.config.class ? " " + this.config.class : "");
9282
9288
  for (let prop in config.domEventHandlers) {
9283
9289
  this.dom.addEventListener(prop, (event) => {
9284
- let line = view.lineBlockAtHeight(event.clientY - view.documentTop);
9290
+ let target = event.target, y;
9291
+ if (target != this.dom && this.dom.contains(target)) {
9292
+ while (target.parentNode != this.dom)
9293
+ target = target.parentNode;
9294
+ let rect = target.getBoundingClientRect();
9295
+ y = (rect.top + rect.bottom) / 2;
9296
+ }
9297
+ else {
9298
+ y = event.clientY;
9299
+ }
9300
+ let line = view.lineBlockAtHeight(y - view.documentTop);
9285
9301
  if (config.domEventHandlers[prop](view, line, event))
9286
9302
  event.preventDefault();
9287
9303
  });
package/dist/index.js CHANGED
@@ -1343,7 +1343,9 @@ class LineDecoration extends Decoration {
1343
1343
  super(-200000000 /* Side.Line */, -200000000 /* Side.Line */, null, spec);
1344
1344
  }
1345
1345
  eq(other) {
1346
- return other instanceof LineDecoration && attrsEq(this.spec.attributes, other.spec.attributes);
1346
+ return other instanceof LineDecoration &&
1347
+ this.spec.class == other.spec.class &&
1348
+ attrsEq(this.spec.attributes, other.spec.attributes);
1347
1349
  }
1348
1350
  range(from, to = from) {
1349
1351
  if (to != from)
@@ -3094,7 +3096,8 @@ function domPosAtCoords(parent, x, y) {
3094
3096
  closestRect = rect;
3095
3097
  closestX = dx;
3096
3098
  closestY = dy;
3097
- closestOverlap = !dx || (dx > 0 ? i < rects.length - 1 : i > 0);
3099
+ let side = dy ? (y < rect.top ? -1 : 1) : dx ? (x < rect.left ? -1 : 1) : 0;
3100
+ closestOverlap = !side || (side > 0 ? i < rects.length - 1 : i > 0);
3098
3101
  }
3099
3102
  if (dx == 0) {
3100
3103
  if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
@@ -5318,7 +5321,7 @@ function buildTheme(main, spec, scopes) {
5318
5321
  });
5319
5322
  }
5320
5323
  const baseTheme$1 = /*@__PURE__*/buildTheme("." + baseThemeID, {
5321
- "&.cm-editor": {
5324
+ "&": {
5322
5325
  position: "relative !important",
5323
5326
  boxSizing: "border-box",
5324
5327
  "&.cm-focused": {
@@ -5602,7 +5605,7 @@ function applyDOMChange(view, domChange) {
5602
5605
  insert: Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder)) };
5603
5606
  }
5604
5607
  }
5605
- else if (newSel && (!view.hasFocus || !view.state.facet(editable) || newSel.main.eq(sel))) {
5608
+ else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel.main.eq(sel))) {
5606
5609
  newSel = null;
5607
5610
  }
5608
5611
  if (!change && !newSel)
@@ -6666,6 +6669,8 @@ class EditorView {
6666
6669
  if (this.measureScheduled < 0)
6667
6670
  this.measureScheduled = this.win.requestAnimationFrame(() => this.measure());
6668
6671
  if (request) {
6672
+ if (this.measureRequests.indexOf(request) > -1)
6673
+ return;
6669
6674
  if (request.key != null)
6670
6675
  for (let i = 0; i < this.measureRequests.length; i++) {
6671
6676
  if (this.measureRequests[i].key === request.key) {
@@ -7349,6 +7354,8 @@ function runHandlers(map, event, view, scope) {
7349
7354
  if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
7350
7355
  return true;
7351
7356
  if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
7357
+ // Ctrl-Alt may be used for AltGr on Windows
7358
+ !(browser.windows && event.ctrlKey && event.altKey) &&
7352
7359
  (baseName = base[event.keyCode]) && baseName != name) {
7353
7360
  if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
7354
7361
  return true;
@@ -7643,7 +7650,7 @@ function drawSelection(config = {}) {
7643
7650
  ];
7644
7651
  }
7645
7652
  function configChanged(update) {
7646
- return update.startState.facet(selectionConfig) != update.startState.facet(selectionConfig);
7653
+ return update.startState.facet(selectionConfig) != update.state.facet(selectionConfig);
7647
7654
  }
7648
7655
  const cursorLayer = /*@__PURE__*/layer({
7649
7656
  above: true,
@@ -7662,7 +7669,7 @@ const cursorLayer = /*@__PURE__*/layer({
7662
7669
  return cursors;
7663
7670
  },
7664
7671
  update(update, dom) {
7665
- if (update.transactions.some(tr => tr.scrollIntoView))
7672
+ if (update.transactions.some(tr => tr.selection))
7666
7673
  dom.style.animationName = dom.style.animationName == "cm-blink" ? "cm-blink2" : "cm-blink";
7667
7674
  let confChange = configChanged(update);
7668
7675
  if (confChange)
@@ -9228,15 +9235,14 @@ class UpdateContext {
9228
9235
  constructor(gutter, viewport, height) {
9229
9236
  this.gutter = gutter;
9230
9237
  this.height = height;
9231
- this.localMarkers = [];
9232
9238
  this.i = 0;
9233
9239
  this.cursor = RangeSet.iter(gutter.markers, viewport.from);
9234
9240
  }
9235
9241
  line(view, line, extraMarkers) {
9236
- if (this.localMarkers.length)
9237
- this.localMarkers = [];
9238
- advanceCursor(this.cursor, this.localMarkers, line.from);
9239
- let localMarkers = extraMarkers.length ? this.localMarkers.concat(extraMarkers) : this.localMarkers;
9242
+ let localMarkers = [];
9243
+ advanceCursor(this.cursor, localMarkers, line.from);
9244
+ if (extraMarkers.length)
9245
+ localMarkers = localMarkers.concat(extraMarkers);
9240
9246
  let forLine = this.gutter.config.lineMarker(view, line, localMarkers);
9241
9247
  if (forLine)
9242
9248
  localMarkers.unshift(forLine);
@@ -9274,7 +9280,17 @@ class SingleGutterView {
9274
9280
  this.dom.className = "cm-gutter" + (this.config.class ? " " + this.config.class : "");
9275
9281
  for (let prop in config.domEventHandlers) {
9276
9282
  this.dom.addEventListener(prop, (event) => {
9277
- let line = view.lineBlockAtHeight(event.clientY - view.documentTop);
9283
+ let target = event.target, y;
9284
+ if (target != this.dom && this.dom.contains(target)) {
9285
+ while (target.parentNode != this.dom)
9286
+ target = target.parentNode;
9287
+ let rect = target.getBoundingClientRect();
9288
+ y = (rect.top + rect.bottom) / 2;
9289
+ }
9290
+ else {
9291
+ y = event.clientY;
9292
+ }
9293
+ let line = view.lineBlockAtHeight(y - view.documentTop);
9278
9294
  if (config.domEventHandlers[prop](view, line, event))
9279
9295
  event.preventDefault();
9280
9296
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.7.1",
3
+ "version": "6.7.3",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",