mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-08 01:53:04 +08:00
fix(core): take atom content entirely (#5321)
This commit is contained in:
parent
b47df57444
commit
4cca382695
5
.changeset/atom-text-content-in-full.md
Normal file
5
.changeset/atom-text-content-in-full.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Make sure that atoms are used in-full without cutting the content. Node size for atoms is 1 which causes text to be cut unexpectedly.
|
@ -24,7 +24,7 @@ export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
|
|||||||
|| node.textContent
|
|| node.textContent
|
||||||
|| '%leaf%'
|
|| '%leaf%'
|
||||||
|
|
||||||
textBefore += chunk.slice(0, Math.max(0, sliceEndPos - pos))
|
textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
|
import {
|
||||||
|
getSchemaByResolvedExtensions, getTextContentFromNodes,
|
||||||
|
} from '@tiptap/core'
|
||||||
|
import Document from '@tiptap/extension-document'
|
||||||
|
import Mention from '@tiptap/extension-mention'
|
||||||
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
|
import Text from '@tiptap/extension-text'
|
||||||
|
import { Node } from '@tiptap/pm/model'
|
||||||
|
|
||||||
|
describe(getTextContentFromNodes.name, () => {
|
||||||
|
it('gets text', () => {
|
||||||
|
const schema = getSchemaByResolvedExtensions([
|
||||||
|
Document,
|
||||||
|
Paragraph,
|
||||||
|
Text,
|
||||||
|
Mention.configure({ renderText: ({ node }) => `@${node.attrs.label ?? 'Unknown'}` }),
|
||||||
|
])
|
||||||
|
|
||||||
|
const doc = Node.fromJSON(schema, {
|
||||||
|
type: 'doc',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'paragraph',
|
||||||
|
content: [
|
||||||
|
{ type: 'text', text: 'Start ' },
|
||||||
|
{ type: 'mention', attrs: { id: 1, label: 'Mention' } },
|
||||||
|
{ type: 'text', text: ' End' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const pos = doc.resolve(12)
|
||||||
|
|
||||||
|
const text = getTextContentFromNodes(pos)
|
||||||
|
|
||||||
|
expect(text).to.eq('Start @Mention End')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user