Repository navigation
Fix: Changing URL in link after changing text outside the popover resets it #75342
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
Changes from 5 commits
25d74a2
a862b66
2faeb3e
682d12e
50af4bb
9f8933e
e0ec85b
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 |
|---|---|---|
|
|
@@ -31,8 +31,7 @@ import { createLinkFormat, isValidHref, getFormatBoundary } from './utils'; | |
| import { link as settings } from './index'; | ||
| import CSSClassesSettingComponent from './css-classes-setting'; | ||
|
|
||
| // CSSClassesSettingComponent moved to its own file and imported above. | ||
|
|
||
| const FORMAT_BOUNDARY_EDGE_OFFSET = 1; | ||
| const LINK_SETTINGS = [ | ||
| ...LinkControl.DEFAULT_LINK_SETTINGS, | ||
| { | ||
|
|
@@ -167,7 +166,23 @@ function InlineLinkUI( { | |
|
|
||
| return; | ||
| } else if ( newText === richTextText ) { | ||
| newValue = applyFormat( value, linkFormat ); | ||
| // Use explicit format boundaries rather than relying on | ||
| // the current selection which may be collapsed or | ||
| // misaligned after external value changes. | ||
| const boundary = isActive | ||
| ? getFormatBoundary( value, { | ||
| type: 'core/link', | ||
| } ) | ||
| : undefined; | ||
| newValue = applyFormat( | ||
| value, | ||
| linkFormat, | ||
| boundary?.start, | ||
| // Text *selection* always extends +1 beyond the edge of the format. Account for it. | ||
| boundary?.end !== undefined | ||
| ? boundary.end + FORMAT_BOUNDARY_EDGE_OFFSET | ||
| : undefined | ||
| ); | ||
| } else { | ||
| // Scenario: Editing an existing link. | ||
|
|
||
|
|
@@ -318,10 +333,8 @@ function getRichTextValueFromSelection( value, isActive ) { | |
| } ); | ||
|
|
||
| textStart = boundary.start; | ||
|
|
||
| // Text *selection* always extends +1 beyond the edge of the format. | ||
| // We account for that here. | ||
| textEnd = boundary.end + 1; | ||
| // Text *selection* always extends +1 beyond the edge of the format. Account for it. | ||
| textEnd = boundary.end + FORMAT_BOUNDARY_EDGE_OFFSET; | ||
|
Member
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. Not sure what you mean here. If I have "text" selected, the selection is start: 0, end: 4?
Member
Author
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. If you have "text" selected and focus moves to the Link popover, selection collapses - start: 4, end: 4. The You can log something using
Member
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. Yes, you have a format at index 0, 1, 2, 3. There's no index 4 in the text? Also, if the selection resets after moving focus to the link popover, that sounds like a bug. Selection should not change
Member
Author
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. If you select the whole linked text with a double-click and change it while the popover is open. Selection will be collapsed, which is I understand it's an odd case, but it's definitely a bug somewhere. P.S. It is easy to view the text changing flow via e2e test UI mode.
Member
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. If selection starts with start:0 and end:4, and it's collapsed, then the result will either be start:0 end:0 or start:4 end:4. Not sure why it should be start:3 end:3. I don't know anything about
Member
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. Or is it used elsewhere and is this fix also fixing a bug elsewhere?
Member
Author
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. Yes, it's internal utility for the Link format, which has a more complex editing flow compared to other formats.
Member
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 there was a bug wherever else that util is used?
Member
Author
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.
Contributor
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. Thanks for wrangling this. I only noticed the ping today I'm afraid and I didn't get time to input. I appreciate the fix 🙇 |
||
| } | ||
|
|
||
| // Get a RichTextValue containing the selected text content. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.