Skip to content

Commit d2bd5bd

Browse files
committed
Fix folder rename
1 parent 3792d24 commit d2bd5bd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/unfold.ts

+26
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,32 @@ export class DirTreeListing extends DirListing {
207207
return this._model;
208208
}
209209

210+
rename(): Promise<string> {
211+
// In the case of renaming directories, we need to fix the model path
212+
// So that it's the parent directory and not the directory itself
213+
//
214+
// We need to do this because we always change the model path upon directory
215+
// selection, unlike the
216+
217+
const oldModelPath = this.model.path;
218+
// @ts-ignore
219+
const items = this._sortedItems;
220+
const path = Object.keys(this.selection)[0];
221+
// @ts-ignore
222+
const index = ArrayExt.findFirstIndex(items, value => value.path === path);
223+
const item: Contents.IModel = items[index];
224+
if (item.type === 'directory' && this.model.path === '/' + item.path) {
225+
this.model.path = '/' + PathExt.dirname(item.path);
226+
}
227+
228+
const rename = super.rename();
229+
230+
// Revert path change
231+
this.model.path = oldModelPath;
232+
233+
return rename;
234+
}
235+
210236
private async _eventDblClick(event: MouseEvent): Promise<void> {
211237
const entry = this.modelForClick(event);
212238

0 commit comments

Comments
 (0)