Skip to content
Open
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
14 changes: 9 additions & 5 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ export default class BlockEvents extends Module {
* - close Toolbar
* - clear block highlighting
*/
if (_.isPrintableKey(event.keyCode)) {

const isPrintableKey = _.isPrintableKey(event.keyCode);

if (isPrintableKey) {
this.Editor.Toolbar.close();

/**
* Allow to use shortcuts with selected blocks
*
* @type {boolean}
*/
const isShortcut = event.ctrlKey || event.metaKey || event.altKey || event.shiftKey;
const isShortcut = event.ctrlKey || event.metaKey || event.altKey || (event.shiftKey && !isPrintableKey);

if (!isShortcut) {
this.Editor.BlockSelection.clearSelection(event);
Expand Down Expand Up @@ -660,15 +663,16 @@ export default class BlockEvents extends Module {
const toolboxItemSelected = (event.keyCode === _.keyCodes.ENTER && this.Editor.Toolbar.toolbox.opened),
blockSettingsItemSelected = (event.keyCode === _.keyCodes.ENTER && this.Editor.BlockSettings.opened),
inlineToolbarItemSelected = (event.keyCode === _.keyCodes.ENTER && this.Editor.InlineToolbar.opened),
flippingToolbarItems = event.keyCode === _.keyCodes.TAB;
flippingToolbarItems = event.keyCode === _.keyCodes.TAB,
shiftKeyEventEmitted = event.shiftKey && !_.isPrintableKey(event.keyCode);

/**
* Do not close Toolbar in cases:
* 1. ShiftKey pressed (or combination with shiftKey)
* 1. ShiftKey event emitted
* 2. When Toolbar is opened and Tab leafs its Tools
* 3. When Toolbar's component is opened and some its item selected
*/
return !(event.shiftKey ||
return !(shiftKeyEventEmitted ||
flippingToolbarItems ||
toolboxItemSelected ||
blockSettingsItemSelected ||
Expand Down
4 changes: 3 additions & 1 deletion src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ export default class BlockSelection extends Module {
*
* @see https://developer.mozilla.org/ru/docs/Web/API/KeyboardEvent/key
*/
Caret.insertContentAtCaretPosition(eventKey.length > 1 ? '' : eventKey);
if (eventKey.length > 1) {
Caret.insertContentAtCaretPosition('');
}
Comment on lines +255 to +257
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
}, 20)();
}
Expand Down
78 changes: 78 additions & 0 deletions test/cypress/tests/modules/Ui.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,84 @@ describe('Ui module', function () {
});
});
});

describe('Replace', function() {
it('should replace selected blocks with a single keystroke', function() {
cy.createEditor({
Comment on lines +97 to +99
data: {
blocks: [
{
id: 'block1',
type: 'paragraph',
data: {
text: 'The first block',
},
},
{
id: 'block2',
type: 'paragraph',
data: {
text: 'The second block',
},
},
],
},
}).as('editorInstance');

/**
* Select two blocks by shift+down
*/
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.click()
.type('{shift+downArrow}')
.type('f');

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.should('have.text', 'f');
});
Comment on lines +130 to +134

it('should replace selected blocks with a single shift + keystroke', function() {
cy.createEditor({
data: {
blocks: [
{
id: 'block1',
type: 'paragraph',
data: {
text: 'The first block',
},
},
{
id: 'block2',
type: 'paragraph',
data: {
text: 'The second block',
},
},
],
},
}).as('editorInstance');

/**
* Select two blocks by shift+down
*/
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.click()
.type('{shift+downArrow}')
.type('{shift+F}');

Comment on lines +164 to +167
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.first()
.should('have.text', 'F');
});
Comment on lines +168 to +172
});
});

describe('mousedown', function () {
Expand Down
Loading