Skip to content

Conversation

salihudickson
Copy link

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

Copy link

vercel bot commented Jul 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Aug 24, 2025 8:13pm
lexical-playground Ready Ready Preview Comment Aug 24, 2025 8:13pm

@facebook-github-bot
Copy link
Contributor

Hi @salihudickson!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@salihudickson
Copy link
Author

@etrepum, this is the PR i spoke about in #7675. Please check it out.

@etrepum
Copy link
Collaborator

etrepum commented Jul 8, 2025

A simpler and more efficient approach here would be to have a function to normalize a RangeSelection such that the points are moved closer to each other so long as it can be done in a "zero distance" manner. It's not necessary to know the absolute positions, only the relative positions, and even then you don't have to know how much is between them only which direction they are from each other.

Either way, the most important part of this work would be to write a few tests to show that it works as expected in all of the scenarios it's supposed to cover. The actual change itself is less important than the tests that define the behavior and prevent it from regressing in the future.

@etrepum
Copy link
Collaborator

etrepum commented Jul 8, 2025

IIRC the normalization that currently happens already has a right-bias so mostly it's the focus point that would need to move (assuming the selection is already normalized to be forwards such that the focus is not before the anchor).

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 8, 2025
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@salihudickson
Copy link
Author

@etrepum, yeah that makes sense. Thanks for the suggestion.

And I'll be sure to add a bunch of test cases.

@salihudickson salihudickson changed the title [lexical-code][lexical][lexical-playground][lexical-list][lexical-rich-text] Feature: adjust text selection by node position before applying block-level formats [lexical] Fix: adjust text selection by node position before applying block-level formats Aug 8, 2025
@salihudickson
Copy link
Author

hey @etrepum, could you take another look at this PR?

@etrepum
Copy link
Collaborator

etrepum commented Aug 21, 2025

It looks like the tests are not passing, I will take a look after the tests pass. When updating this PR with main you may have to make some additional changes because the HTML output has changed after #7727 (the ltr/rtl classes are gone and the dir attribute may be set differently or not at all)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants