Skip to content

Commit

Permalink
fix(Preview): allow removing Preview with backspace
Browse files Browse the repository at this point in the history
* Also only allow link marks inside the Preview.
* See #5442 for list of other follow up fixes for Previews

Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Mar 7, 2024
1 parent 6f7768d commit db17b04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/nodes/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export default Node.create({

content: 'text?',

defining: true,
atom: true,

marks: 'link',

isolating: true,

addOptions() {
return {
Expand Down
15 changes: 9 additions & 6 deletions src/tests/nodes/Preview.spec.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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()
})
Expand All @@ -32,9 +31,7 @@ describe('Preview extension', () => {

it('detects links', () => {
const link = `<a href="https://nextcloud.com" title="preview">link</a>`
const editor = createCustomEditor({
extensions: [Markdown, Preview]
})
const editor = createEditorWithPreview()
editor.commands.setContent(`${link}<p>hello></p>`)
const node = editor.state.doc.content.firstChild
expect(node.type.name).toBe('preview')
Expand All @@ -43,3 +40,9 @@ describe('Preview extension', () => {
})

})

function createEditorWithPreview() {
return createCustomEditor({
extensions: [Markdown, Preview, Link]
})
}

0 comments on commit db17b04

Please sign in to comment.