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

Fix toolbars that shouldn't appear in certain cases #4077

Merged
merged 9 commits into from
Mar 10, 2023

Conversation

WarrenLee19
Copy link
Contributor

@WarrenLee19 WarrenLee19 commented Mar 9, 2023

For example,
when the number of lines in the editor is more than 2,
gently double-click the end of the line, a toolbar will appear, and this toolbar will not process any text content.
In this case, it is obviously unnecessary to display the toolbar.

2023-03-09.09.38.27.mov

image
image

@facebook-github-bot
Copy link
Contributor

Hi @WarrenLee19!

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!

@vercel
Copy link

vercel bot commented Mar 9, 2023

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

Name Status Preview Comments Updated
lexical ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 10, 2023 at 5:39PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 10, 2023 at 5:39PM (UTC)

@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 Mar 9, 2023
Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! We still do formatting on collapsed selection that will carry over the following written text but since we don't show the toolbar either on collapsed selection your solution makes sense to me

@zurfyx
Copy link
Member

zurfyx commented Mar 9, 2023

Can you revise the 8 failing checks please?

@WarrenLee19
Copy link
Contributor Author

I'm going to modify these eight

@WarrenLee19
Copy link
Contributor Author

@zurfyx Hi, I have modified the judgment conditions. You can reprocess my pr. thanks

@zurfyx
Copy link
Member

zurfyx commented Mar 10, 2023

Can you double check TextFormatting.spec.mjs? Seems like the tests in this file are failing consistently

You can run npm run test-e2e-chromium -- TextFormatting.spec

@WarrenLee19
Copy link
Contributor Author

ok, let me try

@WarrenLee19
Copy link
Contributor Author

image

@WarrenLee19
Copy link
Contributor Author

@zurfyx hi, fixed it in TextFormatting.spec.mjs, please reprocess

@trueadm trueadm removed their request for review March 10, 2023 14:48
Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Hm, it turns out that the test is actually correct, we shouldn't modify it. See my proposed solution

Comment on lines 310 to 322
if ($isRangeSelection(selection) && !selection.isCollapsed()) {
const anchorOffset = selection.anchor.offset;
const focusOffset = selection.focus.offset;
if (
selection.anchor.key !== selection.focus.key &&
selection.dirty &&
focusOffset === 0 &&
anchorOffset > 0
) {
setIsText(false);
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The problem with the current solution is that when your select spans multiple characers, it gets removed as soon as you take the first action. It should remain around.

Additionally, we probably want to handle this case in a more generic manner. We know that this happens when the selection is not collapsed and when there's no content.

Unfortunately, the selection.getTextContent will includes new lines spacers in the output, that's intentional because this function is usually used to export plain text content. We can either rebuild this or assume that this is one only edge case for now and run a simple regex to drop it. I'd probably go for the easy path for now and we can revisit this later since it's quite involved (if it makes any sense to invest in this at all).

        const rawTextContent = selection.getTextContent().replace(/\n/g, '');
        if (!selection.isCollapsed() && rawTextContent === '') {
          setIsText(false);
          return;
        }

@WarrenLee19
Copy link
Contributor Author

@zurfyx hi, i has been modified based on your method and reset the TextFormatting.spec.mjs. thanks

@zurfyx
Copy link
Member

zurfyx commented Mar 10, 2023

Thank you Warren!

@zurfyx zurfyx merged commit 5cf8ce9 into facebook:main Mar 10, 2023
@zurfyx zurfyx mentioned this pull request Mar 24, 2023
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants