diff --git a/.playwright/tests/strictMarks.spec.ts b/.playwright/tests/strictMarks.spec.ts index 646d74b88..23609b1d3 100644 --- a/.playwright/tests/strictMarks.spec.ts +++ b/.playwright/tests/strictMarks.spec.ts @@ -143,6 +143,30 @@ test.describe('strict marks', () => { await expect(boldBtn).toHaveClass(/toolbar-btn--active/); }); + test('pressing Enter in the middle of bold that is followed by plain text keeps bold and types bold', async ({ + page, + }) => { + await setEditorHtml(page, '

hello world

'); + + const editor = editorLocator(page); + const boldBtn = toolbarButton(page, 'bold'); + + await editor.click(); + await editor.press('End'); + // land in he|llo + for (let i = 0; i < 9; i++) { + await editor.press('ArrowLeft', { delay: 80 }); + } + + await editor.press('Enter'); + await expect(boldBtn).toHaveClass(/toolbar-btn--active/); + + await editor.pressSequentially('X', { delay: 80 }); + await expect(boldBtn).toHaveClass(/toolbar-btn--active/); + + await expect.poll(async () => getSerializedHtml(page)).toMatch(/

X/); + }); + test('pressing Enter after the last bold character keeps bold when the rest of the line is plain', async ({ page, }) => { diff --git a/src/web/pmPlugins/StrictMarksPlugin.ts b/src/web/pmPlugins/StrictMarksPlugin.ts index cbbc5de18..5d5220362 100644 --- a/src/web/pmPlugins/StrictMarksPlugin.ts +++ b/src/web/pmPlugins/StrictMarksPlugin.ts @@ -104,6 +104,9 @@ export const StrictMarksPlugin = Extension.create({ if (!selection.empty) return null; const docChanged = !oldState.doc.eq(newState.doc); + const selChanged = !oldState.selection.eq(newState.selection); + if (!docChanged && !selChanged) return null; + const isExplicitToggle = !docChanged && transactions.some((tr) => tr.storedMarks !== null); if (isExplicitToggle) return null;