From d2bd5bdb5afd3f0f156a5637bd3f2c9fa6b16339 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 17 Dec 2021 15:33:40 +0100 Subject: [PATCH] Fix folder rename --- src/unfold.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/unfold.ts b/src/unfold.ts index 7b5c2f5..e3b5386 100644 --- a/src/unfold.ts +++ b/src/unfold.ts @@ -207,6 +207,32 @@ export class DirTreeListing extends DirListing { return this._model; } + rename(): Promise { + // In the case of renaming directories, we need to fix the model path + // So that it's the parent directory and not the directory itself + // + // We need to do this because we always change the model path upon directory + // selection, unlike the + + const oldModelPath = this.model.path; + // @ts-ignore + const items = this._sortedItems; + const path = Object.keys(this.selection)[0]; + // @ts-ignore + const index = ArrayExt.findFirstIndex(items, value => value.path === path); + const item: Contents.IModel = items[index]; + if (item.type === 'directory' && this.model.path === '/' + item.path) { + this.model.path = '/' + PathExt.dirname(item.path); + } + + const rename = super.rename(); + + // Revert path change + this.model.path = oldModelPath; + + return rename; + } + private async _eventDblClick(event: MouseEvent): Promise { const entry = this.modelForClick(event);