prosemirror-view 1.23.3 → 1.23.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/dist/index.js CHANGED
@@ -2081,8 +2081,8 @@ function findTextInFragment(frag, text, from, to) {
2081
2081
  if (!next.isText) { break }
2082
2082
  str += next.text;
2083
2083
  }
2084
- if (pos >= from) {
2085
- var found = str.lastIndexOf(text, to - childStart);
2084
+ if (pos >= from && childStart < to) {
2085
+ var found = str.lastIndexOf(text, to - childStart - 1);
2086
2086
  if (found >= 0 && found + text.length + childStart >= from)
2087
2087
  { return childStart + found }
2088
2088
  }
@@ -2153,9 +2153,13 @@ function selectionToDOM(view, force) {
2153
2153
  if (!editorOwnsSelection(view)) { return }
2154
2154
 
2155
2155
  if (!force && view.mouseDown && view.mouseDown.allowDefault) {
2156
- view.mouseDown.delayedSelectionSync = true;
2157
- view.domObserver.setCurSelection();
2158
- return
2156
+ var domSel = view.root.getSelection(), curSel = view.domObserver.currentSelection;
2157
+ if (domSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset,
2158
+ curSel.anchorNode, curSel.anchorOffset)) {
2159
+ view.mouseDown.delayedSelectionSync = true;
2160
+ view.domObserver.setCurSelection();
2161
+ return
2162
+ }
2159
2163
  }
2160
2164
 
2161
2165
  view.domObserver.disconnectSelection();
@@ -3507,9 +3511,14 @@ function dispatchEvent(view, event) {
3507
3511
  editHandlers.keydown = function (view, event) {
3508
3512
  view.shiftKey = event.keyCode == 16 || event.shiftKey;
3509
3513
  if (inOrNearComposition(view, event)) { return }
3510
- if (event.keyCode != 229) { view.domObserver.forceFlush(); }
3511
3514
  view.lastKeyCode = event.keyCode;
3512
3515
  view.lastKeyCodeTime = Date.now();
3516
+ // Suppress enter key events on Chrome Android, because those tend
3517
+ // to be part of a confused sequence of composition events fired,
3518
+ // and handling them eagerly tends to corrupt the input.
3519
+ if (result.android && result.chrome && event.keyCode == 13) { return }
3520
+ if (event.keyCode != 229) { view.domObserver.forceFlush(); }
3521
+
3513
3522
  // On iOS, if we preventDefault enter key presses, the virtual
3514
3523
  // keyboard gets confused. So the hack here is to set a flag that
3515
3524
  // makes the DOM change code recognize that what just happens should
@@ -3894,6 +3903,7 @@ function timestampFromCustomEvent() {
3894
3903
  }
3895
3904
 
3896
3905
  function endComposition(view, forceUpdate) {
3906
+ if (result.android && view.domObserver.flushingSoon >= 0) { return }
3897
3907
  view.domObserver.forceFlush();
3898
3908
  clearComposition(view);
3899
3909
  if (forceUpdate || view.docView.dirty) {
@@ -3984,6 +3994,11 @@ function doPaste(view, text, html, e) {
3984
3994
  }
3985
3995
 
3986
3996
  editHandlers.paste = function (view, e) {
3997
+ // Handling paste from JavaScript during composition is very poorly
3998
+ // handled by browsers, so as a dodgy but preferable kludge, we just
3999
+ // let the browser do its native thing there, except on Android,
4000
+ // where the editor is almost always composing.
4001
+ if (view.composing && !result.android) { return }
3987
4002
  var data = brokenClipboardAPI ? null : e.clipboardData;
3988
4003
  if (data && doPaste(view, data.getData("text/plain"), data.getData("text/html"), e)) { e.preventDefault(); }
3989
4004
  else { capturePaste(view, e); }
@@ -4115,6 +4130,7 @@ handlers.beforeinput = function (view, event) {
4115
4130
  // Very specific hack to deal with backspace sometimes failing on
4116
4131
  // Chrome Android when after an uneditable node.
4117
4132
  if (result.chrome && result.android && event.inputType == "deleteContentBackward") {
4133
+ view.domObserver.flushSoon();
4118
4134
  var domChangeCount = view.domChangeCount;
4119
4135
  setTimeout(function () {
4120
4136
  if (view.domChangeCount != domChangeCount) { return } // Event already had some effect