Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing flow: allow select all from empty selection #33446

Merged
merged 6 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/block-editor/src/components/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import useTabNav from './use-tab-nav';
import useArrowNav from './use-arrow-nav';
import useSelectAll from './use-select-all';
import { store as blockEditorStore } from '../../store';
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* Handles selection and navigation across blocks. This component should be
Expand All @@ -21,7 +25,7 @@ import { store as blockEditorStore } from '../../store';
* @param {Object} props Component properties.
* @param {WPElement} props.children Children to be rendered.
*/
export default function WritingFlow( { children } ) {
export default function WritingFlow( { children, ...props } ) {
const [ before, ref, after ] = useTabNav();
const hasMultiSelection = useSelect(
( select ) => select( blockEditorStore ).hasMultiSelection(),
Expand All @@ -31,14 +35,19 @@ export default function WritingFlow( { children } ) {
<>
{ before }
<div
{ ...props }
ref={ useMergeRefs( [
props.ref,
ref,
useMultiSelection(),
useSelectAll(),
useArrowNav(),
] ) }
className="block-editor-writing-flow"
tabIndex={ hasMultiSelection ? '0' : undefined }
className={ classNames(
props.className,
'block-editor-writing-flow'
) }
tabIndex={ -1 }
aria-label={
hasMultiSelection
? __( 'Multiple selected blocks' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ export default function useSelectAll() {

return useRefEffect( ( node ) => {
function onKeyDown( event ) {
const selectedClientIds = getSelectedBlockClientIds();

if ( ! selectedClientIds.length ) {
return;
}

if ( ! isMatch( 'core/block-editor/select-all', event ) ) {
return;
}

const selectedClientIds = getSelectedBlockClientIds();

if (
selectedClientIds.length === 1 &&
! isEntirelySelected( event.target )
Expand Down
27 changes: 12 additions & 15 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ function MaybeIframe( {
return (
<>
<EditorStyles styles={ styles } />
<div
<WritingFlow
ref={ contentRef }
className="editor-styles-wrapper"
style={ { flex: '1', ...style } }
tabIndex={ -1 }
>
{ children }
</div>
</WritingFlow>
</>
);
}
Expand All @@ -75,7 +76,7 @@ function MaybeIframe( {
contentRef={ contentRef }
style={ { width: '100%', height: '100%', display: 'block' } }
>
{ children }
<WritingFlow>{ children }</WritingFlow>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, writing flow behaviour will be set on the iframe body element.

</Iframe>
);
}
Expand Down Expand Up @@ -234,18 +235,14 @@ export default function VisualEditor( { styles } ) {
layout={ defaultLayout }
/>
) }
<WritingFlow>
{ ! isTemplateMode && (
<div className="edit-post-visual-editor__post-title-wrapper">
<PostTitle />
</div>
) }
<RecursionProvider>
<BlockList
__experimentalLayout={ layout }
/>
</RecursionProvider>
</WritingFlow>
{ ! isTemplateMode && (
<div className="edit-post-visual-editor__post-title-wrapper">
<PostTitle />
</div>
) }
<RecursionProvider>
<BlockList __experimentalLayout={ layout } />
</RecursionProvider>
</MaybeIframe>
</motion.div>
</motion.div>
Expand Down