mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix(client) dom: getCurrentType
This commit is contained in:
parent
2efba6c0d7
commit
5b9e250c95
6 changed files with 90 additions and 42 deletions
|
|
@ -289,14 +289,16 @@ module.exports.isCurrentIsDir = (currentFile) => {
|
|||
const current = currentFile || DOM.getCurrentFile();
|
||||
const fileType = DOM.getCurrentType(current);
|
||||
|
||||
return DOM.isContainClass(fileType, [
|
||||
'directory',
|
||||
'directory-link',
|
||||
]);
|
||||
return /^directory(-link)?/.test(fileType);
|
||||
};
|
||||
|
||||
module.exports.getCurrentType = (currentFile) => {
|
||||
const current = currentFile || DOM.getCurrentFile();
|
||||
return DOM.getByDataName('js-type', current);
|
||||
const el = DOM.getByDataName('js-type', current);
|
||||
const type = el.className
|
||||
.split(' ')
|
||||
.pop();
|
||||
|
||||
return type;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,10 @@ test('current-file: getCurrentType', (t) => {
|
|||
|
||||
const {getByDataName} = global.DOM;
|
||||
|
||||
getByDataName.returns({
|
||||
className: 'mini-icon directory',
|
||||
});
|
||||
|
||||
const current = create();
|
||||
|
||||
currentFile.getCurrentType(current);
|
||||
|
|
@ -212,7 +216,53 @@ test('current-file: isCurrentIsDir: getCurrentType', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: isCurrentIsDir: isContainClass', (t) => {
|
||||
test('current-file: isCurrentIsDir: directory', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
|
||||
global.DOM = getDOM({
|
||||
getCurrentType: stub().returns('directory'),
|
||||
});
|
||||
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const current = create();
|
||||
|
||||
const result = currentFile.isCurrentIsDir(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: isCurrentIsDir: directory-link', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
|
||||
global.DOM = getDOM({
|
||||
getCurrentType: stub().returns('directory-link'),
|
||||
});
|
||||
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const current = create();
|
||||
|
||||
const result = currentFile.isCurrentIsDir(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: isCurrentIsDir: file', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
|
|
@ -224,19 +274,14 @@ test('current-file: isCurrentIsDir: isContainClass', (t) => {
|
|||
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const {isContainClass} = global.DOM;
|
||||
|
||||
const current = create();
|
||||
|
||||
currentFile.isCurrentIsDir(current);
|
||||
const result = currentFile.isCurrentIsDir(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(isContainClass.calledWith('file', [
|
||||
'directory',
|
||||
'directory-link',
|
||||
]));
|
||||
t.notOk(result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -801,12 +801,12 @@ function CmdProto() {
|
|||
if (cancel)
|
||||
return;
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
});
|
||||
};
|
||||
|
||||
this.duplicatePanel = () => {
|
||||
this.duplicatePanel = async () => {
|
||||
const Info = CurrentInfo;
|
||||
const {isDir} = Info;
|
||||
const panel = Info.panelPassive;
|
||||
|
|
@ -821,14 +821,14 @@ function CmdProto() {
|
|||
|
||||
const path = getPath(isDir);
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
panel,
|
||||
noCurrent,
|
||||
});
|
||||
};
|
||||
|
||||
this.swapPanels = () => {
|
||||
this.swapPanels = async () => {
|
||||
const Info = CurrentInfo;
|
||||
const {
|
||||
panel,
|
||||
|
|
@ -842,26 +842,25 @@ function CmdProto() {
|
|||
|
||||
let currentIndex = files.indexOf(element);
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
panel: panelPassive,
|
||||
noCurrent: true,
|
||||
});
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path: dirPathPassive,
|
||||
panel,
|
||||
}, () => {
|
||||
const {files} = Info;
|
||||
const length = files.length - 1;
|
||||
|
||||
if (currentIndex > length)
|
||||
currentIndex = length;
|
||||
|
||||
const el = files[currentIndex];
|
||||
|
||||
DOM.setCurrentFile(el);
|
||||
});
|
||||
|
||||
const length = Info.files.length - 1;
|
||||
|
||||
if (currentIndex > length)
|
||||
currentIndex = length;
|
||||
|
||||
const el = Info.files[currentIndex];
|
||||
|
||||
DOM.setCurrentFile(el);
|
||||
};
|
||||
|
||||
this.CurrentInfo = CurrentInfo;
|
||||
|
|
|
|||
|
|
@ -196,7 +196,9 @@ function KeyProto() {
|
|||
|
||||
case Key.F3:
|
||||
if (Info.isDir)
|
||||
loadDir({path});
|
||||
await loadDir({
|
||||
path,
|
||||
});
|
||||
else if (shift)
|
||||
CloudCmd.Markdown.show(path);
|
||||
else if (ctrlMeta)
|
||||
|
|
@ -393,7 +395,7 @@ function KeyProto() {
|
|||
|
||||
case Key.ENTER:
|
||||
if (Info.isDir)
|
||||
loadDir({path});
|
||||
await loadDir({path});
|
||||
else
|
||||
CloudCmd.View.show();
|
||||
break;
|
||||
|
|
@ -405,7 +407,7 @@ function KeyProto() {
|
|||
|
||||
case Key.BACKSLASH:
|
||||
if (ctrlMeta)
|
||||
loadDir({
|
||||
await loadDir({
|
||||
path: '/',
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ function decodePath(path) {
|
|||
.replace(NBSP_REG, SPACE) || '/';
|
||||
}
|
||||
|
||||
function onPathElementClick(panel, event) {
|
||||
async function onPathElementClick(panel, event) {
|
||||
event.preventDefault();
|
||||
|
||||
const element = event.target;
|
||||
|
|
@ -214,7 +214,7 @@ function onPathElementClick(panel, event) {
|
|||
const {href} = element;
|
||||
const path = decodePath(href);
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
isRefresh: false,
|
||||
panel: noCurrent ? panel : Info.panel,
|
||||
|
|
@ -264,13 +264,13 @@ function changePanel(element) {
|
|||
DOM.changePanel();
|
||||
}
|
||||
|
||||
function onDblClick(event) {
|
||||
async function onDblClick(event) {
|
||||
const current = getLIElement(event.target);
|
||||
const isDir = DOM.isCurrentIsDir(current);
|
||||
const path = DOM.getCurrentPath(current);
|
||||
|
||||
if (isDir) {
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path: path === '/' ? '/' : path + '/',
|
||||
});
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ function onDblClick(event) {
|
|||
}
|
||||
}
|
||||
|
||||
function onTouch(event) {
|
||||
async function onTouch(event) {
|
||||
const current = getLIElement(event.target);
|
||||
const isDir = DOM.isCurrentIsDir(current);
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ function onTouch(event) {
|
|||
if (!isCurrent)
|
||||
return;
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path: DOM.getCurrentPath(current),
|
||||
});
|
||||
}
|
||||
|
|
@ -470,14 +470,14 @@ function unload() {
|
|||
}
|
||||
|
||||
function pop() {
|
||||
Events.add('popstate', ({state}) => {
|
||||
Events.add('popstate', async ({state}) => {
|
||||
const path = (state || '').replace(FS, '');
|
||||
|
||||
if (!path)
|
||||
return CloudCmd.route(location.hash);
|
||||
|
||||
const history = false;
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
history,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ function getEnv() {
|
|||
};
|
||||
}
|
||||
|
||||
function onPath(path) {
|
||||
async function onPath(path) {
|
||||
if (Info.dirPath === path)
|
||||
return;
|
||||
|
||||
CloudCmd.loadDir({
|
||||
await CloudCmd.loadDir({
|
||||
path,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue