Skip to content

Commit 0beeb04

Browse files
authored
Merge pull request #228 from takker99:insert-text
refactor(api): Use `scrapbox.Page.waitForSave` to wait for `insertText` finished.
2 parents 7ad4449 + 618f996 commit 0beeb04

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

browser/dom/edit.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { textInput } from "./dom.ts";
66
import { isArray } from "@core/unknownutil/is/array";
77
import { isNumber } from "@core/unknownutil/is/number";
88
import { isString } from "@core/unknownutil/is/string";
9-
import { delay } from "@std/async/delay";
9+
import type { Scrapbox } from "@cosense/types/userscript";
10+
declare const scrapbox: Scrapbox;
1011

1112
export const undo = (count = 1): void => {
1213
for (const _ of range(0, count)) {
@@ -157,7 +158,7 @@ export const downBlocks = (count = 1): void => {
157158
}
158159
};
159160

160-
export const insertText = async (text: string): Promise<void> => {
161+
export const insertText = (text: string): Promise<void> => {
161162
const cursor = textInput();
162163
if (!cursor) {
163164
throw Error("#text-input is not ditected.");
@@ -167,5 +168,5 @@ export const insertText = async (text: string): Promise<void> => {
167168

168169
const event = new InputEvent("input", { bubbles: true });
169170
cursor.dispatchEvent(event);
170-
await delay(1); // 1ms delay to ensure event processing completes
171+
return scrapbox.Page.waitForSave();
171172
};

0 commit comments

Comments
 (0)