Skip to content

Conversation

@AlexGaillard
Copy link

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's surround() 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:

  • Explicit unlink: User clicks the link button to toggle it off (inputOpened === false) → unlink and close
  • Programmatic close: Link input is already open and needs to close for tool switching (inputOpened === true) → close cleanly without unlinking

This preserves the link when switching to other formatting tools while maintaining the unlink functionality for explicit toggle actions.

Changes

  • Updated surround() method to check inputOpened state before unlinking
  • When input is open, only close actions without removing the selection or anchor
  • When input is closed, preserve existing unlink behavior (explicit user action)

Testing

  • ✅ Build: yarn build:test — No compilation errors
  • ✅ E2E Tests: yarn test:e2e — All 348 tests passing (no regressions)
  • ✅ Link tool tests: test/cypress/tests/inline-tools/link.cy.ts — Passing

Expected Behavior After Fix

Selecting linked text and clicking Bold now results in: <a><b>linked bold text</b></a> instead of losing the link.

@AlexGaillard
Copy link
Author

Hiya 👋

This problem is a big blocker preventing some of our users from upgrading to the latest version of our product, so hopefully we can get this merged and released soon. There is of course a workaround where users can apply the tags themselves in html, but that's not feasible for non-technical users.

If we can't get this merged we'll likely need to maintain a fork to unblock our users.

TY for your time and let me know if there's anything else I need to do to get this over the line.

@akulistus
Copy link
Contributor

Hi!

Thank you for the PR — the solution looks solid :)

Could you please include a Fix entry in the CHANGELOG and if you have a moment, add some test cases?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline link tool interaction with other inline tools is broken

2 participants