fix: client: edit-names: group rename not renaming (#453)

This commit is contained in:
coderiaser 2026-01-14 14:35:29 +02:00
parent 6856207d0d
commit 9e2c5ac635

View file

@ -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();
}