-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc79ab4
commit 3240227
Showing
13 changed files
with
649 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
'use strict'; | ||
/* global CloudCmd, DOM */ | ||
|
||
const Info = DOM.CurrentInfo; | ||
const KEY = require('./key'); | ||
|
||
const fullstore = require('fullstore/legacy'); | ||
const store = fullstore(''); | ||
const visual = fullstore(false); | ||
|
||
const stopVisual = () => { | ||
visual(false); | ||
}; | ||
|
||
const end = () => { | ||
store(''); | ||
}; | ||
|
||
const rmFirst = (a) => { | ||
return a | ||
.split('') | ||
.slice(1) | ||
.join(''); | ||
}; | ||
|
||
module.exports = (key, event) => { | ||
const current = Info.element; | ||
const keyCode = event.keyCode; | ||
const prevStore = store(); | ||
|
||
const value = store(prevStore.concat(key)); | ||
|
||
if (keyCode === KEY.ENTER) | ||
return end(); | ||
|
||
if (keyCode === KEY.ESC) { | ||
DOM.unselectFiles(); | ||
visual(false); | ||
return end(); | ||
} | ||
|
||
if (key === 'j') { | ||
move('next', { | ||
prevStore, | ||
current, | ||
}); | ||
|
||
return end(); | ||
} | ||
|
||
if (key === 'k') { | ||
move('previous', { | ||
prevStore, | ||
current, | ||
}); | ||
|
||
return end(); | ||
} | ||
|
||
if (/gg/.test(value)) { | ||
move('previous', { | ||
current, | ||
prevStore, | ||
max: Infinity, | ||
}); | ||
|
||
return end(); | ||
} | ||
|
||
if (key === 'd' && (visual() || prevStore === 'd')) { | ||
CloudCmd.Operation.show('delete'); | ||
stopVisual(); | ||
return end(); | ||
} | ||
|
||
if (key === 'G') { | ||
move('next', { | ||
current, | ||
prevStore, | ||
max: Infinity, | ||
}); | ||
|
||
return end(); | ||
} | ||
|
||
if (key === 'y') { | ||
if (!visual()) | ||
return end(); | ||
|
||
DOM.Buffer.copy(); | ||
stopVisual(); | ||
DOM.unselectFiles(); | ||
return end(); | ||
} | ||
|
||
if (/^p$/i.test(key)) { | ||
DOM.Buffer.paste(); | ||
return end(); | ||
} | ||
|
||
if (/^v$/i.test(key)) { | ||
DOM.toggleSelectedFile(current); | ||
visual(!visual()); | ||
|
||
return end(); | ||
} | ||
}; | ||
|
||
module.exports.selectFile = selectFile; | ||
|
||
function move(sibling, {max, current, prevStore}) { | ||
const isDelete = prevStore[0] === 'd'; | ||
|
||
if (isDelete) { | ||
visual(true); | ||
prevStore = rmFirst(prevStore); | ||
} | ||
|
||
const n = max || getNumber(prevStore); | ||
|
||
if (isNaN(n)) | ||
return; | ||
|
||
setCurrent({ | ||
n, | ||
current, | ||
sibling, | ||
visual: visual(), | ||
}); | ||
|
||
if (isDelete) | ||
CloudCmd.Operation.show('delete'); | ||
} | ||
|
||
function getNumber(value) { | ||
if (!value) | ||
return 1; | ||
|
||
if (value === 'g') | ||
return 1; | ||
|
||
return parseInt(value); | ||
} | ||
|
||
function selectFile(current) { | ||
const name = DOM.getCurrentName(current); | ||
|
||
if (name === '..') | ||
return; | ||
|
||
DOM.selectFile(current); | ||
} | ||
|
||
function setCurrent({n, current, visual, sibling}) { | ||
const select = visual ? selectFile : DOM.unselectFile; | ||
|
||
select(current); | ||
|
||
const position = `${sibling}Sibling`; | ||
for (let i = 0; i < n; i++) { | ||
const next = current[position]; | ||
|
||
if (!next) | ||
break; | ||
|
||
current = next; | ||
select(current); | ||
} | ||
|
||
DOM.setCurrentFile(current); | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.