Skip to content

Commit

Permalink
add canMergeWhenEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Jul 17, 2024
1 parent 8d078bb commit 8e97547
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ export class ListItemNode extends ElementNode {
createParentElementNode(): ElementNode {
return $createListNode('bullet');
}

canMergeWhenEmpty(): true {
return true;
}
}

function $setListItemThemeClassNames(
Expand Down
4 changes: 4 additions & 0 deletions packages/lexical-rich-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export class QuoteNode extends ElementNode {
this.replace(paragraph);
return true;
}

canMergeWhenEmpty(): true {
return true;
}
}

export function $createQuoteNode(): QuoteNode {
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1257,13 +1257,12 @@ export class RangeSelection implements BaseSelection {
const blocks = blocksParent.getChildren();
const isLI = (node: LexicalNode) =>
'__value' in node && '__checked' in node;
const isQuote = (node: LexicalNode) => node.__type === 'quote';
const isMergeable = (node: LexicalNode): node is ElementNode =>
$isElementNode(node) &&
INTERNAL_$isBlock(node) &&
!node.isEmpty() &&
$isElementNode(firstBlock) &&
(!firstBlock.isEmpty() || isLI(firstBlock) || isQuote(firstBlock));
(!firstBlock.isEmpty() || firstBlock.canMergeWhenEmpty());

const shouldInsert = !$isElementNode(firstBlock) || !firstBlock.isEmpty();
const insertedParagraph = shouldInsert ? this.insertParagraph() : null;
Expand Down
4 changes: 4 additions & 0 deletions packages/lexical/src/nodes/LexicalElementNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ export class ElementNode extends LexicalNode {
): boolean {
return false;
}

canMergeWhenEmpty(): boolean {
return false;
}
}

export function $isElementNode(
Expand Down

0 comments on commit 8e97547

Please sign in to comment.