mirror of
https://github.com/facebook/lexical.git
synced 2025-05-17 15:18:47 +08:00
[lexical-playground] Feature: clear blockelement formatting along with textNode (#7384)
This commit is contained in:

committed by
GitHub

parent
7dd022053c
commit
283a8fa4b1
@ -7,6 +7,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
centerAlign,
|
||||
rightAlign,
|
||||
selectAll,
|
||||
toggleBold,
|
||||
toggleItalic,
|
||||
@ -192,4 +194,53 @@ test.describe('Clear All Formatting', () => {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(`Can clear left/center/right alignment when BIU formatting already applied`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await focusEditor(page);
|
||||
|
||||
await page.keyboard.type('Hello');
|
||||
await toggleBold(page);
|
||||
await page.keyboard.type(' World');
|
||||
await rightAlign(page);
|
||||
await page.keyboard.type(' Test');
|
||||
await selectAll(page);
|
||||
await selectFromAdditionalStylesDropdown(page, '.clear');
|
||||
await assertHTML(
|
||||
page,
|
||||
html`
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr"
|
||||
style="">
|
||||
<span data-lexical-text="true">Hello World Test</span>
|
||||
</p>
|
||||
`,
|
||||
);
|
||||
});
|
||||
|
||||
test(`Can clear left/center/right alignment when BIU formatting not applied`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await focusEditor(page);
|
||||
|
||||
await page.keyboard.type('Hello World');
|
||||
await rightAlign(page);
|
||||
await page.keyboard.type(' Test');
|
||||
await centerAlign(page);
|
||||
await selectAll(page);
|
||||
await selectFromAdditionalStylesDropdown(page, '.clear');
|
||||
await assertHTML(
|
||||
page,
|
||||
html`
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr"
|
||||
style="">
|
||||
<span data-lexical-text="true">Hello World Test</span>
|
||||
</p>
|
||||
`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -276,7 +276,11 @@ export const clearFormatting = (editor: LexicalEditor) => {
|
||||
}
|
||||
if (textNode.__format !== 0) {
|
||||
textNode.setFormat(0);
|
||||
$getNearestBlockElementAncestorOrThrow(textNode).setFormat('');
|
||||
}
|
||||
const nearestBlockElement =
|
||||
$getNearestBlockElementAncestorOrThrow(textNode);
|
||||
if (nearestBlockElement.__format !== 0) {
|
||||
nearestBlockElement.setFormat('');
|
||||
}
|
||||
node = textNode;
|
||||
} else if ($isHeadingNode(node) || $isQuoteNode(node)) {
|
||||
|
Reference in New Issue
Block a user