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

Fixed that the block is selected instead of the title when using the select all shortcut. #33621

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export default function useSelectAll() {
return;
}

if (
event.target.classList.contains( 'editor-post-title__input' )
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think code in the block editor package should use a classname from the editor package. The dependency is the other way, that editor package depends on block editor.

But it also doesn't cause any issues, this will just be ignored in other editors.

It could be good to see if there are other options for solving this that don't rely on an editor class name, though.

Copy link
Member Author

@torounit torounit Jul 22, 2021

Choose a reason for hiding this comment

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

Thank you @talldan
I think that point is well taken.

Conditions such as isEmpty( getSelectionStart() ) && isEmpty( getSelectionEnd() ) will cause this test to fail.
https://github.com/WordPress/gutenberg/blob/v11.1.0/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js#L656

Any good ideas to get the state that the cursor is on the title?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like @ellatrix iterated on this in #33699, sorry I couldn't provide any better suggestions.

) {
return;
}

const selectedClientIds = getSelectedBlockClientIds();

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,20 @@ describe( 'Multi-block selection', () => {
// Expect both paragraphs to be deleted.
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should select title if the cursor is on title', async () => {
await clickBlockAppender();

await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );

await page.type( '.editor-post-title__input', 'Post title' );

await pressKeyWithModifier( 'primary', 'a' );
const selectedText = await page.evaluate( () => {
return window.getSelection().toString();
} );
expect( selectedText ).toEqual( 'Post title' );
} );
} );