Skip to content

Commit 931ed20

Browse files
authored
fix: resolve whitespace bug and bump version to 2.30.8 (#2881)
1 parent 597bde3 commit 931ed20

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

docs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.30.8
4+
5+
- `Fix` - Handle whitespace input in empty placeholder elements to prevent caret from moving unexpectedly to the end of the placeholder
6+
37
### 2.30.7
48

59
- `Fix` - Link insertion in Safari fixed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/editorjs",
3-
"version": "2.30.7",
3+
"version": "2.30.8",
44
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
55
"main": "dist/editorjs.umd.js",
66
"module": "dist/editorjs.mjs",

src/components/dom.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export default class Dom {
373373
nodeText = nodeText.replace(new RegExp(ignoreChars, 'g'), '');
374374
}
375375

376-
return nodeText.trim().length === 0;
376+
return nodeText.length === 0;
377377
}
378378

379379
/**

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

+26-3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ describe('Backspace keydown', function () {
118118
.last()
119119
.should('have.text', '12');
120120
});
121+
122+
123+
it('   | — should delete visible and invisble whitespaces in the abscence of any non whitespace characters', function () {
124+
createEditorWithTextBlocks([
125+
'1',
126+
'   ',
127+
]);
128+
129+
cy.get('[data-cy=editorjs]')
130+
.find('.ce-paragraph')
131+
.last()
132+
.click()
133+
.type('{downArrow}')
134+
.type('{backspace}')
135+
.type('{backspace}')
136+
.type('{backspace}')
137+
.type('{backspace}');
138+
139+
cy.get('[data-cy=editorjs]')
140+
.find('div.ce-block')
141+
.last()
142+
.should('have.text', '1');
143+
});
121144
});
122145

123146
it('should just delete chars (native behaviour) when some fragment is selected', function () {
@@ -184,7 +207,7 @@ describe('Backspace keydown', function () {
184207
* Saving logic is not necessary for this test
185208
*/
186209
// eslint-disable-next-line @typescript-eslint/no-empty-function
187-
public save(): void {}
210+
public save(): void { }
188211
}
189212

190213
cy.createEditor({
@@ -545,7 +568,7 @@ describe('Backspace keydown', function () {
545568
* Saving logic is not necessary for this test
546569
*/
547570
// eslint-disable-next-line @typescript-eslint/no-empty-function
548-
public save(): void {}
571+
public save(): void { }
549572
}
550573

551574
cy.createEditor({
@@ -678,7 +701,7 @@ describe('Backspace keydown', function () {
678701

679702
describe('at the start of the first Block', function () {
680703
it('should do nothing if Block is not empty', function () {
681-
createEditorWithTextBlocks([ 'The only block. Not empty' ]);
704+
createEditorWithTextBlocks(['The only block. Not empty']);
682705

683706
cy.get('[data-cy=editorjs]')
684707
.find('.ce-paragraph')

test/cypress/tests/ui/Placeholders.cy.ts

+17
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,21 @@ describe('Placeholders', function () {
7777
.getPseudoElementContent('::before')
7878
.should('eq', 'none');
7979
});
80+
81+
it('should be hidden when user adds trailing whitespace characters', function () {
82+
cy.createEditor({
83+
placeholder: PLACEHOLDER_TEXT,
84+
});
85+
86+
cy.get('[data-cy=editorjs]')
87+
.find('.ce-paragraph')
88+
.as('firstBlock')
89+
.getPseudoElementContent('::before')
90+
.should('eq', PLACEHOLDER_TEXT);
91+
92+
cy.get('@firstBlock')
93+
.type(' ')
94+
.getPseudoElementContent('::before')
95+
.should('eq', 'none');
96+
});
8097
});

0 commit comments

Comments
 (0)