Skip to content

fix(block-events): remove line breaks with Backspace and Delete in Tools with line breaks - #3043

Open
b84330808 wants to merge 1 commit into
codex-team:nextfrom
b84330808:fix-backspace-line-breaks
Open

b84330808 wants to merge 1 commit into
codex-team:nextfrom
b84330808:fix-backspace-line-breaks

Conversation

@b84330808

Copy link
Copy Markdown

Fixes #2854. The same bug is reported in #2730, #2685 and #2609.

In a Tool with enableLineBreaks (Quote, or a custom contenteditable Tool), each Enter makes the browser wrap the new line in a <div>, and Dom.findAllInputs() lists every one of those divs as a separate input. So Backspace at the start of any line after the first is caught by BlockEvents.backspace(), which calls Caret.navigatePrevious(): the caret jumps up a line and the line break stays. Delete does the same at the end of a line (navigateNext()). Repro on the editorjs.io demo: add a Quote, type something, press Enter a few times, then Backspace.

backspace() and delete() now leave the key to the browser when the caret's input is a line inside a contenteditable that has visible content (text, a <br> or another line) before it, for Backspace, or after it, for Delete. At the start of the first line and the end of the last line the Block behaviour is unchanged, and separate inputs like the Quote text and caption are not affected.

New cases in Backspace.cy.ts and Delete.cy.ts use a Tool with enableLineBreaks. The four that remove an empty line or join two lines fail on next and pass with this change; the two that check the first/last line Block behaviour pass on both. The full Cypress suite passes in Chrome.

…ols with line breaks

In a Tool with enableLineBreaks, browsers wrap each line created by
Enter in a <div>. Dom.findAllInputs() lists those divs as separate
inputs, so Backspace at the start of a line was treated as "caret at the
start of a non-first input" and moved the caret to the previous line
instead of removing the line break. Delete had the same problem at the
end of a line.

Leave the native behaviour when there is other content before (or
after) the line in the same contenteditable. The first line and the
last line keep the existing Block behaviour.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in div content editable backspace doesnt delete blank lines

1 participant