mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-29 16:48:54 +08:00
add y.js support for codeblock extension
This commit is contained in:
parent
6757813fd0
commit
25582c64cc
@ -71,9 +71,31 @@ export function LowlightPlugin({ name }: { name: string }) {
|
||||
const oldNodes = findChildren(oldState.doc, node => node.type.name === name)
|
||||
const newNodes = findChildren(newState.doc, node => node.type.name === name)
|
||||
|
||||
// Apply decorations if selection includes named node, or transaction changes named node.
|
||||
if (transaction.docChanged && ([oldNodeName, newNodeName].includes(name)
|
||||
|| newNodes.length !== oldNodes.length)) {
|
||||
if (
|
||||
transaction.docChanged
|
||||
// Apply decorations if:
|
||||
&& (
|
||||
// selection includes named node,
|
||||
[oldNodeName, newNodeName].includes(name)
|
||||
// OR transaction adds/removes named node,
|
||||
|| newNodes.length !== oldNodes.length
|
||||
// OR transaction has changes that completely encapsulte a node
|
||||
// (for example, a transaction that affects the entire document).
|
||||
// Such transactions can happen during collab syncing via y-prosemirror, for example.
|
||||
|| transaction.steps.some(step => {
|
||||
// @ts-ignore
|
||||
return step.from !== undefined
|
||||
// @ts-ignore
|
||||
&& step.to !== undefined
|
||||
&& oldNodes.some(node => {
|
||||
// @ts-ignore
|
||||
return node.pos >= step.from
|
||||
// @ts-ignore
|
||||
&& node.pos + node.node.nodeSize <= step.to
|
||||
})
|
||||
})
|
||||
)
|
||||
) {
|
||||
return getDecorations({ doc: transaction.doc, name })
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user