From 43bbff3d9c989fd818f437e877886997ac496e1f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 8 Oct 2024 10:36:30 +0200 Subject: [PATCH 1/2] fix(plaintext): allow adding multiple empty lines at the end Pressing enter three times exits a CodeBlock element by default. Disable this by setting `exitOnTripleEnter` to false in plaintext editor. Signed-off-by: Max --- src/EditorFactory.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/EditorFactory.js b/src/EditorFactory.js index feeb13e1238..bd0bfbfc162 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -68,7 +68,14 @@ const createEditor = ({ language, onCreate = () => {}, onUpdate = () => {}, exte FocusTrap, ] } else { - defaultExtensions = [PlainText, CodeBlockLowlight.configure({ lowlight, defaultLanguage: language })] + defaultExtensions = [ + PlainText, + CodeBlockLowlight.configure({ + lowlight, + defaultLanguage: language, + exitOnTripleEnter: false, + }), + ] } return new Editor({ From 116a48387e5070587795d98e26be1e14e09cf056 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 8 Oct 2024 11:47:14 +0200 Subject: [PATCH 2/2] test(plaintext) add regression test for newlines Signed-off-by: Max --- src/tests/plaintext.spec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tests/plaintext.spec.js b/src/tests/plaintext.spec.js index fdd68fa0eb4..0f6f194d1d2 100644 --- a/src/tests/plaintext.spec.js +++ b/src/tests/plaintext.spec.js @@ -79,4 +79,17 @@ describe('html as plain text', () => { expect(plaintextThroughEditor('"\';&.-#><')).toBe('"\';&.-#><') expect(plaintextThroughEditor(xssFuzzVectors)).toBe(xssFuzzVectors) }) +} ) + +describe('regression tests', () => { + test('tripple enter creates new lines at end (#6507)', () => { + const tiptap = createEditor({ + enableRichEditing: false + }) + tiptap.commands.enter() + tiptap.commands.enter() + tiptap.commands.enter() + expect(serializePlainText(tiptap.state.doc)) + .toEqual("\n\n\n") + }) })