Skip to content

fix: add link on commented text removes the comment highlight (2573)#2592

Open
miadnguyen wants to merge 1 commit intoTypeCellOS:mainfrom
miadnguyen:fix/preserve-comment-mark-on-link-edit
Open

fix: add link on commented text removes the comment highlight (2573)#2592
miadnguyen wants to merge 1 commit intoTypeCellOS:mainfrom
miadnguyen:fix/preserve-comment-mark-on-link-edit

Conversation

@miadnguyen
Copy link

@miadnguyen miadnguyen commented Mar 24, 2026

Summary

This pull request fixes an issue where adding or editing a link on commented text removes the comment highlight and comment association. After this change, a link can be added or edited on commented text while preserving both the link underline and the existing comment behavior.

Rationale

The issue was caused by LinkToolbarExtension.editLink() (from packages/core/src/extensions/LinkToolbar/LinkToolbar.ts) replacing the selected text with insertText(...) and then reapplying only the link mark. As a result, existing marks on that text, including the comment mark, were lost. Preserving existing non-link marks makes link editing behave correctly and keeps comment functionality intact.

Changes

  • Updated LinkToolbarExtension.editLink() to preserve existing marks on the selected text before replacing it
  • Reapplied existing non-link marks after insertText(...)
  • Reapplied the updated link mark after restoring the preserved marks

Impact

This change affects the link editing flow for text that already contains other marks, especially comments. It should improve behavior by preserving comment highlighting and comment accessibility when links are added or edited. The intended behavior for normal link editing remains the same.

Testing

Manual testing performed in the local comment demo:

  • Added a comment to selected text
  • Added a link to that same text
  • Edited the link on commented text
  • Verified the link underline remained
  • Verified the comment highlight remained
  • Verified the comment was still accessible after the link was added/edited

Screenshots/Video

Below is an image showing commented text retaining the comment, highlight, and link after the fix.
image

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

Fixes #2573

Summary by CodeRabbit

Bug Fixes

  • Fixed link editing to properly preserve other text formatting (bold, italic, etc.) when updating link URLs
  • Improved focus handling in link toolbar operations to ensure it occurs after changes are committed

@vercel
Copy link

vercel bot commented Mar 24, 2026

@miadnguyen is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0a5a9db-9f99-4d5d-828c-2b2aa2b939c5

📥 Commits

Reviewing files that changed from the base of the PR and between af3737a and 9da3e59.

📒 Files selected for processing (1)
  • packages/core/src/extensions/LinkToolbar/LinkToolbar.ts

📝 Walkthrough

Walkthrough

The editLink operation in LinkToolbar was updated to preserve non-link marks (such as comment highlights) when editing links. The logic now captures the link range, inserts new text, collects and reapplies all non-link marks, then adds the link mark. The focus call was moved outside the transaction callback.

Changes

Cohort / File(s) Summary
LinkToolbar Mark Preservation
packages/core/src/extensions/LinkToolbar/LinkToolbar.ts
Modified editLink operation to preserve non-link marks when editing links. Now captures existing link range, inserts text, reapplies all marks except "link" type over inserted span, then applies link mark. Moved focus call outside transaction completion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰✨ A link that shines without a care,

Preserving comments floating there,

Marks are kept in their rightful place,

While links now get their featured space! 📝🔗

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main bug fix: preventing link editing from removing comment highlights, with issue reference #2573.
Description check ✅ Passed The description covers all key template sections: Summary, Rationale, Changes, Impact, Testing, Screenshots, and Checklist with appropriate detail level.
Linked Issues check ✅ Passed The PR directly addresses the requirement from issue #2573 by preserving the comment mark when editing links, ensuring comment highlights remain visible alongside link formatting.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the link editing behavior by preserving non-link marks; no unrelated modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Add link on commented text removes the comment highlight

1 participant