Skip to content

Commit

Permalink
Fix ui.quit()
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Jun 30, 2024
1 parent fc8d89e commit 9064bc3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 59 deletions.
4 changes: 2 additions & 2 deletions denops/ddu/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export const main: Entrypoint = (denops: Denops) => {
const ddu = getDdu(name);

if (event === "close" || event === "cancel") {
ddu.quit();
await ddu.quit(denops);
}

await ddu.onEvent(denops, event);
Expand All @@ -372,7 +372,7 @@ export const main: Entrypoint = (denops: Denops) => {

if (dduLength <= 1 || opt?.quit) {
// Quit current ddu
currentDdu.quit();
await currentDdu.quit(denops);
await currentDdu.onEvent(denops, "cancel");
return;
}
Expand Down
76 changes: 19 additions & 57 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
getUi,
initSource,
sourceArgs,
uiQuit,
uiRedraw,
uiSearchItem,
} from "./ext.ts";
Expand Down Expand Up @@ -112,22 +113,7 @@ export class Ddu {

if (uiChanged) {
// Quit current UI
const [ui, uiOptions, uiParams] = await getUi(
denops,
this.#loader,
this.#options,
);
if (!ui) {
return;
}
await ui.quit({
denops,
context: this.#context,
options: this.#options,
uiOptions,
uiParams,
});
this.quit();
await this.quit(denops);
}

const checkToggle = this.#initialized && !prevSignal.aborted &&
Expand Down Expand Up @@ -165,14 +151,7 @@ export class Ddu {
}

if (checkToggle && uiOptions.toggle) {
await ui.quit({
denops,
context: this.#context,
options: this.#options,
uiOptions,
uiParams,
});
this.quit();
await this.quit(denops);
return;
}

Expand Down Expand Up @@ -220,21 +199,14 @@ export class Ddu {
}

// NOTE: UI must be reset.
const [ui, uiOptions, uiParams] = await getUi(
const [ui, uiOptions, _] = await getUi(
denops,
this.#loader,
this.#options,
);

if (checkToggle && ui && uiOptions.toggle) {
await ui.quit({
denops,
context: this.#context,
options: this.#options,
uiOptions,
uiParams,
});
this.quit();
await this.quit(denops);
return;
}

Expand Down Expand Up @@ -273,23 +245,7 @@ export class Ddu {
denops: Denops,
userOptions: UserOptions,
): Promise<void> {
// Quit current UI
const [ui, uiOptions, uiParams] = await getUi(
denops,
this.#loader,
this.#options,
);
if (!ui) {
return;
}
await ui.quit({
denops,
context: this.#context,
options: this.#options,
uiOptions,
uiParams,
});
this.quit();
await this.quit(denops);

// Disable resume
userOptions.resume = false;
Expand Down Expand Up @@ -868,7 +824,14 @@ export class Ddu {
}
}

quit() {
async quit(denops: Denops) {
await uiQuit(
denops,
this.#loader,
this.#context,
this.#options,
);

// NOTE: quitted flag must be called after ui.quit().
this.#quitted = true;
this.#aborter.abort({ reason: "quit" });
Expand Down Expand Up @@ -1048,13 +1011,12 @@ export class Ddu {

if (itemAction.actionOptions.quit && visible) {
// Quit UI before action
await ui.quit({
await uiQuit(
denops,
context: this.#context,
options: this.#options,
uiOptions,
uiParams,
});
this.#loader,
this.#context,
this.#options,
);
}
}

Expand Down
29 changes: 29 additions & 0 deletions denops/ddu/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,33 @@ async function checkUiOnInit(
}
}

export async function uiQuit<
Params extends BaseUiParams,
>(
denops: Denops,
loader: Loader,
context: Context,
options: DduOptions,
): Promise<void> {
// Quit current UI
const [ui, uiOptions, uiParams] = await getUi(
denops,
loader,
options,
);
if (!ui) {
return;
}
await ui.quit({
denops,
context,
options,
uiOptions,
uiParams,
});
ui.prevDone = false;
}

export async function uiRedraw<
Params extends BaseUiParams,
>(
Expand Down Expand Up @@ -929,6 +956,7 @@ export async function uiRedraw<
uiOptions,
uiParams,
});
ui.prevDone = false;
return;
}

Expand Down Expand Up @@ -957,6 +985,7 @@ export async function uiRedraw<
uiOptions,
uiParams,
});
ui.prevDone = false;
}

await denops.cmd("doautocmd <nomodeline> User Ddu:redraw");
Expand Down

0 comments on commit 9064bc3

Please sign in to comment.