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

fix/keyboard-shortcut-multi-block-unselect #3436

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
1 change: 1 addition & 0 deletions editor/modes/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class VisualEditor extends Component {
'mod+shift+z': this.undoOrRedo,
backspace: this.deleteSelectedBlocks,
del: this.deleteSelectedBlocks,
escape: this.props.clearSelectedBlock,
} } />
<WritingFlow>
<PostTitle />
Expand Down
61 changes: 61 additions & 0 deletions test/e2e/integration/003-multi-block-selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe( 'Multi-block selection', () => {
before( () => {
cy.newPost();
} );

it( 'Should select/unselect multiple blocks', () => {

const lastBlockSelector = '.editor-visual-editor__block-edit:last [contenteditable="true"]:first';
const firstBlockContainerSelector = '.editor-visual-editor__block:first';
const lastBlockContainerSelector = '.editor-visual-editor__block:last';
const multiSelectedCssClass = 'is-multi-selected';
Copy link
Contributor

Choose a reason for hiding this comment

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

Raised before on other PRs. We should consolidate these selectors in shared variables or use data-test attributes


// Creating test blocks
// Using the placeholder
cy.get( '[value="Write your story"]' ).click();
cy.get( lastBlockSelector ).type( 'First Paragraph' );

// Using the quick inserter
cy.get( '.editor-visual-editor__inserter [aria-label="Insert Paragraph"]' ).click();
cy.get( lastBlockSelector ).type( 'Second Paragraph' );


// Default: No selection
cy.get( firstBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);
cy.get( lastBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);


// Multiselect via Shift + click
cy.get( firstBlockContainerSelector ).click();
cy.get('body').type( '{shift}', { release: false } );
cy.get( lastBlockContainerSelector ).click();

// Verify selection
cy.get( firstBlockContainerSelector ).should('have.class', multiSelectedCssClass);
cy.get( lastBlockContainerSelector ).should('have.class', multiSelectedCssClass);

// Unselect
cy.get('body').type( '{shift}' ); // releasing shift
cy.get( lastBlockContainerSelector ).click();

// No selection
cy.get( firstBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);
cy.get( lastBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);


// Multiselect via keyboard
cy.get('body').type( '{ctrl}a' );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is failing locally, because on MacOS the shortcut is {meta}a. A simple way to fix this is to type both (and explain with a comment). But I wonder if there's a nicer way to fix it.


// Verify selection
cy.get( firstBlockContainerSelector ).should('have.class', multiSelectedCssClass);
cy.get( lastBlockContainerSelector ).should('have.class', multiSelectedCssClass);

// Unselect
cy.get('body').type( '{esc}' );

// No selection
cy.get( firstBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);
cy.get( lastBlockContainerSelector ).should('not.have.class', multiSelectedCssClass);

} );
} );