store subset of entry data in clipboard

This commit is contained in:
joshuaboud 2022-06-16 15:00:07 -03:00
parent 5fe2575c0d
commit eb9e84260d
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E
2 changed files with 37 additions and 13 deletions

View File

@ -119,7 +119,7 @@ export default {
return; // changed directory before could finish return; // changed directory before could finish
} }
const selectedIds = gatherEntries([], false).filter(entry => entry.selected).map(entry => entry.uniqueId); const selectedIds = gatherEntries([], false).filter(entry => entry.selected).map(entry => entry.uniqueId);
const clipboardIds = clipboard.content.map(entry => entry.uniqueId); const clipboardIds = clipboard.content.map(item => item.uniqueId);
tmpEntries.map(entry => { tmpEntries.map(entry => {
entry.selected = selectedIds.includes(entry.uniqueId); entry.selected = selectedIds.includes(entry.uniqueId);
entry.cut = clipboardIds.includes(entry.uniqueId); entry.cut = clipboardIds.includes(entry.uniqueId);

View File

@ -166,7 +166,16 @@ export default {
return directoryEntryListRef.value?.refresh?.(); return directoryEntryListRef.value?.refresh?.();
} }
const getSelected = () => directoryEntryListRef.value?.gatherEntries().filter(entry => entry.selected) ?? []; /**
* Recursive get all entries for browser
*
* @param {DirectoryEntryObj[]} - Holds all entries
*
* @returns {DirectoryEntryObj[]} - the accumulator
*/
const gatherEntries = (accumulator = [], onlyVisible = true) => directoryEntryListRef.value?.gatherEntries(accumulator, onlyVisible) ?? [];
const getSelected = () => gatherEntries().filter(entry => entry.selected);
const tallySelected = () => { const tallySelected = () => {
selectedCount.value = getSelected().length; selectedCount.value = getSelected().length;
@ -179,7 +188,7 @@ export default {
if (!ctrlKey) if (!ctrlKey)
deselectAll(); deselectAll();
if (shiftKey && lastSelectedEntry !== null) { if (shiftKey && lastSelectedEntry !== null) {
const entries = directoryEntryListRef.value?.gatherEntries(); const entries = gatherEntries();
let [startInd, endInd] = [entries.indexOf(lastSelectedEntry), entries.indexOf(entry)]; let [startInd, endInd] = [entries.indexOf(lastSelectedEntry), entries.indexOf(entry)];
if (startInd != -1 && endInd != -1) { if (startInd != -1 && endInd != -1) {
if (endInd < startInd) if (endInd < startInd)
@ -201,11 +210,11 @@ export default {
} }
const selectAll = () => { const selectAll = () => {
selectedCount.value = directoryEntryListRef.value?.gatherEntries().map(entry => entry.selected = true).length ?? 0; selectedCount.value = gatherEntries().map(entry => entry.selected = true).length ?? 0;
} }
const deselectAll = (event) => { const deselectAll = (event) => {
directoryEntryListRef.value?.gatherEntries([], false).map(entry => entry.selected = false); gatherEntries([], false).map(entry => entry.selected = false);
selectedCount.value = 0; selectedCount.value = 0;
} }
@ -213,7 +222,7 @@ export default {
if (!(ctrlKey || shiftKey)) if (!(ctrlKey || shiftKey))
deselectAll(); deselectAll();
directoryEntryListRef.value?.gatherEntries().map(entry => { gatherEntries().map(entry => {
const entryRect = entry.DOMElement?.getBoundingClientRect(); const entryRect = entry.DOMElement?.getBoundingClientRect();
if ( if (
!entryRect !entryRect
@ -230,11 +239,11 @@ export default {
* @param {KeyboardEvent} event * @param {KeyboardEvent} event
*/ */
const keyHandler = (event) => { const keyHandler = (event) => {
console.log("DirectoryView::keyHandler:", event); const unCutEntries = () => gatherEntries([], false).map(entry => entry.cut = false);
if (event.key === 'Escape') { if (event.key === 'Escape') {
if (getSelected().length === 0) { if (getSelected().length === 0) {
if (clipboard.content.length) { if (clipboard.content.length) {
clipboard.content.map(entry => entry.cut = false); unCutEntries();
clipboard.content = []; clipboard.content = [];
notifications.value.constructNotification('Clipboard', 'Cleared clipboard.', 'info', 2000); notifications.value.constructNotification('Clipboard', 'Cleared clipboard.', 'info', 2000);
} }
@ -255,12 +264,27 @@ export default {
case 'c': case 'c':
case 'x': case 'x':
const isCut = keypress === 'x'; const isCut = keypress === 'x';
clipboard.content.map(entry => entry.cut = false); if (!event.shiftKey)
clipboard.content = getSelected().map(entry => { unCutEntries();
const newContent = getSelected().map(entry => {
entry.cut = isCut; entry.cut = isCut;
return entry; return {
uniqueId: entry.uniqueId,
host: entry.host,
path: entry.path,
name: entry.name,
cut: isCut,
clipboardRelativePath: entry.path.slice(props.path.length).replace(/^\//, '')
};
}); });
notifications.value.constructNotification('Clipboard', `Copied ${clipboard.content.length} items to clipboard.`, 'info', 2000); if (event.shiftKey)
clipboard.content = [ ...newContent, ...clipboard.content ].filter((a, index, arr) => arr.findIndex(b => b.uniqueId === a.uniqueId) === index);
else
clipboard.content = newContent;
const message = event.shiftKey
? `Added ${newContent.length} items to clipboard.\n(${clipboard.content.length} items total)`
: `Copied ${newContent.length} items to clipboard.`;
notifications.value.constructNotification('Clipboard', message, 'info', 2000);
break; break;
case 'v': case 'v':
const selected = getSelected(); const selected = getSelected();
@ -277,7 +301,7 @@ export default {
notifications.value.constructNotification("Paste Failed", 'Cannot paste to multiple directories.', 'error'); notifications.value.constructNotification("Paste Failed", 'Cannot paste to multiple directories.', 'error');
break; break;
} }
console.log("paste", clipboard.content.map(entry => ({ host: entry.host, path: entry.path })), destination); console.log("paste", clipboard.content, destination);
break; break;
default: default:
return; return;