editor: fix crash on select all + backspace with lists

This commit is contained in:
Abdullah Atta
2024-03-19 12:29:56 +05:00
parent 479dec6998
commit 732185a69d
2 changed files with 50 additions and 2 deletions

View File

@@ -1,7 +1,16 @@
diff --git a/node_modules/@tiptap/core/dist/index.cjs b/node_modules/@tiptap/core/dist/index.cjs
index 1ea30e0..b6f4899 100644
index 1ea30e0..b5d15e3 100644
--- a/node_modules/@tiptap/core/dist/index.cjs
+++ b/node_modules/@tiptap/core/dist/index.cjs
@@ -1327,7 +1327,7 @@ const cut = (originRange, targetPos) => ({ editor, tr }) => {
tr.deleteRange(originRange.from, originRange.to);
const newPos = tr.mapping.map(targetPos);
tr.insert(newPos, contentSlice.content);
- tr.setSelection(new state.TextSelection(tr.doc.resolve(newPos - 1)));
+ tr.setSelection(new state.TextSelection(tr.doc.resolve(Math.max(0, newPos - 1))));
return true;
};
@@ -1901,9 +1901,24 @@ const lift = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
return commands$1.lift(state, dispatch);
};
@@ -31,9 +40,18 @@ index 1ea30e0..b6f4899 100644
const liftListItem = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema);
diff --git a/node_modules/@tiptap/core/dist/index.js b/node_modules/@tiptap/core/dist/index.js
index 554e919..23a99fd 100644
index 554e919..cdd21be 100644
--- a/node_modules/@tiptap/core/dist/index.js
+++ b/node_modules/@tiptap/core/dist/index.js
@@ -1323,7 +1323,7 @@ const cut = (originRange, targetPos) => ({ editor, tr }) => {
tr.deleteRange(originRange.from, originRange.to);
const newPos = tr.mapping.map(targetPos);
tr.insert(newPos, contentSlice.content);
- tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)));
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(0, newPos - 1))));
return true;
};
@@ -1897,9 +1897,24 @@ const lift = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
return lift$1(state, dispatch);
};

View File

@@ -0,0 +1,30 @@
diff --git a/node_modules/@tiptap/extension-list-keymap/dist/index.cjs b/node_modules/@tiptap/extension-list-keymap/dist/index.cjs
index 9cd822f..1539b13 100644
--- a/node_modules/@tiptap/extension-list-keymap/dist/index.cjs
+++ b/node_modules/@tiptap/extension-list-keymap/dist/index.cjs
@@ -82,7 +82,9 @@ const handleBackspace = (editor, name, parentListTypes) => {
// the previous item is a list (orderedList or bulletList)
// move the cursor into the list and delete the current item
if (!core.isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
- const { $anchor } = editor.state.selection;
+ const { $anchor, empty } = editor.state.selection;
+ if (!empty) return false;
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
const listDescendants = [];
$listPos.node().descendants((node, pos) => {
diff --git a/node_modules/@tiptap/extension-list-keymap/dist/index.js b/node_modules/@tiptap/extension-list-keymap/dist/index.js
index e759826..11a385f 100644
--- a/node_modules/@tiptap/extension-list-keymap/dist/index.js
+++ b/node_modules/@tiptap/extension-list-keymap/dist/index.js
@@ -78,7 +78,9 @@ const handleBackspace = (editor, name, parentListTypes) => {
// the previous item is a list (orderedList or bulletList)
// move the cursor into the list and delete the current item
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
- const { $anchor } = editor.state.selection;
+ const { $anchor, empty } = editor.state.selection;
+ if (!empty) return false;
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
const listDescendants = [];
$listPos.node().descendants((node, pos) => {