Skip to content

Commit

Permalink
fix-decorations-and-attribute-editor-props
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHung authored Mar 30, 2022
1 parent ebddbad commit 1d71877
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions packages/extension-placeholder/src/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
return
}

cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
cachedEmptyTopNode = cachedEmptyTopNode || doc.type.createAndFill()
let isEditorEmpty = cachedEmptyTopNode.sameMarkup(doc) && cachedEmptyTopNode.content.findDiffStart(doc.content) === null

doc.descendants((node, pos) => {
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
Expand Down Expand Up @@ -80,16 +80,28 @@ export const Placeholder = Extension.create<PlaceholderOptions>({

return DecorationSet.create(doc, decorations)
},
},

attributes(state) {
cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
if (isEditorEmpty) {
return {class: this.options.emptyEditorClass}
attributes: ({ doc }) => {
cachedEmptyTopNode = cachedEmptyTopNode || doc.type.createAndFill()
let isEditorEmpty = cachedEmptyTopNode.sameMarkup(doc) && cachedEmptyTopNode.content.findDiffStart(doc.content) === null
if (isEditorEmpty) {
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

0 comments on commit 1d71877

Please sign in to comment.