fix(slash): do not handle / + shift/alt, support for ascii keyboard

This commit is contained in:
Peter Savchenko 2024-01-27 15:14:33 +03:00
parent 9542551d84
commit 9759294e96
No known key found for this signature in database
GPG key ID: E68306B1AB0F727C
4 changed files with 47 additions and 8 deletions

View file

@ -1,5 +1,10 @@
# Changelog
### 2.29.1
- `Fix` — Toolbox wont be shown when Slash pressed with along with Shift or Alt
- `Fix` — Toolbox will be opened when Slash pressed in ASCII-capable keyboard layout.
### 2.29.0
- `New` — Editor Config now has the `style.nonce` attribute that could be used to allowlist editor style tag for Content Security Policy "style-src"

View file

@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.29.0",
"version": "2.29.1",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editorjs.umd.js",
"module": "dist/editorjs.mjs",

View file

@ -52,13 +52,17 @@ export default class BlockEvents extends Module {
case _.keyCodes.TAB:
this.tabPressed(event);
break;
case _.keyCodes.SLASH:
if (event.ctrlKey || event.metaKey) {
this.commandSlashPressed();
} else {
this.slashPressed();
}
break;
}
/**
* Keyboard-layout independent handling of Slash key
*/
if (event.key === '/' || event.code === 'Slash') {
if (event.ctrlKey || event.metaKey) {
this.commandSlashPressed();
} else if (!event.shiftKey && !event.altKey) {
this.slashPressed();
}
}
}

View file

@ -23,6 +23,36 @@ describe('Slash keydown', function () {
.get('.ce-popover')
.should('be.visible');
});
[
'{shift}',
'{alt}',
'{option}',
].forEach((key) => {
it(`should not open Toolbox if Slash pressed with ${key}`, () => {
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: '',
},
},
],
},
});
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.click()
.type(`${key}/`);
cy.get('[data-cy="toolbox"]')
.get('.ce-popover')
.should('not.be.visible');
});
});
});
describe('pressed in non-empty block', function () {