fix(QEditor): save selection range before execCommand('createLink') t…#18249
Merged
rstoenescu merged 2 commits intoquasarframework:devfrom Mar 20, 2026
Merged
Conversation
…o fix hyperlink on formatted text
When selecting text with mixed formatting (e.g., bold + plain),
document.execCommand('createLink') mutates the DOM by splitting the
selection into separate <a> elements per formatting context. Previously,
the selection range was saved *after* this mutation, so only the first
<a> element's range was preserved. On 'Update', caret.restore() would
then only reselect that partial content, causing the final URL to be
applied to just one portion of the original selection.
Fix: save the range *before* calling execCommand('createLink') so the
full original selection is preserved and correctly restored when the
user confirms the URL.
Fixes #<issue-number>
… on formatted text
UI Tests Results 1 files 98 suites 40s ⏱️ Results for commit 7ec2fbb. |
Contributor
Author
|
@rstoenescu pls review this pr |
Member
|
Thanks for contributing! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
The PR fulfills these requirements:
devbranch (orv[X]branch)fix: #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
When selecting text with mixed formatting (e.g.,
**bold** plain) and applying a hyperlink via the Link toolbar button, the hyperlink was not being applied to the full selection.Root Cause:
document.execCommand('createLink')mutates the DOM by splitting a mixed-format selection into separate<a>elements per formatting context:The selection range was saved after this mutation, so
getRangeAt(0)only captured the first<a>element's range. When the user confirmed the URL,restore()reselected only that partial content, and the finalcreateLinkonly updated one anchor'shref.Fix:
Move
this.save(selection.getRangeAt(0))to beforedocument.execCommand('createLink', ...)inui/src/components/editor/editor-caret.js, so the full original selection is preserved before the DOM is mutated.Since
createLinkonly re-parents existing text nodes (it doesn't create new ones), the saved range node references remain valid after the mutation.restore()then correctly reselects the full original content, and the finalcreateLinkcall updates all anchorhrefvalues.fixes #18233