prosemirror-view 1.34.0 → 1.34.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,11 @@
1
+ ## 1.34.1 (2024-08-26)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix null dereferences caused by the behavior of Chrome's newly supported `caretPositionFromPoint` method.
6
+
7
+ Fix an issue where on Android, with GBoard, enter presses in code blocks while a spell correction was selected didn't insert a new line.
8
+
1
9
  ## 1.34.0 (2024-08-23)
2
10
 
3
11
  ### New features
package/dist/index.cjs CHANGED
@@ -135,7 +135,7 @@ function caretFromPoint(doc, x, y) {
135
135
  var pos = doc.caretPositionFromPoint(x, y);
136
136
  if (pos) return {
137
137
  node: pos.offsetNode,
138
- offset: pos.offset
138
+ offset: Math.min(nodeSize(pos.offsetNode), pos.offset)
139
139
  };
140
140
  } catch (_) {}
141
141
  }
@@ -143,7 +143,7 @@ function caretFromPoint(doc, x, y) {
143
143
  var range = doc.caretRangeFromPoint(x, y);
144
144
  if (range) return {
145
145
  node: range.startContainer,
146
- offset: range.startOffset
146
+ offset: Math.min(nodeSize(range.startContainer), range.startOffset)
147
147
  };
148
148
  }
149
149
  }
@@ -4560,6 +4560,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4560
4560
  }
4561
4561
  view.input.lastKeyCode = null;
4562
4562
  var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
4563
+ if (change) view.input.domChangeCount++;
4563
4564
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
4564
4565
  return n.nodeType == 1 && !isInline.test(n.nodeName);
4565
4566
  }) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
@@ -4587,7 +4588,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4587
4588
  return;
4588
4589
  }
4589
4590
  }
4590
- view.input.domChangeCount++;
4591
4591
  if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof prosemirrorState.TextSelection) {
4592
4592
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) {
4593
4593
  change.start = view.state.selection.from;
package/dist/index.js CHANGED
@@ -139,15 +139,18 @@ function caretFromPoint(doc, x, y) {
139
139
  if (doc.caretPositionFromPoint) {
140
140
  try { // Firefox throws for this call in hard-to-predict circumstances (#994)
141
141
  let pos = doc.caretPositionFromPoint(x, y);
142
+ // Clip the offset, because Chrome will return a text offset
143
+ // into <input> nodes, which can't be treated as a regular DOM
144
+ // offset
142
145
  if (pos)
143
- return { node: pos.offsetNode, offset: pos.offset };
146
+ return { node: pos.offsetNode, offset: Math.min(nodeSize(pos.offsetNode), pos.offset) };
144
147
  }
145
148
  catch (_) { }
146
149
  }
147
150
  if (doc.caretRangeFromPoint) {
148
151
  let range = doc.caretRangeFromPoint(x, y);
149
152
  if (range)
150
- return { node: range.startContainer, offset: range.startOffset };
153
+ return { node: range.startContainer, offset: Math.min(nodeSize(range.startContainer), range.startOffset) };
151
154
  }
152
155
  }
153
156
 
@@ -4902,6 +4905,8 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4902
4905
  }
4903
4906
  view.input.lastKeyCode = null;
4904
4907
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
4908
+ if (change)
4909
+ view.input.domChangeCount++;
4905
4910
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) &&
4906
4911
  addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
4907
4912
  (!change || change.endA >= change.endB) &&
@@ -4927,7 +4932,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4927
4932
  return;
4928
4933
  }
4929
4934
  }
4930
- view.input.domChangeCount++;
4931
4935
  // Handle the case where overwriting a selection by typing matches
4932
4936
  // the start or end of the selected content, creating a change
4933
4937
  // that's smaller than what was actually overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.34.0",
3
+ "version": "1.34.1",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/dom.ts CHANGED
@@ -141,11 +141,14 @@ export function caretFromPoint(doc: Document, x: number, y: number): {node: Node
141
141
  if ((doc as any).caretPositionFromPoint) {
142
142
  try { // Firefox throws for this call in hard-to-predict circumstances (#994)
143
143
  let pos = (doc as any).caretPositionFromPoint(x, y)
144
- if (pos) return {node: pos.offsetNode, offset: pos.offset}
144
+ // Clip the offset, because Chrome will return a text offset
145
+ // into <input> nodes, which can't be treated as a regular DOM
146
+ // offset
147
+ if (pos) return {node: pos.offsetNode, offset: Math.min(nodeSize(pos.offsetNode), pos.offset)}
145
148
  } catch (_) {}
146
149
  }
147
150
  if (doc.caretRangeFromPoint) {
148
151
  let range = doc.caretRangeFromPoint(x, y)
149
- if (range) return {node: range.startContainer, offset: range.startOffset}
152
+ if (range) return {node: range.startContainer, offset: Math.min(nodeSize(range.startContainer), range.startOffset)}
150
153
  }
151
154
  }
package/src/domchange.ts CHANGED
@@ -120,6 +120,7 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
120
120
  view.input.lastKeyCode = null
121
121
 
122
122
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide)
123
+ if (change) view.input.domChangeCount++
123
124
  if ((browser.ios && view.input.lastIOSEnter > Date.now() - 225 || browser.android) &&
124
125
  addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
125
126
  (!change || change.endA >= change.endB) &&
@@ -144,7 +145,6 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
144
145
  }
145
146
  }
146
147
 
147
- view.input.domChangeCount++
148
148
  // Handle the case where overwriting a selection by typing matches
149
149
  // the start or end of the selected content, creating a change
150
150
  // that's smaller than what was actually overwritten.