diff --git a/src/shared/components/BlockEditor/Block.client.js b/src/shared/components/BlockEditor/Block.client.js index 8a7f822..3ba5ed2 100644 --- a/src/shared/components/BlockEditor/Block.client.js +++ b/src/shared/components/BlockEditor/Block.client.js @@ -26,11 +26,13 @@ const Block = forwardRef(function Block( disabled, isDragOverTop, isDragOverBottom, + isSelected, onContentChange, onEnter, onBackspaceAtStart, onSlashOpen, onSlashClose, + onSelectAllBlocks, onShortcutMatch, onFocus, onDragStart, @@ -120,17 +122,26 @@ const Block = forwardRef(function Block( return; } - // Ctrl/Cmd+A : limite la sélection au bloc courant. La sélection native - // s'étend sur plusieurs contentEditable et leur suppression fusionne le - // texte en un seul bloc — bug. On force la sélection à rester ici. + // Ctrl/Cmd+A : 1er appui → sélectionne le contenu du bloc courant. + // 2e appui (le contenu est déjà entièrement sélectionné) → bascule en + // sélection multi-blocs (tous les blocs). if ((e.ctrlKey || e.metaKey) && (e.key === 'a' || e.key === 'A')) { if (el) { e.preventDefault(); - const range = document.createRange(); - range.selectNodeContents(el); const sel = window.getSelection(); - sel?.removeAllRanges(); - sel?.addRange(range); + const txt = el.textContent ?? ''; + const fullySelected = + !!sel && sel.rangeCount > 0 && !sel.isCollapsed && + el.contains(sel.anchorNode) && el.contains(sel.focusNode) && + sel.toString() === txt && txt.length > 0; + if (fullySelected) { + onSelectAllBlocks?.(); + } else { + const range = document.createRange(); + range.selectNodeContents(el); + sel?.removeAllRanges(); + sel?.addRange(range); + } } return; } @@ -227,6 +238,12 @@ const Block = forwardRef(function Block( data-block-id={block.id} > {dropIndicator} + {isSelected && ( +