From 18681f3cae26c7124cef08a4c3974a30bb729f0c Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 7 Mar 2024 12:04:07 +0100 Subject: [PATCH] fix(Preview): allow removing Preview with backspace * Also only allow link marks inside the Preview. * See #5442 for list of other follow up fixes for Previews Signed-off-by: Max --- src/nodes/Preview.js | 6 +++++- src/tests/nodes/Preview.spec.js | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/nodes/Preview.js b/src/nodes/Preview.js index 412705f34cc..d48e9208ed0 100644 --- a/src/nodes/Preview.js +++ b/src/nodes/Preview.js @@ -34,7 +34,11 @@ export default Node.create({ content: 'text?', - defining: true, + atom: true, + + marks: 'link', + + isolating: true, addOptions() { return { diff --git a/src/tests/nodes/Preview.spec.js b/src/tests/nodes/Preview.spec.js index 8b401996975..4b0107dc02b 100644 --- a/src/tests/nodes/Preview.spec.js +++ b/src/tests/nodes/Preview.spec.js @@ -1,5 +1,6 @@ import Preview from './../../nodes/Preview' import Markdown from './../../extensions/Markdown' +import Link from './../../marks/Link' import { getExtensionField } from '@tiptap/core' import { createCustomEditor, markdownThroughEditor, markdownThroughEditorHtml } from '../helpers' import markdownit from '../../markdownit/index.js' @@ -11,9 +12,7 @@ describe('Preview extension', () => { }) it('exposes the toMarkdown function in the prosemirror schema', () => { - const editor = createCustomEditor({ - extensions: [Markdown, Preview] - }) + const editor = createEditorWithPreview() const preview = editor.schema.nodes.preview expect(preview.spec.toMarkdown).toBeDefined() }) @@ -32,9 +31,7 @@ describe('Preview extension', () => { it('detects links', () => { const link = `link` - const editor = createCustomEditor({ - extensions: [Markdown, Preview] - }) + const editor = createEditorWithPreview() editor.commands.setContent(`${link}

hello>

`) const node = editor.state.doc.content.firstChild expect(node.type.name).toBe('preview') @@ -43,3 +40,9 @@ describe('Preview extension', () => { }) }) + +function createEditorWithPreview() { + return createCustomEditor({ + extensions: [Markdown, Preview, Link] + }) +}