From a77be8b90da60b5980fee2dc37ef42bc12dd0a23 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 2 Jun 2024 17:50:55 +0900 Subject: [PATCH] Check expandedItems are exists in this.#items --- denops/ddu/ddu.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/denops/ddu/ddu.ts b/denops/ddu/ddu.ts index d3f3f06..2eeced2 100644 --- a/denops/ddu/ddu.ts +++ b/denops/ddu/ddu.ts @@ -1133,7 +1133,7 @@ export class Ddu { await this.refresh(denops); - if (searchPath.length > 0) { + if (searchPath.length <= 0) { // NOTE: If searchPath exists, expandItems() is executed. await this.restoreTree(denops); } @@ -1756,16 +1756,21 @@ export class Ddu { async restoreTree( denops: Denops, ): Promise { - if (this.#expandedItems.size === 0) { + // NOTE: Check expandedItems are exists in this.#items + const checkItems: Map = new Map(); + for (const item of this.#items) { + checkItems.set(item2Key(item), item); + } + + const restoreItems = [...this.#expandedItems.values()].filter((item) => + checkItems.has(item2Key(item)) + ).map((item) => ({ item })); + + if (restoreItems.length === 0) { return; } - await this.expandItems( - denops, - [...this.#expandedItems.values()].map((item) => ({ - item, - })), - ); + await this.expandItems(denops, restoreItems); } async #filterItems(