Skip to content

Fix issues with selected blocks#3006

Open
akulistus wants to merge 3 commits into
nextfrom
fix/replacement-of-selected-blocks
Open

Fix issues with selected blocks#3006
akulistus wants to merge 3 commits into
nextfrom
fix/replacement-of-selected-blocks

Conversation

@akulistus

Copy link
Copy Markdown
Contributor

Issues with block selection

  1. When multiple blocks are selected, keystroke is duplicated.
  2. Shift + printable key doesn't replace selected blocks.

Solutions

  1. Prevent content insertion at the caret position unless the typed key is Enter or an unrecognized key.
  2. Treat Shift + printable key as regular text input rather than a shortcut.

@neSpecc neSpecc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add tests please

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Addresses two regressions in multi-block selection editing: duplicated character insertion when multiple blocks are selected, and failure to replace selected blocks when typing Shift + printable key.

Changes:

  • Adjust block-selection key handling to avoid programmatic caret insertion for normal printable keys (preventing duplicated characters).
  • Treat Shift + printable key as normal text input (not a shortcut) so it replaces the selection.
  • Add Cypress coverage for replacing selected blocks via a single keystroke (including shifted printable input).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
test/cypress/tests/modules/Ui.cy.ts Adds Cypress tests for replacing multi-block selections with printable and shifted-printable input.
src/components/modules/blockSelection.ts Stops inserting typed printable characters via caret helper to avoid duplicate insertion when clearing a multi-block selection.
src/components/modules/blockEvents.ts Refines shortcut detection so Shift + printable is handled as text input and selection is cleared/replaced.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +130 to +134
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.should('have.text', 'f');
});
Comment on lines +164 to +167
.click()
.type('{shift+downArrow}')
.type('{shift+F}');

Comment on lines +168 to +172
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.should('have.text', 'F');
});
Comment on lines +97 to +99
describe('Replace', function() {
it('should replace selected blocks with a single keystroke', function() {
cy.createEditor({
.should('have.text', 'f');
});

it('should replace selected blocks with a single shift + keystroke', function() {
* @type {boolean}
*/
const isShortcut = event.ctrlKey || event.metaKey || event.altKey || event.shiftKey;
const isShortcut = event.ctrlKey || event.metaKey || event.altKey || (event.shiftKey && !isPrintableKey);
Comment on lines +255 to +257
if (eventKey.length > 1) {
Caret.insertContentAtCaretPosition('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants