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

fix: properly handle visible whitespaces in empty blocks #2865

Open
wants to merge 9 commits into
base: next
Choose a base branch
from
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `Fix` - Several toolbox items exported by the one tool have the same shortcut displayed in toolbox
- `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

### 2.30.7

Expand Down
1 change: 0 additions & 1 deletion example/tools/checklist
Submodule checklist deleted from 1c116d
1 change: 0 additions & 1 deletion example/tools/code
neSpecc marked this conversation as resolved.
Outdated
Show resolved Hide resolved
Submodule code deleted from f28199
1 change: 0 additions & 1 deletion example/tools/delimiter
Submodule delimiter deleted from 4ca1c1
1 change: 0 additions & 1 deletion example/tools/embed
Submodule embed deleted from f2585a
1 change: 0 additions & 1 deletion example/tools/header
Submodule header deleted from 477853
1 change: 0 additions & 1 deletion example/tools/image
Submodule image deleted from 25d46c
1 change: 0 additions & 1 deletion example/tools/inline-code
Submodule inline-code deleted from dcd4c1
1 change: 0 additions & 1 deletion example/tools/list
Submodule list deleted from a6dc6a
1 change: 0 additions & 1 deletion example/tools/nested-list
Submodule nested-list deleted from 591bd2
1 change: 0 additions & 1 deletion example/tools/quote
Submodule quote deleted from 9377ca
1 change: 0 additions & 1 deletion example/tools/table
Submodule table deleted from 2948cd
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.31.0-rc.5",
"version": "2.31.0-rc.6",
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
"main": "dist/editorjs.umd.js",
"module": "dist/editorjs.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/components/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export default class Dom {
nodeText = nodeText.replace(new RegExp(ignoreChars, 'g'), '');
}

return nodeText.trim().length === 0;
return nodeText.length === 0;
}

/**
Expand Down
28 changes: 25 additions & 3 deletions test/cypress/tests/modules/BlockEvents/Backspace.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ describe('Backspace keydown', function () {
.last()
.should('have.text', '12');
});

it('   | — should delete visible and invisble whitespaces in the abscence of any non whitespace characters', function () {
createEditorWithTextBlocks([
'1',
'   ',
]);

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.last()
.click()
.type('{downArrow}')
.type('{backspace}')
.type('{backspace}')
.type('{backspace}')
.type('{backspace}');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.last()
.should('have.text', '1');
});
});

it('should just delete chars (native behaviour) when some fragment is selected', function () {
Expand Down Expand Up @@ -184,7 +206,7 @@ describe('Backspace keydown', function () {
* Saving logic is not necessary for this test
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
public save(): void {}
public save(): void { }
}

cy.createEditor({
Expand Down Expand Up @@ -545,7 +567,7 @@ describe('Backspace keydown', function () {
* Saving logic is not necessary for this test
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
public save(): void {}
public save(): void { }
}

cy.createEditor({
Expand Down Expand Up @@ -678,7 +700,7 @@ describe('Backspace keydown', function () {

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

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
Expand Down
17 changes: 17 additions & 0 deletions test/cypress/tests/ui/Placeholders.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ describe('Placeholders', function () {
.getPseudoElementContent('::before')
.should('eq', 'none');
});

it('should be hidden when user adds trailing whitespace characters', function () {
cy.createEditor({
placeholder: PLACEHOLDER_TEXT,
});

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.as('firstBlock')
.getPseudoElementContent('::before')
.should('eq', PLACEHOLDER_TEXT);

cy.get('@firstBlock')
.type(' ')
.getPseudoElementContent('::before')
.should('eq', 'none');
});
});
Loading