@lvce-editor/explorer-view 2.53.0 → 2.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/explorerViewWorkerMain.js +87 -42
- package/package.json +1 -1
|
@@ -1005,9 +1005,6 @@ const dirname = (pathSeparator, path) => {
|
|
|
1005
1005
|
const dirname2 = path => {
|
|
1006
1006
|
return dirname('/', path);
|
|
1007
1007
|
};
|
|
1008
|
-
const join = (pathSeparator, ...parts) => {
|
|
1009
|
-
return parts.join(pathSeparator);
|
|
1010
|
-
};
|
|
1011
1008
|
const getBaseName = (pathSeparator, path) => {
|
|
1012
1009
|
return path.slice(path.lastIndexOf(pathSeparator) + 1);
|
|
1013
1010
|
};
|
|
@@ -1844,6 +1841,7 @@ const writeText = async text => {
|
|
|
1844
1841
|
await invoke$1('ClipBoard.writeText', /* text */text);
|
|
1845
1842
|
};
|
|
1846
1843
|
const readNativeFiles = async () => {
|
|
1844
|
+
// @ts-ignore
|
|
1847
1845
|
return invoke$1('ClipBoard.readNativeFiles');
|
|
1848
1846
|
};
|
|
1849
1847
|
const writeNativeFiles = async (type, files) => {
|
|
@@ -3361,12 +3359,12 @@ const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) =
|
|
|
3361
3359
|
return true;
|
|
3362
3360
|
};
|
|
3363
3361
|
|
|
3364
|
-
const mergeDirents$
|
|
3362
|
+
const mergeDirents$1 = (oldDirents, newDirents) => {
|
|
3365
3363
|
return newDirents;
|
|
3366
3364
|
};
|
|
3367
3365
|
const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
|
|
3368
3366
|
const childDirents = await getChildDirents(pathSeparator, root, 0);
|
|
3369
|
-
const mergedDirents = mergeDirents$
|
|
3367
|
+
const mergedDirents = mergeDirents$1(dirents, childDirents);
|
|
3370
3368
|
return mergedDirents;
|
|
3371
3369
|
};
|
|
3372
3370
|
const handleDrop$2 = async (state, fileHandles, files) => {
|
|
@@ -3414,12 +3412,12 @@ const copyFilesElectron = async (root, pathSeparator, fileHandles, files, paths)
|
|
|
3414
3412
|
await applyFileOperations(operations);
|
|
3415
3413
|
};
|
|
3416
3414
|
|
|
3417
|
-
const mergeDirents
|
|
3415
|
+
const mergeDirents = (oldDirents, newDirents) => {
|
|
3418
3416
|
return newDirents;
|
|
3419
3417
|
};
|
|
3420
3418
|
const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
|
|
3421
3419
|
const childDirents = await getChildDirents(pathSeparator, root, 0);
|
|
3422
|
-
const mergedDirents = mergeDirents
|
|
3420
|
+
const mergedDirents = mergeDirents(dirents, childDirents);
|
|
3423
3421
|
return mergedDirents;
|
|
3424
3422
|
};
|
|
3425
3423
|
const handleDrop$1 = async (state, fileHandles, files, paths) => {
|
|
@@ -3682,41 +3680,59 @@ const handleKeyDown = (state, key) => {
|
|
|
3682
3680
|
};
|
|
3683
3681
|
};
|
|
3684
3682
|
|
|
3685
|
-
const
|
|
3686
|
-
|
|
3687
|
-
|
|
3683
|
+
const generateUniqueName = (baseName, existingPaths, root) => {
|
|
3684
|
+
// Handle files with extensions
|
|
3685
|
+
const lastDotIndex = baseName.lastIndexOf('.');
|
|
3686
|
+
const hasExtension = lastDotIndex !== -1 && lastDotIndex !== 0 && lastDotIndex !== baseName.length - 1;
|
|
3687
|
+
let nameWithoutExtension;
|
|
3688
|
+
let extension;
|
|
3689
|
+
if (hasExtension) {
|
|
3690
|
+
nameWithoutExtension = baseName.slice(0, lastDotIndex);
|
|
3691
|
+
extension = baseName.slice(lastDotIndex);
|
|
3692
|
+
} else {
|
|
3693
|
+
nameWithoutExtension = baseName;
|
|
3694
|
+
extension = '';
|
|
3688
3695
|
}
|
|
3689
|
-
return getChildDirents(pathSeparator, root, 0, excluded);
|
|
3690
|
-
};
|
|
3691
3696
|
|
|
3692
|
-
|
|
3693
|
-
const
|
|
3694
|
-
|
|
3695
|
-
|
|
3697
|
+
// Check if original name exists
|
|
3698
|
+
const originalPath = join2(root, baseName);
|
|
3699
|
+
if (!existingPaths.includes(originalPath)) {
|
|
3700
|
+
return baseName;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
// Try "original copy"
|
|
3704
|
+
const copyName = `${nameWithoutExtension} copy${extension}`;
|
|
3705
|
+
const copyPath = join2(root, copyName);
|
|
3706
|
+
if (!existingPaths.includes(copyPath)) {
|
|
3707
|
+
return copyName;
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
// Try "original copy 1", "original copy 2", etc.
|
|
3711
|
+
let counter = 1;
|
|
3712
|
+
while (true) {
|
|
3713
|
+
const numberedCopyName = `${nameWithoutExtension} copy ${counter}${extension}`;
|
|
3714
|
+
const numberedCopyPath = join2(root, numberedCopyName);
|
|
3715
|
+
if (!existingPaths.includes(numberedCopyPath)) {
|
|
3716
|
+
return numberedCopyName;
|
|
3717
|
+
}
|
|
3718
|
+
counter++;
|
|
3696
3719
|
}
|
|
3697
|
-
return merged;
|
|
3698
3720
|
};
|
|
3699
3721
|
|
|
3700
|
-
|
|
3701
|
-
const
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3722
|
+
const getFileOperationsCopy = (root, existingUris, files) => {
|
|
3723
|
+
const operations = [];
|
|
3724
|
+
for (const file of files) {
|
|
3725
|
+
const baseName = getBaseName('/', file);
|
|
3726
|
+
const uniqueName = generateUniqueName(baseName, existingUris, root);
|
|
3727
|
+
const newUri = join2(root, uniqueName);
|
|
3728
|
+
operations.push({
|
|
3729
|
+
type: Copy$2,
|
|
3730
|
+
from: file,
|
|
3731
|
+
// TODO ensure file is uri
|
|
3732
|
+
path: newUri
|
|
3733
|
+
});
|
|
3705
3734
|
}
|
|
3706
|
-
|
|
3707
|
-
// @ts-ignore
|
|
3708
|
-
const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator, []);
|
|
3709
|
-
// const state2 = Viewlet.getState('Explorer')
|
|
3710
|
-
// // TODO what if root changes while reading directories?
|
|
3711
|
-
// if (state2.disposed || state2.root !== state1.root) {
|
|
3712
|
-
// return state2
|
|
3713
|
-
// }
|
|
3714
|
-
const newDirents = mergeDirents(state1.items, topLevelDirents);
|
|
3715
|
-
const state3 = {
|
|
3716
|
-
...state1,
|
|
3717
|
-
items: newDirents
|
|
3718
|
-
};
|
|
3719
|
-
return state3;
|
|
3735
|
+
return operations;
|
|
3720
3736
|
};
|
|
3721
3737
|
|
|
3722
3738
|
const handlePasteCopy = async (state, nativeFiles) => {
|
|
@@ -3725,13 +3741,42 @@ const handlePasteCopy = async (state, nativeFiles) => {
|
|
|
3725
3741
|
// TODO handle pasting files into broken symlink
|
|
3726
3742
|
// TODO handle pasting files into hardlink
|
|
3727
3743
|
// TODO what if folder is big and it takes a long time
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3744
|
+
|
|
3745
|
+
// TODO use file operations and bulk edit
|
|
3746
|
+
const {
|
|
3747
|
+
items,
|
|
3748
|
+
root
|
|
3749
|
+
} = state;
|
|
3750
|
+
const existingUris = items.map(item => item.path);
|
|
3751
|
+
const operations = getFileOperationsCopy(root, existingUris, nativeFiles.files);
|
|
3752
|
+
// TODO handle error?
|
|
3753
|
+
await applyFileOperations(operations);
|
|
3754
|
+
|
|
3755
|
+
// TODO use refreshExplorer with the paths that have been affected by file operations
|
|
3733
3756
|
// TODO only update folder at which level it changed
|
|
3734
|
-
|
|
3757
|
+
const latestState = await refresh(state);
|
|
3758
|
+
|
|
3759
|
+
// Focus on the first newly created file
|
|
3760
|
+
const newFilePaths = operations.map(operation => operation.path);
|
|
3761
|
+
if (newFilePaths.length > 0) {
|
|
3762
|
+
const firstNewFilePath = newFilePaths[0];
|
|
3763
|
+
const newFileIndex = getIndex(latestState.items, firstNewFilePath);
|
|
3764
|
+
if (newFileIndex !== -1) {
|
|
3765
|
+
return {
|
|
3766
|
+
...latestState,
|
|
3767
|
+
focusedIndex: newFileIndex,
|
|
3768
|
+
focused: true
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
// If there are no items, ensure focusedIndex is 0
|
|
3773
|
+
if (latestState.items.length === 0) {
|
|
3774
|
+
return {
|
|
3775
|
+
...latestState,
|
|
3776
|
+
focusedIndex: 0
|
|
3777
|
+
};
|
|
3778
|
+
}
|
|
3779
|
+
return latestState;
|
|
3735
3780
|
};
|
|
3736
3781
|
|
|
3737
3782
|
const handlePasteCut = async (state, nativeFiles) => {
|