-
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
Rich Text: Set applied format as active in applyFormats #15573
Conversation
// Always revise active formats. This serves as a placeholder for new | ||
// inputs with the format so new input appears with the format applied, | ||
// and ensures a format of the same type uses the latest values. | ||
activeFormats: [ format, ...activeFormats ], |
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 wonder if order could matter here. Could be not just copy the formats at the selection start? Or perhaps use getActiveFormats
?
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.
In my testing, it did matter: Where due to the behavior of normaliseFormats
, the 'latest' format must occur first, since normaliseFormats
defers to the previous entry:
gutenberg/packages/rich-text/src/normalise-formats.js
Lines 27 to 29 in 4108e37
if ( isFormatEqual( format, previousFormat ) ) { | |
newFormatsAtIndex[ formatIndex ] = previousFormat; | |
} |
I suppose I ought to document this more clearly.
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.
Although looking closer at isFormatEqual
, it's odd that it would have made any effective difference for me... considering that "latest" shouldn't matter if the attribute values (i.e. target="_blank"
was not the same between formats anyways).
I was looking at this wrong: I also found that Generally I'm still a bit wary about how this all works, mostly because "active formats" seems like a UI concern which shouldn't be considered in this module. But given the precedent, this seems an improvement all the same.
I tried using |
Anyone tested if this affects WP 5.2? |
I'll have a closer look Monday. |
In my testing, this is looking good. |
d1843ee includes an updated end-to-end test which should verify regression fix against both #15503 and #15522 . In scanning for other references to active formats within the
The changes in this pull request shouldn't introduce conflicts, though it is likely that if the logic was meant to align, the revisions here would not be reflected. I don't personally understand well enough why these files exist as native-specific to judge whether changes to those files are necessary (cc @koke , @hypest ). |
I observe there is a utility function This seems more as a general refactoring / consolidation point, however. |
@Tug I don't remember why these were introduced, can you comment here? |
We added those because we didn't want any regression in the editor compared to aztec (the mobile editor), especially regarding writing in multiple formats at once. At the time gutenberg was not able to handle that properly so we "forked" the rich-text lib and hacked the This is being removed in our fix PR which tries to bring in all the changes from #14640 into mobile. |
* Rich Text: Set applied format as active in applyFormats * Rich Text: Update toggleFormat tests per activeFormats revision * Rich Text: Replace existing active format in applied * Rich Text: Remove active format in all cases for removeFormat * Rich Text: Update toggleFormat tests per removeFormats revision * Testing: Update E2E test case to verify link display regression * Rich Text: Verify by test of activeFormats format replacement
* Rich Text: Set applied format as active in applyFormats * Rich Text: Update toggleFormat tests per activeFormats revision * Rich Text: Replace existing active format in applied * Rich Text: Remove active format in all cases for removeFormat * Rich Text: Update toggleFormat tests per removeFormats revision * Testing: Update E2E test case to verify link display regression * Rich Text: Verify by test of activeFormats format replacement
Fixes #15503
Fixes #15522
This pull request seeks to resolve an issue where updates to links (and presumably any applied format?) may not immediately appear as having taken effect in the UI.
Implementation notes:
I'm not entirely comfortable in this realm of the code, but judging by some existing logic which modifies active formats in
applyFormats
for formats applied to collapsed text where the format was not already applied, I thought it might be safe to extrapolate this out to include the format as being considered active for any provided value. Alternative suggestions welcome.Testing instructions:
Repeat Steps to Reproduce from #15503 and #15522, verifying expected results.
Ensure unit tests pass: