import {test, expect} from '../../fixtures/test' // Formatting applied to a selection that spans multiple paragraphs must affect // all selected content, not just the anchor paragraph. This tests TinyMCE's // range-based formatting against a refactor that might break multi-node ranges. test.describe('cross-paragraph selection formatting', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) test('bold applied to multi-paragraph selection wraps all selected paragraphs', async ({ page, rcePage, }) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

paragraph one

paragraph two

') }) // Select all content across both paragraphs await rcePage.contentFrame().locator('body').press('Control+a') await page.keyboard.press('Control+b') const content = await rcePage.getContent() // Both paragraphs should now be bold expect(content).toMatch(/.*paragraph one.*<\/strong>/s) expect(content).toContain('paragraph two') expect(content).toMatch(//) }) test('italic applied to all content via Ctrl+A affects all paragraphs', async ({ page, rcePage, }) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

first

second

third

') }) await rcePage.contentFrame().locator('body').press('Control+a') await page.keyboard.press('Control+i') const content = await rcePage.getContent() const emCount = (content.match(//g) ?? []).length // At least one per paragraph (some may share) expect(emCount).toBeGreaterThanOrEqual(1) expect(content).toContain('first') expect(content).toContain('third') }) test('heading applied to entire content changes all blocks', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

block one

block two

') }) await rcePage.contentFrame().locator('body').press('Control+a') await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.execCommand('FormatBlock', false, 'h2') }) const content = await rcePage.getContent() const h2Count = (content.match(/

{ await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent( '

bold italic one

bold two

', ) }) await rcePage.contentFrame().locator('body').press('Control+a') // Clear formatting via Format menu await page.locator('.tox-menubar button[role="menuitem"]:has-text("Format")').click() await page.locator('.tox-collection__item:has-text("Clear formatting")').click() const content = await rcePage.getContent() expect(content).toContain('bold italic one') expect(content).toContain('bold two') expect(content).not.toMatch(//) expect(content).not.toMatch(//) }) })