Skip to content
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

[lexical] Bug Fix: lines were being deleted with deleteLine #6719

Merged
merged 9 commits into from
Oct 16, 2024

Conversation

taro-shono
Copy link
Contributor

Description

When I pressed ⌘ + Delete, the line was deleted. This is different from the behavior of other editors (such as textarea), so some users may find it to be a bug. Please see the video for more information about the behavior.

Before

Screen.Shot.2024-10-10.at.16.05.54.mp4

After

Screen.Shot.2024-10-10.at.16.05.25.mp4

Copy link

vercel bot commented Oct 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 1:10am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 1:10am

@facebook-github-bot
Copy link
Contributor

Hi @taro-shono!

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 cla@meta.com. Thanks!

Copy link

github-actions bot commented Oct 10, 2024

size-limit report 📦

Path Size
lexical - cjs 29.94 KB (0%)
lexical - esm 29.81 KB (0%)
@lexical/rich-text - cjs 38.54 KB (0%)
@lexical/rich-text - esm 31.61 KB (0%)
@lexical/plain-text - cjs 37.15 KB (0%)
@lexical/plain-text - esm 28.99 KB (0%)
@lexical/react - cjs 40.34 KB (+0.03% 🔺)
@lexical/react - esm 33.08 KB (0%)

@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 Oct 10, 2024
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

It would be great if this change had a test, and it is necessary for all PRs to pass the formatting and type checks. This particular formatting issue (extra indent on all changed lines) can be fixed with npm run prettier:fix or by allowing husky to get set up properly which normally happens during npm install.

I think the logic might also not be correct, it seems to me that this extend behavior only happens in other editors (I tested VSCode and Chrome's textarea on github) when the selection is collapsed at offset 0.

@taro-shono
Copy link
Contributor Author

I think the logic might also not be correct, it seems to me that this extend behavior only happens in other editors (I tested VSCode and Chrome's textarea on github) when the selection is collapsed at offset 0.

@etrepum What does that mean? Please explain in more detail.

@etrepum
Copy link
Collaborator

etrepum commented Oct 15, 2024

A collapsed selection is where the focus and anchor are the same node and offset. It displays as a cursor, no text is highlighted.

// extend the selection by one character in the specified direction.
// This ensures that the parent element is deleted along with its content.
// Otherwise, only the text content will be deleted, leaving an empty parent node.
if (this.anchor.offset === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

By collapsed I mean that this check should be more like this:

Suggested change
if (this.anchor.offset === 0) {
if (this.isCollapsed() && this.anchor.offset === 0) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you

Copy link
Contributor Author

@taro-shono taro-shono Oct 15, 2024

Choose a reason for hiding this comment

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

@etrepum isCollapsed check had already been made.

if (this.isCollapsed()) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right that a check was already made but the selection is mutated after the check is made with this.modify('extend', isBackward, 'lineboundary'); and an extend modification (if it does anything) will only change either the anchor or focus thus changing the selection so it's no longer collapsed

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 see. I've also added a test for the logic of collapsed: c26567c

Co-authored-by: Bob Ippolito <bob@redivi.com>
@@ -270,6 +272,34 @@ test.describe.parallel('Selection', () => {
);
});

test('can delete line by collapse', async ({page, isPlainText}) => {
test.skip(isPlainText || !IS_MAC);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to skip this test on mac?

Suggested change
test.skip(isPlainText || !IS_MAC);
test.skip(isPlainText);

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 think so too. But I don't know why this line:

test.skip(isPlainText || !IS_MAC);

test.skip(isPlainText || !IS_MAC);

The above test is the same as the deleteLine test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

They're not useful there either! All of them pass without it for me locally on my Mac. We can address that separately though

@etrepum etrepum added this pull request to the merge queue Oct 16, 2024
Merged via the queue into facebook:main with commit 7a80c89 Oct 16, 2024
36 of 38 checks passed
@taro-shono taro-shono deleted the fix-deleteline branch October 16, 2024 02:30
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.

4 participants