mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(cloudcmd) add ability to set current file closer to removed files
This commit is contained in:
parent
0202192fc0
commit
cfa7a8b640
3 changed files with 72 additions and 3 deletions
19
client/modules/operation/get-next-current-name.js
Normal file
19
client/modules/operation/get-next-current-name.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const currify = require('currify/legacy');
|
||||
|
||||
const not = currify((array, value) => !~array.indexOf(value));
|
||||
const notOneOf = currify((a, b) => a.filter(not(b)));
|
||||
|
||||
module.exports = (currentName, names, removedNames) => {
|
||||
const i = names.indexOf(currentName);
|
||||
|
||||
const nextNames = notOneOf(names, removedNames);
|
||||
const length = nextNames.length;
|
||||
|
||||
if (nextNames[i])
|
||||
return nextNames[i];
|
||||
|
||||
return nextNames[length - 1];
|
||||
};
|
||||
|
||||
43
client/modules/operation/get-next-current-name.spec.js
Normal file
43
client/modules/operation/get-next-current-name.spec.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const getNextCurrentName = require('./get-next-current-name');
|
||||
|
||||
test('get-next-current-name', (t) => {
|
||||
const names = [
|
||||
'..',
|
||||
'hello',
|
||||
'1',
|
||||
'2',
|
||||
];
|
||||
|
||||
const removedNames = [
|
||||
'1'
|
||||
];
|
||||
|
||||
const name = getNextCurrentName('hello', names, removedNames);
|
||||
|
||||
t.equal(name, 'hello', 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('get-next-current-name: all files removed', (t) => {
|
||||
const names = [
|
||||
'..',
|
||||
'hello',
|
||||
'1',
|
||||
'2',
|
||||
];
|
||||
|
||||
const removedNames = [
|
||||
'1',
|
||||
'2',
|
||||
'hello',
|
||||
];
|
||||
|
||||
const name = getNextCurrentName('2', names, removedNames);
|
||||
|
||||
t.equal(name, '..', 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -18,6 +18,7 @@ const {
|
|||
const RESTful = require('../../dom/rest');
|
||||
const removeExtension = require('./remove-extension');
|
||||
const setListeners = require('./set-listeners');
|
||||
const getNextCurrentName = require('./get-next-current-name');
|
||||
|
||||
const removeQuery = (a) => a.replace(/\?.*/, '');
|
||||
|
||||
|
|
@ -258,13 +259,19 @@ function OperationProto(operation, data) {
|
|||
|
||||
showLoad();
|
||||
|
||||
const names = DOM.getFilenames(files);
|
||||
const removedNames = DOM.getFilenames(files);
|
||||
const names = DOM.CurrentInfo.files.map(DOM.getCurrentName);
|
||||
const prevCurrent = DOM.getCurrentName();
|
||||
const currentName = getNextCurrentName(prevCurrent, names, removedNames);
|
||||
|
||||
deleteFn(path + query, names, () => {
|
||||
deleteFn(path + query, removedNames, (e) => {
|
||||
const Storage = DOM.Storage;
|
||||
const dirPath = Info.dirPath;
|
||||
|
||||
CloudCmd.refresh();
|
||||
!e && CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
|
||||
Storage.removeMatch(dirPath);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue