Skip to content

Commit

Permalink
List View: Try adding keyboard shortcut to select all blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Sep 28, 2023
1 parent 21e2603 commit a98f918
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ListViewExpander from './expander';
import { useBlockLock } from '../block-lock';
import { store as blockEditorStore } from '../../store';
import useListViewImages from './use-list-view-images';
import { useListViewContext } from './context';

function ListViewBlockSelectButton(
{
Expand Down Expand Up @@ -64,10 +65,12 @@ function ListViewBlockSelectButton(
getBlocksByClientId,
canRemoveBlocks,
} = useSelect( blockEditorStore );
const { duplicateBlocks, removeBlocks } = useDispatch( blockEditorStore );
const { duplicateBlocks, multiSelect, removeBlocks } =
useDispatch( blockEditorStore );
const isMatch = useShortcutEventMatch();
const isSticky = blockInformation?.positionType === 'sticky';
const images = useListViewImages( { clientId, isExpanded } );
const { rootClientId } = useListViewContext();

const positionLabel = blockInformation?.positionLabel
? sprintf(
Expand Down Expand Up @@ -183,6 +186,24 @@ function ListViewBlockSelectButton(
updateFocusAndSelection( updatedBlocks[ 0 ], false );
}
}
} else if ( isMatch( 'core/block-editor/select-all', event ) ) {
if ( event.defaultPrevented ) {
return;
}
event.preventDefault();

const blockClientIds = getBlockOrder( rootClientId );
if ( ! blockClientIds.length ) {
return;
}

// Select all while passing `null` to skip focusing to the editor canvas,
// and retain focus within the list view.
multiSelect(
blockClientIds[ 0 ],
blockClientIds[ blockClientIds.length - 1 ],
null
);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function ListViewComponent(
insertedBlock,
setInsertedBlock,
treeGridElementRef: elementRef,
rootClientId,
} ),
[
draggedClientIds,
Expand All @@ -226,6 +227,7 @@ function ListViewComponent(
AdditionalBlockContent,
insertedBlock,
setInsertedBlock,
rootClientId,
]
);

Expand Down

0 comments on commit a98f918

Please sign in to comment.