fix-decorations-and-attribute-editor-props
This commit is contained in:
@@ -45,8 +45,8 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
|
cachedEmptyTopNode = cachedEmptyTopNode || doc.type.createAndFill()
|
||||||
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
|
let isEditorEmpty = cachedEmptyTopNode.sameMarkup(doc) && cachedEmptyTopNode.content.findDiffStart(doc.content) === null
|
||||||
|
|
||||||
doc.descendants((node, pos) => {
|
doc.descendants((node, pos) => {
|
||||||
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
||||||
@@ -80,16 +80,28 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|||||||
|
|
||||||
return DecorationSet.create(doc, decorations)
|
return DecorationSet.create(doc, decorations)
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
attributes(state) {
|
attributes: ({ doc }) => {
|
||||||
cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
|
cachedEmptyTopNode = cachedEmptyTopNode || doc.type.createAndFill()
|
||||||
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
|
let isEditorEmpty = cachedEmptyTopNode.sameMarkup(doc) && cachedEmptyTopNode.content.findDiffStart(doc.content) === null
|
||||||
if (isEditorEmpty) {
|
if (isEditorEmpty) {
|
||||||
return {class: this.options.emptyEditorClass}
|
return {
|
||||||
|
class: this.options.emptyEditorClass,
|
||||||
|
'data-placeholder': typeof this.options.placeholder === 'function'
|
||||||
|
? this.options.placeholder({
|
||||||
|
editor: this.editor,
|
||||||
|
node: doc,
|
||||||
|
pos: 0,
|
||||||
|
hasAnchor: true,
|
||||||
|
})
|
||||||
|
: this.options.placeholder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Placeholder
|
||||||
Reference in New Issue
Block a user