diff options
Diffstat (limited to 'app/assets/javascripts/ide/stores/mutations.js')
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations.js | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/app/assets/javascripts/ide/stores/mutations.js b/app/assets/javascripts/ide/stores/mutations.js index 8060ead5728..40baa3e7c6a 100644 --- a/app/assets/javascripts/ide/stores/mutations.js +++ b/app/assets/javascripts/ide/stores/mutations.js @@ -201,27 +201,35 @@ export default { state.changedFiles = state.changedFiles.concat(entry); parent.tree = parent.tree.filter(f => f.path !== entry.path); }, - [types.RENAME_ENTRY](state, { path, name }) { - const oldEntry = state.entries[path]; - const parent = oldEntry.parentPath - ? state.entries[oldEntry.parentPath] - : state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; - const nameRegex = new RegExp(`${oldEntry.name}$`); - const newPath = path.replace(nameRegex, name); + [types.RENAME_ENTRY](state, { path, name, entryPath = null }) { + const oldEntry = state.entries[entryPath || path]; + const nameRegex = new RegExp(`^${path}`); + const newPath = oldEntry.path.replace(nameRegex, name); + const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : ''; state.entries[newPath] = { ...oldEntry, id: newPath, key: `${name}-${oldEntry.type}-${oldEntry.id}`, path: newPath, - name, + name: entryPath ? oldEntry.name : name, tempFile: true, - prevPath: path, - url: oldEntry.url.replace(nameRegex, name), + prevPath: oldEntry.path, + url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath), + tree: [], + parentPath, }; oldEntry.moved = true; - parent.tree = parent.tree.concat(state.entries[newPath]); - state.changedFiles = state.changedFiles.concat(state.entries[newPath]); + + const parent = parentPath + ? state.entries[parentPath] + : state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; + + parent.tree = sortTree(parent.tree.concat(state.entries[newPath])); + + if (!entryPath) { + state.changedFiles = state.changedFiles.concat(state.entries[newPath]); + } }, ...projectMutations, ...mergeRequestMutation, |