fix(LinkInlineTool): improve unlink behavior based on input state #2979
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.
Fix: Prevent link removal when applying bold to linked text
Fixes #2890
Problem
When a user highlighted text, created a link, and then attempted to apply bold formatting to the linked text, the link (
<a>tag) would be unexpectedly removed. The bold formatting would be applied, but the anchor tag would disappear, breaking the link functionality.Root Cause
The link tool's
surround()method was treating all cases where the selection was inside an<a>tag as an explicit "unlink" action. However, when clicking another inline tool (like Bold) while the link input was open, the popover system would programmatically call the link tool'ssurround()method to close it. This would incorrectly trigger the unlink logic, removing the anchor tag before the new tool could be applied.Solution
Modified src/components/inline-tools/inline-tool-link.ts to distinguish between:
inputOpened === false) → unlink and closeinputOpened === true) → close cleanly without unlinkingThis preserves the link when switching to other formatting tools while maintaining the unlink functionality for explicit toggle actions.
Changes
surround()method to checkinputOpenedstate before unlinkingTesting
yarn build:test— No compilation errorsyarn test:e2e— All 348 tests passing (no regressions)test/cypress/tests/inline-tools/link.cy.ts— PassingExpected Behavior After Fix
Selecting linked text and clicking Bold now results in:
<a><b>linked bold text</b></a>instead of losing the link.