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

Bug Fix For When "/" Overides external text #2894

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `Improvement` - The current block reference will be updated in read-only mode when blocks are clicked
- `Fix` - codex-notifier and codex-tooltip moved from devDependencies to dependencies in package.json to solve type errors
- `Fix` - Handle whitespace input in empty placeholder elements to prevent caret from moving unexpectedly to the end of the placeholder
- `Fix` - Fix when / overides selected text outside of the editor
- `DX` - Tools submodules removed from the repository

### 2.30.7
Expand Down
6 changes: 6 additions & 0 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export default class BlockEvents extends Module {
* @param event - keydown
*/
private slashPressed(event: KeyboardEvent): void {
const wasEventTriggeredInsideEditor = this.Editor.UI.nodes.wrapper.contains(event.target as Node);

if (!wasEventTriggeredInsideEditor) {
return;
}

const currentBlock = this.Editor.BlockManager.currentBlock;
const canOpenToolbox = currentBlock.isEmpty;

Expand Down
63 changes: 63 additions & 0 deletions test/cypress/tests/modules/BlockEvents/Slash.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,69 @@ describe('Slash keydown', function () {
.should('eq', 'Hello/');
});
});

describe('pressed outside editor', function () {
it('should not modify any text outside editor when text block is selected', () => {
// Create editor with an empty block
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: '',
},
},
],
},
});

// First click the plus button to open the toolbox
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.click();

cy.get('[data-cy="toolbox"] .ce-popover__container')
.should('not.be.visible');

// Get the heading text content before the slash key press
cy.get('h1')
.contains('Editor.js test page')
.invoke('text')
.then((originalText) => {
// Simulate selecting the heading text
cy.get('h1')
.contains('Editor.js test page')
.trigger('mousedown')
.trigger('mouseup');
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

// Press the slash key
cy.get('h1')
.contains('Editor.js test page')
.trigger('keydown', {
key: '/',
code: 'Slash',
keyCode: 191,
which: 191,
ctrlKey: false,
metaKey: false
});

// Verify the heading text hasn't changed
cy.get('h1')
.contains('Editor.js test page')
.should('have.text', originalText);

// Verify editor content hasn't changed and toolbox isn't open
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.should('have.text', '');

cy.get('[data-cy="toolbox"] .ce-popover__container')
.should('not.be.visible');
});
});
});
});

describe('CMD+Slash keydown', function () {
Expand Down