-
Notifications
You must be signed in to change notification settings - Fork 842
jetpack-mu-wpcom: Code block fixes and improvements #46418
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
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
e6ebf3e to
0201616
Compare
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.
Pull request overview
This PR enhances the code block functionality with several UX improvements and fixes, including reorganizing the language dropdown to prioritize popular languages, ensuring "Plain text" displays correctly as a language name, replacing the filename toggle with a direct input field, and improving the active line highlight color using relative color syntax.
- Sorted popular languages at the top of the language dropdown for easier access
- Fixed display of "Plain text" language name when showLanguageName is enabled
- Replaced filename toggle with direct filename input field in settings panel
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/editor.css |
Adds new active line highlight using oklch relative color syntax |
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/common/block.ts |
Removes deprecated showFileName attribute from interface |
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/class-code-block.php |
Removes showFileName attribute registration and updates rendering logic to always show filename when present, adds "Plain text" fallback for language display |
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx |
Adds popular languages section to dropdown, replaces filename toggle with TextControl input, updates language display logic, and adds copy button click handler |
projects/packages/jetpack-mu-wpcom/changelog/code-block-fixes-polish |
Documents the changes as a minor addition |
...ckages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx
Show resolved
Hide resolved
...ckages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx
Outdated
Show resolved
Hide resolved
...ckages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx
Show resolved
Hide resolved
...ckages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx
Show resolved
Hide resolved
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/class-code-block.php
Outdated
Show resolved
Hide resolved
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/editor.css
Show resolved
Hide resolved
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/editor.css
Show resolved
Hide resolved
...ckages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx
Show resolved
Hide resolved
2bc8833 to
2d6fc0f
Compare
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-definition/block-definition.tsx:216
- The toolbar dropdown menu should also display popular languages at the top, similar to the SelectControl in the sidebar. Currently, it only shows "Plain text" followed by all languages in alphabetical order, but doesn't include the popular languages section that was added to the sidebar dropdown.
{ selectLanguageOptions.map( option => (
<MenuItem
key={ option.value }
role="menuitemradio"
isSelected={ option.value === props.attributes.language }
onClick={ () => {
props.setAttributes( {
language: option.value,
languageConfidence: 'certain',
} );
onClose();
} }
>
{ option.label }
</MenuItem>
) ) }
cbravobernal
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.
LGTM
Replaces the default static current line highlight with a highlight color based on a reduced-opacity current text color. ARC-1308
5c2d9b1 to
5dc97d3
Compare
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| </SelectControl> | ||
| <TextControl | ||
| label={ __( 'Filename', 'jetpack-mu-wpcom' ) } | ||
| defaultValue={ attributes.filename } |
Copilot
AI
Jan 5, 2026
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.
Using defaultValue instead of value for a controlled input means the component won't update when attributes.filename changes externally. This can lead to the displayed value being out of sync with the actual attribute value. Consider using value prop instead to make this a properly controlled component.
| defaultValue={ attributes.filename } | |
| value={ attributes.filename } |
| isSelected={ emptyLanguageOption.value === props.attributes.language } | ||
| onClick={ () => { | ||
| props.setAttributes( { | ||
| language: emptyLanguageOption.value, | ||
| languageConfidence: 'certain', | ||
| } ); |
Copilot
AI
Jan 5, 2026
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.
The comparison emptyLanguageOption.value === props.attributes.language may not work correctly if props.attributes.language is undefined or null instead of an empty string. Consider using a more robust check like !props.attributes.language or explicitly checking for undefined/null values.
| isSelected={ emptyLanguageOption.value === props.attributes.language } | |
| onClick={ () => { | |
| props.setAttributes( { | |
| language: emptyLanguageOption.value, | |
| languageConfidence: 'certain', | |
| } ); | |
| isSelected={ ! props.attributes.language } | |
| onClick={ () => { | |
| props.setAttributes( { | |
| language: emptyLanguageOption.value, | |
| languageConfidence: 'certain', | |
| } ); |
Proposed changes:
A list of popular languages are sorted at the top of the language dropdown (closes ARC-1306):
Ensure that the "show language name" option displays "Plain text" language name when selected (fixes ARC-1305):
Replace show filename toggle with filename input field (closes ARC-1307):
Improve line highlight color based on text color (closes ARC-1308):
Other information:
Jetpack product discussion
pdtkmj-42c-p2#comment-8195
pdtkmj-42c-p2#comment-8230
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Test out the modified functionality in the Code block and confirm it works as expected.