🐛 Fix text editor not auto-selecting all text on mount (#10573)

This commit is contained in:
Belén Albeza 2026-07-10 11:08:10 +02:00 committed by GitHub
parent 3ee5b50007
commit 3469867cf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -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");
});

View File

@ -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…)