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 DecoratorNodes being treated as block elements #5371

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
html,
initialize,
insertCollapsible,
insertHorizontalRule,
insertImageCaption,
insertSampleImage,
insertTable,
Expand Down Expand Up @@ -521,4 +522,40 @@ test.describe('Selection', () => {
`,
);
});

test('Can use block controls on selections including decorator nodes #5371', async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText || isCollab);

await page.keyboard.type('Some text');
await insertHorizontalRule(page);
await page.keyboard.type('More text');
await selectAll(page);

await click(page, '.block-controls');
await click(page, '.dropdown .icon.h1');

await assertHTML(
page,
html`
<h1
class="PlaygroundEditorTheme__h1 PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Some text</span>
</h1>
<hr
class="selected"
contenteditable="false"
data-lexical-decorator="true" />
<h1
class="PlaygroundEditorTheme__h1 PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">More text</span>
</h1>
`,
);
});
});
9 changes: 3 additions & 6 deletions packages/lexical-selection/src/range-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import type {
DecoratorNode,
ElementNode,
INTERNAL_PointSelection,
LexicalNode,
Expand Down Expand Up @@ -568,11 +567,9 @@ export function $getSelectionStyleValueForProperty(
* This function is for internal use of the library.
* Please do not use it as it may change in the future.
*/
export function INTERNAL_$isBlock(
node: LexicalNode,
): node is ElementNode | DecoratorNode<unknown> {
if ($isDecoratorNode(node) && !node.isInline()) {
return true;
export function INTERNAL_$isBlock(node: LexicalNode): node is ElementNode {
if ($isDecoratorNode(node)) {
return false;
}
if (!$isElementNode(node) || $isRootOrShadowRoot(node)) {
return false;
Expand Down
Loading