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 f678d85
Showing 1 changed file with 6 additions and 2 deletions.
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 f678d85

Please sign in to comment.