Skip to content

Commit

Permalink
feat(placeholder): do not show placeholder on atom nodes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadiBlitz authored Jan 21, 2025
1 parent a44a7c3 commit ce57349
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/extension-placeholder/src/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export interface PlaceholderOptions {
* @default false
*/
includeChildren: boolean

/**
* **Controls if the placeholder should be shown for atom nodes.**
*
* If true, the placeholder will be shown for atom nodes.
* If false, the placeholder will not be shown for atom nodes.
* @default false
*/
showWhenAtom: boolean;
}

/**
Expand All @@ -81,6 +90,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
showOnlyWhenEditable: true,
showOnlyCurrent: true,
includeChildren: false,
showWhenAtom: false,
}
},

Expand All @@ -103,8 +113,9 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
doc.descendants((node, pos) => {
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
const isEmpty = !node.isLeaf && isNodeEmpty(node)
const isContentEditable = this.options.showWhenAtom ? !node.type.isAtom : true;

if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty && isContentEditable) {
const classes = [this.options.emptyNodeClass]

if (isEmptyDoc) {
Expand Down

0 comments on commit ce57349

Please sign in to comment.