Shougo / ddu-ui-ff

Fuzzy finder UI for ddu.vim
MIT License
55 stars 26 forks source link

fix: prevent multiple calls to #closeBuffer #134

Closed Milly closed 8 months ago

Milly commented 8 months ago

Problem and actual behavior

#closeBuffer() is called recursively.

In Vim and using floating,

  1. #closeBuffer() is called.
  2. #closeFilterWindow() is called in #closeBuffer()
  3. :close command is called in filter window.
  4. WinClosed autocmd raised and ddu#ui#do_action('quit') is called.
  5. #closeBuffer() is called again before the first call finishes.

Defects in actual use

(Maybe) Nothing. But it will cause bugs.

Diff ignoring spaces

There are many differences, but the reason is indentation.

> git diff -b
diff --git a/denops/@ddu-uis/ff.ts b/denops/@ddu-uis/ff.ts
index b363689..197d257 100644
--- a/denops/@ddu-uis/ff.ts
+++ b/denops/@ddu-uis/ff.ts
@@ -175,6 +175,7 @@ export class Ui extends BaseUi<Params> {
   #restcmd = "";
   #prevWinInfo: WinInfo | null = null;
   #filterBufnr = -1;
+  #bufferClosing = false;

   override async onInit(args: {
     denops: Denops;
@@ -1492,6 +1493,12 @@ export class Ui extends BaseUi<Params> {
     uiParams: Params;
     cancel: boolean;
   }): Promise<void> {
+    if (this.#bufferClosing) {
+      return;
+    }
+    this.#bufferClosing = true;
+
+    try {
       await this.#previewUi.close(args.denops, args.context, args.uiParams);
       await this.#previewUi.removePreviewedBuffers(args.denops);
       const closedFilterWindow = await this.#closeFilterWindow(args.denops);
@@ -1598,6 +1605,9 @@ export class Ui extends BaseUi<Params> {
       }

       await args.denops.dispatcher.event(args.options.name, "close");
+    } finally {
+      this.#bufferClosing = false;
+    }
   }

   async #getItem(