From 618f996fee6e50127368a5be2a83a2ad8269426a Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Fri, 11 Apr 2025 13:04:52 +0900 Subject: [PATCH] refactor(api): Use `scrapbox.Page.waitForSave` to wait for `insertText` finished. --- browser/dom/edit.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/browser/dom/edit.ts b/browser/dom/edit.ts index a1a66b9..e08fc33 100644 --- a/browser/dom/edit.ts +++ b/browser/dom/edit.ts @@ -6,7 +6,8 @@ import { textInput } from "./dom.ts"; import { isArray } from "@core/unknownutil/is/array"; import { isNumber } from "@core/unknownutil/is/number"; import { isString } from "@core/unknownutil/is/string"; -import { delay } from "@std/async/delay"; +import type { Scrapbox } from "@cosense/types/userscript"; +declare const scrapbox: Scrapbox; export const undo = (count = 1): void => { for (const _ of range(0, count)) { @@ -157,7 +158,7 @@ export const downBlocks = (count = 1): void => { } }; -export const insertText = async (text: string): Promise => { +export const insertText = (text: string): Promise => { const cursor = textInput(); if (!cursor) { throw Error("#text-input is not ditected."); @@ -167,5 +168,5 @@ export const insertText = async (text: string): Promise => { const event = new InputEvent("input", { bubbles: true }); cursor.dispatchEvent(event); - await delay(1); // 1ms delay to ensure event processing completes + return scrapbox.Page.waitForSave(); };