diff --git a/package.json b/package.json index 902c9043..192fae04 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@tiptap/extension-highlight": "2.6.6", "@tiptap/extension-image": "2.6.6", "@tiptap/extension-link": "2.6.6", + "@tiptap/extension-list-keymap": "2.11.7", "@tiptap/extension-mention": "2.6.6", "@tiptap/extension-placeholder": "2.6.6", "@tiptap/extension-table": "2.6.6", diff --git a/src/components/Editor/CustomExtensions/KeyboardShortcuts/ExtensionConfig.js b/src/components/Editor/CustomExtensions/KeyboardShortcuts/ExtensionConfig.js index 8ac4eed5..d1666638 100644 --- a/src/components/Editor/CustomExtensions/KeyboardShortcuts/ExtensionConfig.js +++ b/src/components/Editor/CustomExtensions/KeyboardShortcuts/ExtensionConfig.js @@ -1,5 +1,4 @@ import { Extension } from "@tiptap/core"; -import { liftTarget } from "@tiptap/pm/transform"; const KeyboardShortcuts = ({ onSubmit, shortcuts, isBlockQuoteActive }) => Extension.create({ @@ -21,40 +20,6 @@ const KeyboardShortcuts = ({ onSubmit, shortcuts, isBlockQuoteActive }) => return false; }, - // To fix the issue with backspace on the empty list item moving the focus to the block on top. - // https://github.com/ueberdosis/tiptap/issues/2829#issuecomment-1511064298 - Backspace: () => - this.editor.commands.command(({ tr }) => { - const { selection, doc } = tr; - const { $cursor } = selection; - const depth = $cursor?.depth; - - if ( - $cursor && - depth >= 3 && // At least the structure is doc -> orderedList/bulletList -> listItem -> paragraph - $cursor.parent.type.name === "paragraph" && // The cursor is inside a paragraph. - $cursor.parentOffset === 0 && // The cursor is at the beginning of the paragraph. - $cursor.node(depth - 1).type.name === "listItem" && // The paragraph is inside a listItem. - $cursor.index(depth - 1) === 0 && // The paragraph is at the beginning of the listItem. - $cursor.index(depth - 2) === 0 // The listItem is at the beginning of the list. - ) { - const listItemNode = $cursor.node(depth - 1); - const listItemPos = $cursor.before(depth - 1); - const $contentBegin = doc.resolve(listItemPos + 1); - const $contentEnd = doc.resolve( - listItemPos + listItemNode.nodeSize - 1 - ); - const range = $contentBegin.blockRange($contentEnd); - const target = liftTarget(range); - if (target !== null) { - tr.lift(range, target); - - return true; - } - } - - return false; - }), ...shortcuts, }; }, diff --git a/src/components/Editor/CustomExtensions/hooks/useCustomExtensions.js b/src/components/Editor/CustomExtensions/hooks/useCustomExtensions.js index bc73b2fa..7ac99486 100644 --- a/src/components/Editor/CustomExtensions/hooks/useCustomExtensions.js +++ b/src/components/Editor/CustomExtensions/hooks/useCustomExtensions.js @@ -6,6 +6,7 @@ import Color from "@tiptap/extension-color"; import Document from "@tiptap/extension-document"; import Focus from "@tiptap/extension-focus"; import Highlight from "@tiptap/extension-highlight"; +import ListKeymap from "@tiptap/extension-list-keymap"; import TableCell from "@tiptap/extension-table-cell"; import TableHeader from "@tiptap/extension-table-header"; import TableRow from "@tiptap/extension-table-row"; @@ -94,6 +95,7 @@ const useCustomExtensions = ({ shortcuts: keyboardShortcuts, isBlockQuoteActive: options.includes(EDITOR_OPTIONS.BLOCKQUOTE), }), + ListKeymap, ]; if (isVideoEmbedActive) { customExtensions.push(Embeds); diff --git a/yarn.lock b/yarn.lock index a15372a7..d04507b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4018,6 +4018,11 @@ resolved "https://registry.yarnpkg.com/@tiptap/extension-list-item/-/extension-list-item-2.6.6.tgz#fedb7d5b3293d487eb5b9773abe8eb8a0a395428" integrity sha512-k+oEzZu2cgVKqPqOP1HzASOKLpTEV9m7mRVPAbuaaX8mSyvIgD6f+JUx9PvgYv//D918wk98LMoRBFX53tDJ4w== +"@tiptap/extension-list-keymap@2.11.7": + version "2.11.7" + resolved "https://registry.yarnpkg.com/@tiptap/extension-list-keymap/-/extension-list-keymap-2.11.7.tgz#a89a94e961c69d89c06b5071417f9adb78659787" + integrity sha512-t1XgD6+NNxEW9KrI7eK/RnXV/zBsHbYwzn4g0V3+NYQS7siaeCHHN0JwGhVPx1RojYeg+zq9NEj+fr4f3G7XAw== + "@tiptap/extension-mention@2.6.6": version "2.6.6" resolved "https://registry.yarnpkg.com/@tiptap/extension-mention/-/extension-mention-2.6.6.tgz#c46878bed263eb0ddb8f57b33530dd4ae7000920"