import { expect, openFromTree, test } from "./fixtures"; test("Move Caret to Text Start/End moves the caret and extends the selection", async ({ workbench: page }) => { await openFromTree(page, "build.gradle.kts"); const editor = page.locator(".cm-editor").first(); await editor.locator(".cm-content").focus(); const state = async () => page.evaluate(async () => { const path = "/src/editor/api.ts"; const { activeEditor } = await import(/* @vite-ignore */ path); const view = (activeEditor() as { view?: { state: unknown } } | null)?.view; if (!view) return null; const s = ( view as never as { state: { doc: { length: number }; selection: { main: { head: number; anchor: number } } } } ).state; return { docLength: s.doc.length, head: s.selection.main.head, anchor: s.selection.main.anchor }; }); const run = (id: string) => page.evaluate(async (action) => { const path = "/src/platform/actions.ts"; const { executeAction } = await import(/* @vite-ignore */ path); await executeAction(action); }, id); const before = await state(); expect(before).not.toBeNull(); await run("editor.textEnd"); expect((await state())!.head).toBe(before!.docLength); await run("editor.textStart"); expect((await state())!.head).toBe(0); await run("editor.textEndWithSelection"); const extended = (await state())!; expect(extended.head).toBe(extended.docLength); expect(extended.anchor).toBe(0); await run("editor.textStartWithSelection"); expect(await state()).toMatchObject({ anchor: 0, head: 0 }); });