Skip to content

Commit

Permalink
Multi select: prevent blocks from gaining focus
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 18, 2023
1 parent 0eebaf5 commit 34b6ffc
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,27 @@ export default function useSelectionObserver() {
defaultView.removeEventListener( 'mouseup', onSelectionChange );
}

function resetListeners() {
function resetListeners( event ) {
removeListeners();
addListeners();

// Forbid focus within the writing flow wrapper when it is
// editable. The browser might focus a child element, for
// example in some cases when it has a tabindex. There might be
// other unknown cases, so we just forbid focus altogether.
if ( node.isContentEditable && node !== event.target ) {
node.focus();
}
}

addListeners();
// We must allow rich text to set selection first. This ensures that
// our `selectionchange` listener is always reset to be called after
// the rich text one.
node.addEventListener( 'focusin', resetListeners );
node.addEventListener( 'focusin', resetListeners, true );
return () => {
removeListeners();
node.removeEventListener( 'focusin', resetListeners );
node.removeEventListener( 'focusin', resetListeners, true );
};
},
[ multiSelect, selectBlock, selectionChange, getBlockParents ]
Expand Down

0 comments on commit 34b6ffc

Please sign in to comment.