Skip to content

Commit d950a11

Browse files
obafemitayoromotayor-testlioneSpecc
authored
Bug Fix For When "/" Overides external text (#2894)
* Bug Fix For When / Overides external text * Moved fix to blockEvents * Moved fix to blockEvents * Moved fix to blockEvents * Refactored test to simulate behaviour * Added fix to change log * Refactored test to mimick exact behaviour of the bug --------- Co-authored-by: Omotayo Obafemi <omotayo@testlio.com> Co-authored-by: Peter <specc.dev@gmail.com>
1 parent c9a6cfb commit d950a11

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

docs/CHANGELOG.md

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

1617
### 2.30.7

src/components/modules/blockEvents.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ export default class BlockEvents extends Module {
237237
* @param event - keydown
238238
*/
239239
private slashPressed(event: KeyboardEvent): void {
240+
const wasEventTriggeredInsideEditor = this.Editor.UI.nodes.wrapper.contains(event.target as Node);
241+
242+
if (!wasEventTriggeredInsideEditor) {
243+
return;
244+
}
245+
240246
const currentBlock = this.Editor.BlockManager.currentBlock;
241247
const canOpenToolbox = currentBlock.isEmpty;
242248

test/cypress/tests/modules/BlockEvents/Slash.cy.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,60 @@ describe('Slash keydown', function () {
9292
.should('eq', 'Hello/');
9393
});
9494
});
95+
96+
describe('pressed outside editor', function () {
97+
it('should not modify any text outside editor when text block is selected', () => {
98+
cy.createEditor({
99+
data: {
100+
blocks: [
101+
{
102+
type: 'paragraph',
103+
data: {
104+
text: '',
105+
},
106+
},
107+
],
108+
},
109+
});
110+
111+
cy.document().then((doc) => {
112+
const title = doc.querySelector('h1');
113+
114+
if (title) {
115+
title.setAttribute('data-cy', 'page-title');
116+
}
117+
});
118+
119+
// Step 1
120+
// Click on the plus button and select the text option
121+
cy.get('[data-cy=editorjs]')
122+
.find('.ce-paragraph')
123+
.click();
124+
cy.get('[data-cy=editorjs]')
125+
.find('.ce-toolbar__plus')
126+
.click({ force: true });
127+
cy.get('[data-cy="toolbox"] .ce-popover__container')
128+
.contains('Text')
129+
.click();
130+
131+
// Step 2
132+
// Select the 'Editor.js test page' text
133+
cy.get('[data-cy=page-title]')
134+
.invoke('attr', 'contenteditable', 'true')
135+
.click()
136+
.type('{selectall}')
137+
.invoke('removeAttr', 'contenteditable');
138+
139+
// Step 3
140+
// Press the Slash key
141+
cy.get('[data-cy=page-title]')
142+
.trigger('keydown', { key: '/',
143+
code: 'Slash',
144+
which: 191 });
145+
146+
cy.get('[data-cy=page-title]').should('have.text', 'Editor.js test page');
147+
});
148+
});
95149
});
96150

97151
describe('CMD+Slash keydown', function () {

0 commit comments

Comments
 (0)