Skip to content

Commit

Permalink
馃憤 Use BufWipeout to fix behavior
Browse files Browse the repository at this point in the history
Close #9
  • Loading branch information
lambdalisue committed Oct 11, 2021
1 parent c73c4e3 commit ae4e644
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions denops/guise/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as autocmd from "https://deno.land/x/denops_std@v2.0.0/autocmd/mod.ts";
import * as anonymous from "https://deno.land/x/denops_std@v2.0.0/anonymous/mod.ts";
import * as batch from "https://deno.land/x/denops_std@v2.0.0/batch/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v2.0.0/function/mod.ts";
import * as option from "https://deno.land/x/denops_std@v2.0.0/option/mod.ts";
import { deferred } from "https://deno.land/std@0.109.0/async/mod.ts";

/**
Expand All @@ -23,34 +24,26 @@ export async function edit(denops: Denops, filename: string): Promise<void> {
}) as [number, number];
const auname = `guise_editor_${winid}_${bufnr}`;
const waiter = deferred<void>();
const [waiterId] = anonymous.add(denops, async (force: unknown) => {
if (
!force &&
(await fn.win_findbuf(denops, bufnr) as number[]).includes(winid)
) {
return;
}
const [waiterId] = anonymous.add(denops, async () => {
await autocmd.group(denops, auname, (helper) => {
helper.remove();
});
anonymous.remove(denops, waiterId);
waiter.resolve();
});
await autocmd.group(denops, auname, (helper) => {
helper.remove();
helper.define(
["BufEnter", "WinEnter"],
"*",
`call denops#request('${denops.name}', '${waiterId}', [v:false])`,
);
helper.define(
"VimLeave",
"*",
`call denops#request('${denops.name}', '${waiterId}', [v:true])`,
{
once: true,
},
);
await batch.batch(denops, async (denops) => {
await option.bufhidden.setLocal(denops, "wipe");
await autocmd.group(denops, auname, (helper) => {
helper.remove();
helper.define(
["BufWipeout", "VimLeave"],
"*",
`call denops#request('${denops.name}', '${waiterId}', [])`,
{
once: true,
}
);
});
});
await waiter;
}

0 comments on commit ae4e644

Please sign in to comment.