diff --git a/frontend/playwright/ui/specs/text-editor-v3.spec.js b/frontend/playwright/ui/specs/text-editor-v3.spec.js index 4a5964ea01..53b439ab19 100644 --- a/frontend/playwright/ui/specs/text-editor-v3.spec.js +++ b/frontend/playwright/ui/specs/text-editor-v3.spec.js @@ -129,3 +129,27 @@ test("BUG 10467 - Auto-width text captures every typed character", async ({ await workspace.waitForSelectedShapeName("hello world"); }); +test("BUG 10531 - Entering the editor auto-selects the whole text", async ({ + page, +}) => { + const workspace = new WasmWorkspacePage(page, { textEditor: true }); + await workspace.setupEmptyFile(); + await workspace.mockGetFile("text-editor/get-file-lorem-ipsum.json"); + await workspace.goToWorkspace(); + await workspace.waitForFirstRender(); + + // Select the existing text shape and enter edit mode via Enter + await workspace.clickLeafLayer("Lorem ipsum"); + await workspace.textEditor.startEditing(); + + // Copying while editing exports only the selected text as raw text. + // Since we just entered the editor, the whole text should be selected. + await workspace.copy("keyboard"); + + // Assert the text was copied correctly + const copiedText = await page.evaluate(() => + navigator.clipboard.readText(), + ); + expect(copiedText).toBe("Lorem ipsum"); +}); + diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs index 458153f3b5..55310b0b87 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs @@ -350,7 +350,10 @@ (mf/deps contenteditable-ref) (fn [] (when-let [node (mf/ref-val contenteditable-ref)] - (.focus node)) + ;; Focus and select all text on mount (this will trigger on-focus) + (.focus node) + (text-editor/text-editor-select-all) + (wasm.api/request-render "text-editor-select-all-on-mount")) ;; On unmount, finalize the editor content and then dispose the WASM editor. ;; We finalize on unmount instead of relying on the browser blur event, because ;; it was not being reliable (timing issues, Firefox issues…)