Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(api): Use scrapbox.Page.waitForSave to wait for insertText finished. #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions browser/dom/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -157,7 +158,7 @@ export const downBlocks = (count = 1): void => {
}
};

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

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