Skip to content

Remove zero width space when getting text range for comment highlights #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ajwild
Copy link
Contributor

@ajwild ajwild commented Apr 3, 2025

Relations:

Motivation

When creating comments in Livingdocs it uses the selected text to create a highlight. If the text selection contains a zero width non-breaking space, which is removed when the component is blurred, then the highlight never computes the correct start and end offset for the range because the text string no longer matches.

Changelog

  • 🐞 Do not let highlight exceed text range
  • 🐞 Remove zero width space to make selection more accurate, because it will be removed on component blur via extractContent

@ajwild ajwild force-pushed the zero-width-space-text-ranges branch from f916972 to b0097a8 Compare April 3, 2025 20:32
@ajwild ajwild force-pushed the zero-width-space-text-ranges branch from b0097a8 to a6f34d6 Compare April 4, 2025 18:37
@ajwild ajwild marked this pull request as draft April 5, 2025 09:51
Comment on lines +48 to +50
// Do not let highlight exceed text range - it should also be at least 1 character long
const actualStartIndex = Math.min(Math.max(startIndex, 0), blockText.length - 1)
const actualEndIndex = Math.min(Math.max(endIndex, 1), blockText.length)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to take another look at this before merging.

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.

1 participant