diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b8c9365..93ed9fa 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -30,7 +30,7 @@ jobs: - uses: ./.github/actions/setup-bun - name: Cache Playwright Browsers id: playwright-cache - uses: actions/cache@v4 + uses: actions/cache@v6 with: path: ~/.cache/ms-playwright key: playwright-${{ runner.os }}-${{ hashFiles('bun.lock') }} diff --git a/tests/utils.ts b/tests/utils.ts index a4577b8..682db38 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -57,7 +57,7 @@ export async function selectTextInEditor( const text = editor(page, editorName).getByText(selectedText).first() await text.click() - await text.evaluate((node, selected) => { + await text.evaluate(async (node, selected) => { const root = node.closest('[contenteditable="true"]') if (root == null) { @@ -73,18 +73,23 @@ export async function selectTextInEditor( const index = value.indexOf(selected) if (index >= 0) { - const range = document.createRange() - range.setStart(textNode, index) - range.setEnd(textNode, index + selected.length) - const selection = root.ownerDocument?.getSelection() if (selection == null) { throw new Error('Expected an active selection') } - selection.removeAllRanges() - selection.addRange(range) + await new Promise((resolve) => { + document.addEventListener('selectionchange', () => resolve(), { + once: true, + }) + selection.setBaseAndExtent( + textNode, + index, + textNode, + index + selected.length, + ) + }) return }