Skip to content

Commit

Permalink
fix(toolbar-plugin): Adding an extra empty paragraph when insert code…
Browse files Browse the repository at this point in the history
… node
  • Loading branch information
Maksym Plavinskyi authored and Maksym Plavinskyi committed May 14, 2024
1 parent 267382e commit 3699342
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ test.describe('CodeBlock', () => {
await assertHTML(
page,
html`
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
<code
class="PlaygroundEditorTheme__code PlaygroundEditorTheme__ltr"
dir="ltr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ test.describe('Selection', () => {
dir="ltr">
<span data-lexical-text="true">Line1</span>
</p>
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
<code
class="PlaygroundEditorTheme__code PlaygroundEditorTheme__ltr"
spellcheck="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,21 @@ function BlockFormatDropDown({
let selection = $getSelection();

if (selection !== null) {
const emptyParagraph = $createParagraphNode();
const codeNode = $createCodeNode();

if (selection.isCollapsed()) {
$setBlocksType(selection, () => $createCodeNode());
$setBlocksType(selection, () => codeNode);
} else {
const textContent = selection.getTextContent();
const codeNode = $createCodeNode();
selection.insertNodes([codeNode]);
selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertRawText(textContent);
}
}

codeNode.insertBefore(emptyParagraph);
}
});
}
Expand Down

0 comments on commit 3699342

Please sign in to comment.