-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Footnotes: prevent inserting footnotes within a footnotes block #74287
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Size Change: +37 B (0%) Total Size: 2.59 MB
ℹ️ View Unchanged
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Mamaduka
left a comment
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.
|
|
||
| const POST_CONTENT_BLOCK_NAME = 'core/post-content'; | ||
| const SYNCED_PATTERN_BLOCK_NAME = 'core/block'; | ||
| const FOOTNOTES_BLOCK_NAME = 'core/footnotes'; |
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.
Wouldn't be a little cleaner to use?
import { name as FOOTNOTES_BLOCK_NAME } from './block.json';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.
Why? In this case, inline constants make more sense. IMO.
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.
Generally looks good avoiding duplication of something hardcoded if it already exists
| getSelectionStart, | ||
| getBlockName: _getBlockName, |
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.
Also I've noted, that instead of taking getSelectionStart you could take _getSelectedBlockClientId
getSelectedBlockClientId: _getSelectedBlockClientId,And then use it to get the selectedClientId
- const selectionStart = getSelectionStart();
+ const selectedClientId = _getSelectedBlockClientId();What do you think?
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.
This GH commenting thing is bugged AF
Long story short, you can preserve the original logic and simply add the _getBlockName for the check
- // Checks if the selected block lives within a pattern.
- const {
- getBlockParentsByBlockName: _getBlockParentsByBlockName,
- getSelectedBlockClientId: _getSelectedBlockClientId,
- } = select( blockEditorStore );
- const parentCoreBlocks = _getBlockParentsByBlockName(
- _getSelectedBlockClientId(),
- SYNCED_PATTERN_BLOCK_NAME
- );
+ // Checks if the selected block lives within a pattern.
+ const {
+ getBlockParentsByBlockName: _getBlockParentsByBlockName,
+ getSelectedBlockClientId: _getSelectedBlockClientId,
+ getBlockName: _getBlockName,
+ } = select( blockEditorStore );
+ const selectedClientId = _getSelectedBlockClientId();
+ // Check if the selected block itself is a footnotes block.
+ if ( ! selectedClientId ||
+ _getBlockName( selectedClientId ) === FOOTNOTES_BLOCK_NAME
+ ) {
+ return false;
+ }
+
+ const parentCoreBlocks = _getBlockParentsByBlockName(
+ selectedClientId,
+ SYNCED_PATTERN_BLOCK_NAME
+ );
What?
Prevents adding footnotes inside footnotes blocks by checking if the selected block is within a footnotes block before enabling the footnote format.
Unless this was intentional and I can't get it to work?
Why?
To prevent this:
Kapture.2025-12-31.at.13.41.09.mp4
How?
isFootnotesSupportedto detect if the selected block has a footnotes block as a parentTesting Instructions
Screenshots or screencast