mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix: client: edit-names: group rename not renaming (#453)
This commit is contained in:
parent
6856207d0d
commit
9e2c5ac635
1 changed files with 19 additions and 22 deletions
|
|
@ -1,21 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
const {tryToCatch} = require('try-to-catch');
|
||||
|
||||
/* global CloudCmd, DOM */
|
||||
CloudCmd.EditNames = exports;
|
||||
|
||||
const currify = require('currify');
|
||||
const exec = require('execon');
|
||||
const supermenu = require('supermenu');
|
||||
const multiRename = require('multi-rename');
|
||||
|
||||
const reject = Promise.reject.bind(Promise);
|
||||
|
||||
const Info = DOM.CurrentInfo;
|
||||
const {Dialog} = DOM;
|
||||
|
||||
const refresh = currify(_refresh);
|
||||
const rename = currify(_rename);
|
||||
|
||||
let Menu;
|
||||
|
||||
const ConfigView = {
|
||||
|
|
@ -93,7 +89,7 @@ function setListeners() {
|
|||
DOM.Events.addOnce('contextmenu', element, setMenu);
|
||||
}
|
||||
|
||||
function applyNames() {
|
||||
async function applyNames() {
|
||||
const dir = Info.dirPath;
|
||||
const from = getActiveNames();
|
||||
const nameIndex = from.indexOf(Info.name);
|
||||
|
|
@ -105,18 +101,18 @@ function applyNames() {
|
|||
|
||||
const root = CloudCmd.config('root');
|
||||
|
||||
Promise
|
||||
.resolve(root)
|
||||
.then(rename(dir, from, to))
|
||||
.then(refresh(to, nameIndex))
|
||||
.catch(alert);
|
||||
const response = rename(dir, from, to, root);
|
||||
const [error] = await tryToCatch(refresh, to, nameIndex, response);
|
||||
|
||||
if (error)
|
||||
alert(error);
|
||||
}
|
||||
|
||||
function _refresh(to, nameIndex, res) {
|
||||
if (res.status === 404)
|
||||
return res
|
||||
.text()
|
||||
.then(reject);
|
||||
function refresh(to, nameIndex, res) {
|
||||
if (res.status === 404) {
|
||||
const error = res.text();
|
||||
throw error;
|
||||
}
|
||||
|
||||
const currentName = to[nameIndex];
|
||||
|
||||
|
|
@ -132,7 +128,7 @@ function getDir(root, dir) {
|
|||
return root + dir;
|
||||
}
|
||||
|
||||
function _rename(path, from, to, root) {
|
||||
function rename(path, from, to, root) {
|
||||
const dir = getDir(root, path);
|
||||
const {prefix} = CloudCmd;
|
||||
|
||||
|
|
@ -172,8 +168,8 @@ function setMenu(event) {
|
|||
};
|
||||
|
||||
const menuData = {
|
||||
'Save Ctrl+S': () => {
|
||||
applyNames();
|
||||
'Save Ctrl+S': async () => {
|
||||
await applyNames();
|
||||
hide();
|
||||
},
|
||||
'Go To Line Ctrl+G': () => {
|
||||
|
|
@ -214,6 +210,7 @@ async function isChanged() {
|
|||
if (!editor.isChanged())
|
||||
return;
|
||||
|
||||
const [, names] = await Dialog.confirm(msg);
|
||||
names && applyNames();
|
||||
const [cancel] = await Dialog.confirm(msg);
|
||||
|
||||
!cancel && await applyNames();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue