-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Format library: fix unsetting highlight color #37062
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/e2e-tests/specs/editor/various/format-library/__snapshots__/text-color.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RichText should remove highlighting element 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p><mark style=\\"background-color:rgba(0, 0, 0, 0)\\" class=\\"has-inline-color has-cyan-bluish-gray-color\\">1</mark></p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
|
||
exports[`RichText should remove highlighting element 2`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>1</p> | ||
<!-- /wp:paragraph -->" | ||
`; |
47 changes: 47 additions & 0 deletions
47
packages/e2e-tests/specs/editor/various/format-library/text-color.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createNewPost, | ||
getEditedPostContent, | ||
clickBlockAppender, | ||
pressKeyWithModifier, | ||
clickBlockToolbarButton, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'RichText', () => { | ||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
it( 'should remove highlighting element', async () => { | ||
await clickBlockAppender(); | ||
|
||
// Add text and select to color. | ||
await page.keyboard.type( '1' ); | ||
await pressKeyWithModifier( 'primary', 'a' ); | ||
await clickBlockToolbarButton( 'More' ); | ||
|
||
const button = await page.waitForXPath( | ||
`//button[text()='Highlight']` | ||
); | ||
// Clicks may fail if the button is out of view. Assure it is before click. | ||
await button.evaluate( ( element ) => element.scrollIntoView() ); | ||
await button.click(); | ||
|
||
// Tab to the "Text" tab. | ||
await page.keyboard.press( 'Tab' ); | ||
// Tab to black. | ||
await page.keyboard.press( 'Tab' ); | ||
// Select color other than black. | ||
await page.keyboard.press( 'Tab' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await page.keyboard.press( 'Space' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
|
||
await page.keyboard.press( 'Space' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,14 @@ import { __ } from '@wordpress/i18n'; | |
/** | ||
* Internal dependencies | ||
*/ | ||
import { textColor as settings } from './index'; | ||
import { textColor as settings, transparentValue } from './index'; | ||
|
||
function parseCSS( css = '' ) { | ||
return css.split( ';' ).reduce( ( accumulator, rule ) => { | ||
if ( rule ) { | ||
const [ property, value ] = rule.split( ':' ); | ||
if ( property === 'color' ) accumulator.color = value; | ||
if ( property === 'background-color' ) | ||
if ( property === 'background-color' && value !== transparentValue ) | ||
accumulator.backgroundColor = value; | ||
} | ||
return accumulator; | ||
|
@@ -44,9 +44,10 @@ function parseCSS( css = '' ) { | |
|
||
function parseClassName( className = '', colorSettings ) { | ||
return className.split( ' ' ).reduce( ( accumulator, name ) => { | ||
const match = name.match( /^has-([^-]+)-color$/ ); | ||
if ( match ) { | ||
const [ , colorSlug ] = name.match( /^has-([^-]+)-color$/ ); | ||
if ( name.startsWith( 'has-' ) && name.endsWith( '-color' ) ) { | ||
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. There should be a comment here explaining that |
||
const colorSlug = name | ||
.replace( /^has-/, '' ) | ||
.replace( /-color$/, '' ); | ||
const colorObject = getColorObjectByAttributeValues( | ||
colorSettings, | ||
colorSlug | ||
|
@@ -88,7 +89,7 @@ function setColors( value, name, colorSettings, colors ) { | |
styles.push( [ 'background-color', backgroundColor ].join( ':' ) ); | ||
} else { | ||
// Override default browser color for mark element. | ||
styles.push( [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' ) ); | ||
styles.push( [ 'background-color', transparentValue ].join( ':' ) ); | ||
} | ||
|
||
if ( color ) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 pushed a commit replacing all remaining occurrences of this string in
format-library
with the new constant. This should decrease the chances of format mismatches creeping in — for example, if the setter uses a hardcoded string likergba(0,0,0,0)
(with no spaces), the logic breaks.The module constant, coupled with the expanded test coverage, might be enough. Otherwise we could use a regular expression.