lexical icon indicating copy to clipboard operation
lexical copied to clipboard

[lexical] Fix: adjust text selection by node position before applying block-level formats

Open salihudickson opened this issue 6 months ago • 24 comments

Description

Current Behavior

When you triple-click to select an entire line in the editor, the start of the next line is sometimes unintentionally included in the selection. This happens due to the browser’s default selection behavior and is not visibly noticeable to the user. However, it becomes apparent when applying block-level formats — since these styles affect the entire line, the formatting gets applied to both the intended line and part of the next one. This issue is most common in Chromium-based browsers. How This PR Fixes It. https://github.com/user-attachments/assets/2b59e59c-155b-4f79-8896-d7e88ce9cb12

How this PR addresses this

This PR addresses the issue by normalizing the selection before applying block-level formats. It calculates the absolute numeric position of the selection’s end, then filters out any nodes whose start position is greater than or equal to that endpoint. This ensures that only the intended line receives the formatting. https://github.com/user-attachments/assets/832a1350-622b-4418-be18-29fbceb67455

salihudickson avatar Jul 08 '25 21:07 salihudickson