fix(BlockEditor): trigger select-all blocks when block content is empty on Ctrl+A
This commit is contained in:
@@ -158,10 +158,13 @@ const Block = forwardRef(function Block(
|
||||
e.preventDefault();
|
||||
const sel = window.getSelection();
|
||||
const txt = el.textContent ?? '';
|
||||
if (txt.length === 0) {
|
||||
onSelectAllBlocks?.();
|
||||
} else {
|
||||
const fullySelected =
|
||||
!!sel && sel.rangeCount > 0 && !sel.isCollapsed &&
|
||||
el.contains(sel.anchorNode) && el.contains(sel.focusNode) &&
|
||||
sel.toString() === txt && txt.length > 0;
|
||||
sel.toString() === txt;
|
||||
if (fullySelected) {
|
||||
onSelectAllBlocks?.();
|
||||
} else {
|
||||
@@ -171,6 +174,7 @@ const Block = forwardRef(function Block(
|
||||
sel?.addRange(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user