mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
editor: fix selecting blocks and pressing enter not working
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
diff --git a/node_modules/prosemirror-view/dist/index.cjs b/node_modules/prosemirror-view/dist/index.cjs
|
diff --git a/node_modules/prosemirror-view/dist/index.cjs b/node_modules/prosemirror-view/dist/index.cjs
|
||||||
index a615cb7..c9b1f46 100644
|
index a615cb7..9ba1d10 100644
|
||||||
--- a/node_modules/prosemirror-view/dist/index.cjs
|
--- a/node_modules/prosemirror-view/dist/index.cjs
|
||||||
+++ b/node_modules/prosemirror-view/dist/index.cjs
|
+++ b/node_modules/prosemirror-view/dist/index.cjs
|
||||||
@@ -1005,8 +1005,8 @@ var ViewDesc = function () {
|
@@ -1005,8 +1005,8 @@ var ViewDesc = function () {
|
||||||
@@ -12,7 +12,29 @@ index a615cb7..c9b1f46 100644
|
|||||||
if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
|
if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
|
||||||
domSelExtended = true;
|
domSelExtended = true;
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
@@ -3647,7 +3647,7 @@ function handleDrop(view, event, dragging) {
|
@@ -2935,6 +2935,7 @@ var InputState = _createClass(function InputState() {
|
||||||
|
this.lastSelectionOrigin = null;
|
||||||
|
this.lastSelectionTime = 0;
|
||||||
|
this.lastIOSEnter = 0;
|
||||||
|
+ this.lastAndroidEnter = 0;
|
||||||
|
this.lastIOSEnterFallbackTimeout = -1;
|
||||||
|
this.lastFocus = 0;
|
||||||
|
this.lastTouch = 0;
|
||||||
|
@@ -3003,11 +3004,12 @@ function _dispatchEvent(view, event) {
|
||||||
|
}
|
||||||
|
editHandlers.keydown = function (view, _event) {
|
||||||
|
var event = _event;
|
||||||
|
+ if (android && event.keyCode == 13) view.input.lastAndroidEnter = Date.now();
|
||||||
|
view.input.shiftKey = event.keyCode == 16 || event.shiftKey;
|
||||||
|
if (inOrNearComposition(view)) return;
|
||||||
|
view.input.lastKeyCode = event.keyCode;
|
||||||
|
view.input.lastKeyCodeTime = Date.now();
|
||||||
|
- if (android && chrome && event.keyCode == 13) return;
|
||||||
|
+ if (android && chrome && event.keyCode == 13 && view.state.selection.empty) return;
|
||||||
|
if (event.keyCode != 229) view.domObserver.forceFlush();
|
||||||
|
if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) {
|
||||||
|
var now = Date.now();
|
||||||
|
@@ -3647,7 +3649,7 @@ function handleDrop(view, event, dragging) {
|
||||||
});
|
});
|
||||||
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
||||||
}
|
}
|
||||||
@@ -21,17 +43,29 @@ index a615cb7..c9b1f46 100644
|
|||||||
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
||||||
}
|
}
|
||||||
handlers.focus = function (view) {
|
handlers.focus = function (view) {
|
||||||
@@ -4881,7 +4881,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
@@ -3674,6 +3676,7 @@ handlers.blur = function (view, _event) {
|
||||||
|
};
|
||||||
|
handlers.beforeinput = function (view, _event) {
|
||||||
|
var event = _event;
|
||||||
|
+ if (android && /^insert(Paragraph|LineBreak)/.test(event.inputType)) view.input.lastAndroidEnter = Date.now();
|
||||||
|
if (android && event.inputType == "deleteContentBackward") {
|
||||||
|
view.domObserver.flushSoon();
|
||||||
|
var domChangeCount = view.input.domChangeCount;
|
||||||
|
@@ -4881,10 +4884,11 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
||||||
var inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
|
var inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
|
||||||
if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some(function (n) {
|
if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some(function (n) {
|
||||||
return n.nodeName == "DIV" || n.nodeName == "P";
|
return n.nodeName == "DIV" || n.nodeName == "P";
|
||||||
- })) || !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", function (f) {
|
- })) || !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", function (f) {
|
||||||
+ })) || change.endB > change.endA && !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", function (f) {
|
+ })) || (!android || view.input.lastAndroidEnter > Date.now() - 225) && !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", function (f) {
|
||||||
return f(view, keyEvent(13, "Enter"));
|
return f(view, keyEvent(13, "Enter"));
|
||||||
})) {
|
})) {
|
||||||
view.input.lastIOSEnter = 0;
|
view.input.lastIOSEnter = 0;
|
||||||
|
+ view.input.lastAndroidEnter = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (view.state.selection.anchor > change.start && looksLikeBackspace(doc, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", function (f) {
|
||||||
diff --git a/node_modules/prosemirror-view/dist/index.js b/node_modules/prosemirror-view/dist/index.js
|
diff --git a/node_modules/prosemirror-view/dist/index.js b/node_modules/prosemirror-view/dist/index.js
|
||||||
index 61118ee..c8c510b 100644
|
index 61118ee..8484889 100644
|
||||||
--- a/node_modules/prosemirror-view/dist/index.js
|
--- a/node_modules/prosemirror-view/dist/index.js
|
||||||
+++ b/node_modules/prosemirror-view/dist/index.js
|
+++ b/node_modules/prosemirror-view/dist/index.js
|
||||||
@@ -1079,8 +1079,8 @@ class ViewDesc {
|
@@ -1079,8 +1079,8 @@ class ViewDesc {
|
||||||
@@ -44,7 +78,33 @@ index 61118ee..c8c510b 100644
|
|||||||
if (anchor != head)
|
if (anchor != head)
|
||||||
domSel.extend(headDOM.node, headDOM.offset);
|
domSel.extend(headDOM.node, headDOM.offset);
|
||||||
domSelExtended = true;
|
domSelExtended = true;
|
||||||
@@ -3885,7 +3885,7 @@ function handleDrop(view, event, dragging) {
|
@@ -3098,6 +3098,7 @@ class InputState {
|
||||||
|
this.lastSelectionTime = 0;
|
||||||
|
this.lastIOSEnter = 0;
|
||||||
|
this.lastIOSEnterFallbackTimeout = -1;
|
||||||
|
+ this.lastAndroidEnter = 0;
|
||||||
|
this.lastFocus = 0;
|
||||||
|
this.lastTouch = 0;
|
||||||
|
this.lastChromeDelete = 0;
|
||||||
|
@@ -3175,6 +3176,8 @@ function dispatchEvent(view, event) {
|
||||||
|
}
|
||||||
|
editHandlers.keydown = (view, _event) => {
|
||||||
|
let event = _event;
|
||||||
|
+ if (android && event.keyCode == 13)
|
||||||
|
+ view.input.lastAndroidEnter = Date.now();
|
||||||
|
view.input.shiftKey = event.keyCode == 16 || event.shiftKey;
|
||||||
|
if (inOrNearComposition(view))
|
||||||
|
return;
|
||||||
|
@@ -3183,7 +3186,7 @@ editHandlers.keydown = (view, _event) => {
|
||||||
|
// Suppress enter key events on Chrome Android, because those tend
|
||||||
|
// to be part of a confused sequence of composition events fired,
|
||||||
|
// and handling them eagerly tends to corrupt the input.
|
||||||
|
- if (android && chrome && event.keyCode == 13)
|
||||||
|
+ if (android && chrome && event.keyCode == 13 && view.state.selection.empty)
|
||||||
|
return;
|
||||||
|
if (event.keyCode != 229)
|
||||||
|
view.domObserver.forceFlush();
|
||||||
|
@@ -3885,7 +3888,7 @@ function handleDrop(view, event, dragging) {
|
||||||
tr.mapping.maps[tr.mapping.maps.length - 1].forEach((_from, _to, _newFrom, newTo) => end = newTo);
|
tr.mapping.maps[tr.mapping.maps.length - 1].forEach((_from, _to, _newFrom, newTo) => end = newTo);
|
||||||
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
||||||
}
|
}
|
||||||
@@ -53,12 +113,26 @@ index 61118ee..c8c510b 100644
|
|||||||
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
||||||
}
|
}
|
||||||
handlers.focus = view => {
|
handlers.focus = view => {
|
||||||
@@ -5193,7 +5193,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
@@ -3914,6 +3917,8 @@ handlers.blur = (view, _event) => {
|
||||||
|
};
|
||||||
|
handlers.beforeinput = (view, _event) => {
|
||||||
|
let event = _event;
|
||||||
|
+ if (android && /^insert(Paragraph|LineBreak)/.test(event.inputType))
|
||||||
|
+ view.input.lastAndroidEnter = Date.now();
|
||||||
|
// We should probably do more with beforeinput events, but support
|
||||||
|
// is so spotty that I'm still waiting to see where they are going.
|
||||||
|
// Very specific hack to deal with backspace sometimes failing on
|
||||||
|
@@ -5193,11 +5198,12 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
||||||
// as being an iOS enter press), just dispatch an Enter key instead.
|
// as being an iOS enter press), just dispatch an Enter key instead.
|
||||||
if (((ios && view.input.lastIOSEnter > Date.now() - 225 &&
|
if (((ios && view.input.lastIOSEnter > Date.now() - 225 &&
|
||||||
(!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) ||
|
(!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) ||
|
||||||
- (!inlineChange && $from.pos < parse.doc.content.size &&
|
- (!inlineChange && $from.pos < parse.doc.content.size &&
|
||||||
+ (change.endB > change.endA && !inlineChange && $from.pos < parse.doc.content.size &&
|
+ ((!android || view.input.lastAndroidEnter > Date.now() - 225) && !inlineChange && $from.pos < parse.doc.content.size &&
|
||||||
(!$from.sameParent($to) || !$from.parent.inlineContent) &&
|
(!$from.sameParent($to) || !$from.parent.inlineContent) &&
|
||||||
$from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", "")))) &&
|
$from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", "")))) &&
|
||||||
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
|
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
|
||||||
|
view.input.lastIOSEnter = 0;
|
||||||
|
+ view.input.lastAndroidEnter = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Same for backspace
|
||||||
|
|||||||
Reference in New Issue
Block a user