Skip to content

Fix folder rename #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/unfold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ export class DirTreeListing extends DirListing {
return this._model;
}

rename(): Promise<string> {
// 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<void> {
const entry = this.modelForClick(event);

Expand Down