Traffic Boost: Fix link text selection adjustment when a link is included later in the same parent#3322
Conversation
📝 WalkthroughWalkthroughThe logic for detecting anchor ( Changes
Suggested labels
Suggested reviewers
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: .coderabbit.yaml ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)`**/*.{js,ts,tsx,jsx}`: "Perform a detailed review of the provided code with following key aspects in mind: - Review the code to ensure it is well-structured and adheres to best ...
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Description
This fixes an issue where sometimes allowed text could not be selected for link replacement:
This happened under these circumstances:
range.commonAncestorContainerto check for existing links, which is the parent<p>tag.containsAnchor()then loops through all nodes in the parent, including the link in the paragraph after the selection.containsAnchor()then mistakenly returnstrue, even though the anchor is not in the selected text.Fix
Rather than using
range.commonAncestorContainerand evaluating all nodes in the parent selection, the new code walks through the node tree fromrange.startContainertorange.endContainer. This allows us to stop checking before we run into unrelated links later in the parent element. The code borrows from this answer, which recursively visits nodes between the beginning and end nodes.Testing
To test:
In the
add/traffic-boostbranch, apply Traffic Boost to a story.Find a suggestion in a paragraph that already contains a link, like the first GIF in this issue.
Select additional text that contains the suggested text, but none of the actual link later in the paragraph.
See incorrect "Select text without existing links." text:
Switch to this branch
fix/link-replacement-with-existing-anchor.Retry the same steps. Ensure that valid highlight changes including the original suggested text can be added.
Summary by CodeRabbit