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(keydown): trigger copy command for non range selection #6439

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mrdivyansh
Copy link
Contributor

@mrdivyansh mrdivyansh commented Jul 22, 2024

Description

The copy and cut command isn't triggered when the selection is TableSelection type. Currently, the code checks for NodeSelection; however, it should have been supporting custom selection as well.

Closes #6438

Test plan

I have added an e2e test but the test passes even without my changes. I am not sure why I can't reproduce the bug by automated interaction but manual interaction. I am looking for help on this.
The added test works for Firefox.

Before

Lexical.Playground.-.22.July.2024.mp4

After

Lexical.Playground.-.22.July.2024.1.mp4

Copy link

vercel bot commented Jul 22, 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 Aug 10, 2024 10:07am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2024 10:07am

@facebook-github-bot
Copy link
Contributor

Hi @mrdivyansh!

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!

Copy link

github-actions bot commented Jul 22, 2024

size-limit report 📦

Path Size
lexical - cjs 29.25 KB (0%)
lexical - esm 29.11 KB (0%)
@lexical/rich-text - cjs 37.66 KB (0%)
@lexical/rich-text - esm 30.9 KB (0%)
@lexical/plain-text - cjs 36.24 KB (0%)
@lexical/plain-text - esm 28.29 KB (0%)
@lexical/react - cjs 39.52 KB (0%)
@lexical/react - esm 32.39 KB (0%)

@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!

@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 22, 2024
@potatowagon
Copy link
Contributor

potatowagon commented Jul 24, 2024

similar to the test, im unable to manually reproduce the issue described in #6438

Screen.Recording.2024-07-24.at.6.02.02.PM.mov

followed the same steps listed in the issue

are u using any special setup locally?

@potatowagon potatowagon added the extended-tests Run extended e2e tests on a PR label Jul 24, 2024
@mrdivyansh
Copy link
Contributor Author

@potatowagon, you missed the 3rd step. I can see a paragraph node (409) before the table node (410) in your demo. You need to ensure there is no other nodes except a table node.

@potatowagon
Copy link
Contributor

ok i can repro the issue after including the third step

@@ -1080,7 +1079,7 @@ function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void {
dispatchCommand(editor, REDO_COMMAND, undefined);
} else {
const prevSelection = editor._editorState._selection;
if ($isNodeSelection(prevSelection)) {
if (!$isRangeSelection(prevSelection)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

have checked that this includes a solo table into the copy cmd, tho whats missing is that the table doesnt get deleted on cut (which is also happening in prod so not an issue introed in this PR)

Screen.Recording.2024-07-26.at.1.15.43.PM.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

hi @zurfyx! checking with u is this one line change safe?

// Delete the last empty paragraph
await moveToEditorEnd(page);
await page.keyboard.press('Backspace');

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why I can't reproduce the bug by automated interaction but manual interaction.

try adding an assert here to assert that the table isnt wrapped by 2 para nodes

Copy link
Contributor

Choose a reason for hiding this comment

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

if the assert fails it could be need to add keypress delays before hitting backspace

Copy link
Contributor Author

@mrdivyansh mrdivyansh Jul 27, 2024

Choose a reason for hiding this comment

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

I observed a weird behaviour with the Chrome browser. The copy function works when I intermittently switch to another tab and then return to Lexical to trigger the copy. Perhaps this is the reason the test doesn't fail for Chromium browser.

Lexical.Playground.-.27.July.2024.mp4

So, I decided to switch to Firefox with Playwright. Bang! The test failed without the PR changes and passed with the changes 🎉.

Lexical.Playground.-.27.July.2024.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

this test is failing alot on the collab e2e suite, could u please help to fix it? if not landing this change will cause the CI to be unstable

possible fixes include adding asserts and keypress delays at backspace

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 tried with assertion. They were passing. I will check the failing tests.

@potatowagon potatowagon added extended-tests Run extended e2e tests on a PR and removed extended-tests Run extended e2e tests on a PR labels Jul 29, 2024
@mrdivyansh
Copy link
Contributor Author

None of the tests fail on my local machine. Added delays and assertions. It might help.

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.

Bug: table can't be copied when only table is present
3 participants