Skip to content

Commit

Permalink
feature: client: move out set-current
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Dec 4, 2023
1 parent 72df428 commit 656ebd8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
37 changes: 4 additions & 33 deletions client/key/vim/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
/* global DOM */
const vim = require('./vim');
const finder = require('./find');
const {
setCurrent,
selectFileNotParent,
} = require('./set-current');

const {Dialog} = DOM;

Expand Down Expand Up @@ -120,36 +124,3 @@ const getOperations = (event, deps) => {
};

module.exports.selectFile = selectFileNotParent;

function selectFileNotParent(current, {getCurrentName, selectFile} = DOM) {
const name = getCurrentName(current);

if (name === '..')
return;

selectFile(current);
}

function setCurrent(sibling, {count, isVisual, isDelete}, {Info, setCurrentFile, unselectFiles, Operation}) {
let current = Info.element;
const select = isVisual ? selectFileNotParent : unselectFiles;

select(current);

const position = `${sibling}Sibling`;

for (let i = 0; i < count; i++) {
const next = current[position];

if (!next)
break;

current = next;
select(current);
}

setCurrentFile(current);

if (isDelete)
Operation.show('delete');
}
36 changes: 36 additions & 0 deletions client/key/vim/set-current.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

/* global DOM */
module.exports.selectFileNotParent = selectFileNotParent;
function selectFileNotParent(current, {getCurrentName, selectFile} = DOM) {
const name = getCurrentName(current);

if (name === '..')
return;

selectFile(current);
}

module.exports.setCurrent = (sibling, {count, isVisual, isDelete}, {Info, setCurrentFile, unselectFiles, Operation}) => {
let current = Info.element;
const select = isVisual ? selectFileNotParent : unselectFiles;

select(current);

const position = `${sibling}Sibling`;

for (let i = 0; i < count; i++) {
const next = current[position];

if (!next)
break;

current = next;
select(current);
}

setCurrentFile(current);

if (isDelete)
Operation.show('delete');
};

0 comments on commit 656ebd8

Please sign in to comment.