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 Clear Formatting (Fixes #4188) #4204

Merged
merged 8 commits into from
Apr 6, 2023

Conversation

ivailop7
Copy link
Collaborator

@ivailop7 ivailop7 commented Mar 25, 2023

Clear formatting respects the selection, also converts Headings and Quotes down to Paragraphs, but doesn't convert Code Blocks or any list types, matching the behaviour of other popular text editors.

Before:

clear_formatting_before.mp4

After:

clear_formatting_after.mp4

@vercel
Copy link

vercel bot commented Mar 25, 2023

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 Apr 6, 2023 0:31am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 6, 2023 0:31am

@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 25, 2023
@ivailop7
Copy link
Collaborator Author

@fantactuka could you help me out how to replace a HeadingNode with a TextNode. I tried

node.replace(new TextNode('abc'), false);

but I get an error that I can only add an Element or a Decorator node to the Root node. What would be the right syntax here?

@acywatson
Copy link
Contributor

@ivailop7 you need to wrap the TextNode in a ParagraphNode (or some other element). They can’t exist as direct children of the root.

@ivailop7
Copy link
Collaborator Author

@ivailop7 you need to wrap the TextNode in a ParagraphNode (or some other element). They can’t exist as direct children of the root.

Understood. Thank you @acywatson .

@ivailop7
Copy link
Collaborator Author

Updated. The CI failing post the Excalidraw update I believe is because of the parallelization of the tests, thus the sporadic success/failure. I believe it has to be moved from package.json inside the playground to the root one, but needs proper investigation, this is just a theory. Might dig into that one soon.

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.

Thank you! Adding some minor comments

Comment on lines 553 to 583
if (idx === 0 && anchor.offset !== 0) {
node = node.splitText(anchor.offset)[1];
}
if (idx === nodes.length - 1) {
node = node.splitText(focus.offset)[0];
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we check whether format is already 0 and style is ''? This will prevent unnecesarily splitting a node

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very good point, will amend!

Comment on lines +562 to +585
} else if ($isHeadingNode(node) || $isQuoteNode(node)) {
node.replace($createParagraphNode(), true);
Copy link
Member

Choose a reason for hiding this comment

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

Is this what's expected out of clear formatting? My hunch is that clear formatting should only clear the above (style + format) but the nodes should be left intact. What makes you think this is the correct behavior? I'm looking at Quip for example

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the behaviour in Word.

package.json Outdated
@@ -103,6 +103,7 @@
"@babel/preset-flow": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.16.7",
"@excalidraw/excalidraw": "^0.14.2",
Copy link
Member

Choose a reason for hiding this comment

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

Let's drop this and package-lock.json, I'm not sure why GH cache is sometimes bad but we can retry when this happens. Definitely something worth investigating but the package should live inside the playground

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, removing this one.

@ivailop7
Copy link
Collaborator Author

@zurfyx are we good with this one?

@zurfyx
Copy link
Member

zurfyx commented Mar 28, 2023

@zurfyx are we good with this one?

Can you check on the test failures please?

@ivailop7
Copy link
Collaborator Author

ivailop7 commented Mar 29, 2023

Ops, my fault. What's the right order of npm commands to repro these tests locally? When I directly run them, all tests fail, while Unit and Integration pass.

@zurfyx
Copy link
Member

zurfyx commented Mar 29, 2023

Ops, my fault. What's the right order of npm commands to repro these tests locally? When I directly run them, all tests fail, while Unit and Integration pass.

You probably want to run debug-test-e2e-legacy-chromium and the other similar variants listed in the package.json. The CI variants work with a different port if that's what you're referring to

@ivailop7
Copy link
Collaborator Author

@zurfyx All set here.

@ivailop7
Copy link
Collaborator Author

ivailop7 commented Apr 4, 2023

@acywatson @zurfyx I think, this one is ready to merge.

@zurfyx
Copy link
Member

zurfyx commented Apr 6, 2023

Thank you Ivaylo, sorry for the delay, I completely missed the updated version

@zurfyx zurfyx merged commit 1a144b7 into facebook:main Apr 6, 2023
@ivailop7 ivailop7 deleted the clear_formatting_fix branch April 8, 2023 20:31
@acywatson acywatson mentioned this pull request Apr 14, 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.

4 participants