X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/97b201f61f98aaccf779d08634c247c8cfbbfbb5..refs/pull/5681/head:/resources/js/wysiwyg/utils/selection.ts diff --git a/resources/js/wysiwyg/utils/selection.ts b/resources/js/wysiwyg/utils/selection.ts index 167ab32ad..e4b5bf2dc 100644 --- a/resources/js/wysiwyg/utils/selection.ts +++ b/resources/js/wysiwyg/utils/selection.ts @@ -3,7 +3,7 @@ import { $createParagraphNode, $createRangeSelection, $getRoot, $getSelection, $isBlockElementNode, $isDecoratorNode, - $isElementNode, + $isElementNode, $isParagraphNode, $isTextNode, $setSelection, BaseSelection, DecoratorNode, @@ -60,12 +60,19 @@ export function $selectionContainsTextFormat(selection: BaseSelection | null, fo return false; } - for (const node of selection.getNodes()) { + // Check text nodes + const nodes = selection.getNodes(); + for (const node of nodes) { if ($isTextNode(node) && node.hasFormat(format)) { return true; } } + // If we're in an empty paragraph, check the paragraph format + if (nodes.length === 1 && $isParagraphNode(nodes[0]) && nodes[0].hasTextFormat(format)) { + return true; + } + return false; }