-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(placeholder): hide placeholder in atom nodes by default #6044
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tiptap/extension-placeholder": patch | ||
--- | ||
|
||
feat(placeholder): do not show placeholder on atom nodes by default |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -81,6 +90,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({ | |
showOnlyWhenEditable: true, | ||
showOnlyCurrent: true, | ||
includeChildren: false, | ||
showWhenAtom: false, | ||
} | ||
}, | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This var name doesn't really describe it well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the atom is not considered a leaf? That is surprising to me? And it also isn't empty? That sounds wrong to me Either the isNodeEmpty should be updated to make it be counted as being empty or something else is up here |
||
|
||
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) { | ||
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty && isContentEditable) { | ||
const classes = [this.options.emptyNodeClass] | ||
|
||
if (isEmptyDoc) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with making this an option, people should not have to care. You can also just disable the placeholder with css so I don't see why we would need to even modify the JS here