Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions denops/skkeleton/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class Context {
word: "",
candidate: "",
};
// abbrevFromDirect用: abbrevセッション完了時に呼ばれるコールバック
onAbbrevDone?: () => Promise<void>;

kakutei(str: string) {
this.preEdit.doKakutei(str);
Expand Down
6 changes: 3 additions & 3 deletions denops/skkeleton/function/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function newline(context: Context) {
}
}

export function cancel(context: Context) {
export async function cancel(context: Context) {
const state = context.state;
if (
state.type === "input" &&
Expand All @@ -83,12 +83,12 @@ export function cancel(context: Context) {
context.kakutei("\x03");
}
if (config.immediatelyCancel) {
initializeState(context.state);
await initializeStateWithAbbrev(context);
return;
}
switch (state.type) {
case "input":
initializeState(state);
await initializeStateWithAbbrev(context);
break;
case "henkan":
context.state.type = "input";
Expand Down
7 changes: 6 additions & 1 deletion denops/skkeleton/function/henkan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ export async function henkanInput(context: Context, key: string) {
}
}

const wasAbbrevSession = context.onAbbrevDone !== undefined;
await kakutei(context);
await handleKey(context, keyToNotation[key] ?? key);
if (wasAbbrevSession) {
context.kakutei(key);
} else {
await handleKey(context, keyToNotation[key] ?? key);
}
}

export async function suffix(context: Context) {
Expand Down
19 changes: 19 additions & 0 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ async function enable(opts: unknown, vimStatus: unknown): Promise<string> {
return "";
}

async function abbrevFromDirect(
opts: unknown,
vimStatus: unknown,
): Promise<string> {
await enable(opts, vimStatus);
const context = currentContext.get();
context.onAbbrevDone = async () => {
await context.denops!.call("skkeleton#disable");
};
await modeFunctions.get()["abbrev"]?.(context, "");
return context.preEdit.output(context.toString());
}

async function disable(opts: unknown, vimStatus: unknown): Promise<string> {
const context = currentContext.get();
const state = currentContext.get().state;
Expand Down Expand Up @@ -303,6 +316,8 @@ export const main: Entrypoint = async (denops) => {
return buildResult(await enable(opts, vimStatus));
} else if (func === "enable") {
return buildResult(await enable(opts, vimStatus));
} else if (func === "abbrevFromDirect") {
return buildResult(await abbrevFromDirect(opts, vimStatus));
} else if (func === "disable") {
return buildResult(await disable(opts, vimStatus));
} else if (func === "toggle") {
Expand Down Expand Up @@ -374,6 +389,10 @@ export const main: Entrypoint = async (denops) => {
word: midasi,
candidate: word,
};
// abbrevFromDirectセッション中にddc経由で確定された場合の後処理
if (context.onAbbrevDone && context.mode === "abbrev") {
await initializeStateWithAbbrev(context, ["converter"]);
}
},
// deno-lint-ignore require-await
async getConfig() {
Expand Down
12 changes: 11 additions & 1 deletion denops/skkeleton/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ export async function initializeStateWithAbbrev(
ignore: string[] = [],
) {
if (context.mode === "abbrev") {
await modeChange(context, "hira");
ignore = ignore.filter((key) => key !== "converter" && key !== "table");
initializeState(context.state, ignore);
if (context.onAbbrevDone) {
// onAbbrevDoneがある場合はmodeChange("hira")をスキップし
// コールバックに後処理を委ねる(例: disable)
const callback = context.onAbbrevDone;
context.onAbbrevDone = undefined;
await callback();
} else {
await modeChange(context, "hira");
}
return;
}
initializeState(context.state, ignore);
}
Loading