@lvce-editor/explorer-view 2.56.0 → 2.57.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.
@@ -885,7 +885,7 @@ const WebWorkerRpcClient = {
885
885
 
886
886
  const CreateFolder$1 = 1;
887
887
  const CreateFile$1 = 2;
888
- const Copy$2 = 3;
888
+ const Copy$1 = 3;
889
889
  const Rename$2 = 4;
890
890
 
891
891
  const rpcs = Object.create(null);
@@ -973,7 +973,7 @@ const applyOperation = operation => {
973
973
  if (operation.type === CreateFolder$1) {
974
974
  return mkdir(operation.path);
975
975
  }
976
- if (operation.type === Copy$2) {
976
+ if (operation.type === Copy$1) {
977
977
  return copy$1(operation.from || '', operation.path);
978
978
  }
979
979
  if (operation.type === Rename$2) {
@@ -1460,10 +1460,10 @@ const i18nString = (key, placeholders = emptyObject) => {
1460
1460
  };
1461
1461
 
1462
1462
  const CollapseAllFoldersInExplorer = 'Collapse All Folders in Explorer';
1463
- const Copy$1 = 'Copy';
1463
+ const Copy = 'Copy';
1464
1464
  const CopyPath = 'Copy Path';
1465
1465
  const CopyRelativePath = 'Copy Relative Path';
1466
- const Cut$1 = 'Cut';
1466
+ const Cut = 'Cut';
1467
1467
  const Delete$1 = 'Delete';
1468
1468
  const FileNameCannotStartWithSlash = 'A file or folder name cannot start with a slash.';
1469
1469
  const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
@@ -1492,10 +1492,10 @@ const openInIntegratedTerminal = () => {
1492
1492
  return i18nString(OpenInIntegratedTerminal);
1493
1493
  };
1494
1494
  const cut = () => {
1495
- return i18nString(Cut$1);
1495
+ return i18nString(Cut);
1496
1496
  };
1497
1497
  const copy = () => {
1498
- return i18nString(Copy$1);
1498
+ return i18nString(Copy);
1499
1499
  };
1500
1500
  const paste = () => {
1501
1501
  return i18nString(Paste);
@@ -1994,7 +1994,8 @@ const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) =
1994
1994
  handleOffset: 0,
1995
1995
  scrollBarActive: false,
1996
1996
  scrollBarHeight: 0,
1997
- confirmPaste: false
1997
+ confirmPaste: false,
1998
+ pasteShouldMove: false
1998
1999
  };
1999
2000
  set(uid, state, state);
2000
2001
  };
@@ -2041,7 +2042,8 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
2041
2042
  handleOffset: 0,
2042
2043
  scrollBarActive: false,
2043
2044
  scrollBarHeight: 0,
2044
- confirmPaste: false
2045
+ confirmPaste: false,
2046
+ pasteShouldMove: false
2045
2047
  };
2046
2048
  set(state.uid, state, state);
2047
2049
  return state;
@@ -2379,7 +2381,7 @@ const focusPrevious = state => {
2379
2381
  }
2380
2382
  };
2381
2383
 
2382
- const commandIds = ['acceptEdit', 'cancelEdit', 'cancelTypeAhead', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleInputKeyDown', 'handleKeyDown', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
2384
+ const commandIds = ['acceptEdit', 'cancelEdit', 'cancelTypeAhead', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'handleCut', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleInputKeyDown', 'handleKeyDown', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
2383
2385
 
2384
2386
  const getCommandIds = () => {
2385
2387
  return commandIds;
@@ -2535,7 +2537,7 @@ const menuEntryCut = {
2535
2537
  id: 'cut',
2536
2538
  label: cut(),
2537
2539
  flags: RestoreFocus,
2538
- command: /* TODO */'-1'
2540
+ command: 'Explorer.handleCut'
2539
2541
  };
2540
2542
  const menuEntryCopy = {
2541
2543
  id: 'copy',
@@ -3126,7 +3128,28 @@ const handleCopy = async state => {
3126
3128
  // TODO handle copy error gracefully
3127
3129
  const files = [absolutePath];
3128
3130
  await writeNativeFiles('copy', files);
3129
- return state;
3131
+ return {
3132
+ ...state,
3133
+ pasteShouldMove: false
3134
+ };
3135
+ };
3136
+
3137
+ const handleCut = async state => {
3138
+ // TODO handle multiple files
3139
+ // TODO if not file is selected, what happens?
3140
+ const dirent = getFocusedDirent$1(state);
3141
+ if (!dirent) {
3142
+ console.error('[ViewletExplorer/handleCut] no dirent selected');
3143
+ return state;
3144
+ }
3145
+ const absolutePath = dirent.path;
3146
+ // TODO handle cut error gracefully
3147
+ const files = [absolutePath];
3148
+ await writeNativeFiles('cut', files);
3149
+ return {
3150
+ ...state,
3151
+ pasteShouldMove: true
3152
+ };
3130
3153
  };
3131
3154
 
3132
3155
  const handleDragLeave = state => {
@@ -3422,7 +3445,7 @@ const getFileOperationsElectron = async (root, paths, fileHandles) => {
3422
3445
  } = fileHandle;
3423
3446
  const path = paths[i];
3424
3447
  operations.push({
3425
- type: Copy$2,
3448
+ type: Copy$1,
3426
3449
  path: join2(root, name),
3427
3450
  from: path
3428
3451
  });
@@ -3793,7 +3816,7 @@ const getFileOperationsCopy = (root, existingUris, files) => {
3793
3816
  const uniqueName = generateUniqueName(baseName, existingUris, root);
3794
3817
  const newUri = join2(root, uniqueName);
3795
3818
  operations.push({
3796
- type: Copy$2,
3819
+ type: Copy$1,
3797
3820
  from: file,
3798
3821
  // TODO ensure file is uri
3799
3822
  path: newUri
@@ -3829,24 +3852,57 @@ const handlePasteCopy = async (state, nativeFiles) => {
3829
3852
  const firstNewFilePath = newFilePaths[0];
3830
3853
  const newFileIndex = getIndex(latestState.items, firstNewFilePath);
3831
3854
  if (newFileIndex !== -1) {
3832
- return adjustScrollAfterPaste(latestState, newFileIndex);
3855
+ const adjustedState = adjustScrollAfterPaste(latestState, newFileIndex);
3856
+ return {
3857
+ ...adjustedState,
3858
+ pasteShouldMove: false
3859
+ };
3833
3860
  }
3834
3861
  }
3835
3862
  // If there are no items, ensure focusedIndex is 0
3836
3863
  if (latestState.items.length === 0) {
3837
3864
  return {
3838
3865
  ...latestState,
3839
- focusedIndex: 0
3866
+ focusedIndex: 0,
3867
+ pasteShouldMove: false
3840
3868
  };
3841
3869
  }
3842
- return latestState;
3870
+ return {
3871
+ ...latestState,
3872
+ pasteShouldMove: false
3873
+ };
3843
3874
  };
3844
3875
 
3845
- const handlePasteCut = async (state, nativeFiles) => {
3846
- for (const source of nativeFiles.files) {
3847
- const target = `${state.root}${state.pathSeparator}${getBaseName(state.pathSeparator, source)}`;
3848
- await rename$1(source, target);
3876
+ const getOperations = (toUri, files) => {
3877
+ const operations = [];
3878
+ for (const file of files) {
3879
+ const baseName = getBaseName('/', file);
3880
+ const newUri = join2(toUri, baseName);
3881
+ operations.push({
3882
+ type: Rename$2,
3883
+ from: file,
3884
+ path: newUri
3885
+ });
3886
+ }
3887
+ return operations;
3888
+ };
3889
+ const getTargetUri = (root, items, index) => {
3890
+ if (index === -1) {
3891
+ return root;
3849
3892
  }
3893
+ return items[index].path;
3894
+ };
3895
+ const handlePasteCut = async (state, nativeFiles) => {
3896
+ const {
3897
+ root,
3898
+ pathSeparator,
3899
+ items,
3900
+ focusedIndex
3901
+ } = state;
3902
+ // TODO root is not necessrily target uri
3903
+ const targetUri = getTargetUri(root, items, focusedIndex);
3904
+ const operations = getOperations(targetUri, nativeFiles.files);
3905
+ await applyFileOperations(operations);
3850
3906
 
3851
3907
  // Refresh the state after cut operations
3852
3908
  const latestState = await refresh(state);
@@ -3854,36 +3910,23 @@ const handlePasteCut = async (state, nativeFiles) => {
3854
3910
  // Focus on the first pasted file and adjust scroll position
3855
3911
  if (nativeFiles.files.length > 0) {
3856
3912
  const firstPastedFile = nativeFiles.files[0];
3857
- const targetPath = `${state.root}${state.pathSeparator}${getBaseName(state.pathSeparator, firstPastedFile)}`;
3913
+ const targetPath = `${root}${pathSeparator}${getBaseName(pathSeparator, firstPastedFile)}`;
3858
3914
  const pastedFileIndex = getIndex(latestState.items, targetPath);
3859
3915
  if (pastedFileIndex !== -1) {
3860
- return adjustScrollAfterPaste(latestState, pastedFileIndex);
3916
+ const adjustedState = adjustScrollAfterPaste(latestState, pastedFileIndex);
3917
+ return {
3918
+ ...adjustedState,
3919
+ pasteShouldMove: false
3920
+ };
3861
3921
  }
3862
3922
  }
3863
- return latestState;
3864
- };
3865
-
3866
- const handlePasteNone = async (state, nativeFiles) => {
3867
- console.error('[ViewletExplorer/handlePaste] no paths detected');
3868
- return state;
3923
+ return {
3924
+ ...latestState,
3925
+ pasteShouldMove: false
3926
+ };
3869
3927
  };
3870
3928
 
3871
3929
  const None$3 = 'none';
3872
- const Copy = 'copy';
3873
- const Cut = 'cut';
3874
-
3875
- const getPasteHandler = type => {
3876
- switch (type) {
3877
- case None$3:
3878
- return handlePasteNone;
3879
- case Copy:
3880
- return handlePasteCopy;
3881
- case Cut:
3882
- return handlePasteCut;
3883
- default:
3884
- throw new Error(`unexpected native paste type: ${type}`);
3885
- }
3886
- };
3887
3930
 
3888
3931
  const handlePaste = async state => {
3889
3932
  const nativeFiles = await readNativeFiles();
@@ -3902,8 +3945,18 @@ const handlePaste = async state => {
3902
3945
  // TODO but what if a file is currently selected? Then maybe the parent folder
3903
3946
  // TODO but will it work if the folder is a symlink?
3904
3947
  // TODO handle error gracefully when copy fails
3905
- const fn = getPasteHandler(nativeFiles.type);
3906
- return fn(state, nativeFiles);
3948
+
3949
+ // If no files to paste, return original state unchanged
3950
+ if (nativeFiles.type === None$3) {
3951
+ return state;
3952
+ }
3953
+
3954
+ // Use the pasteShouldMove flag to determine whether to cut or copy
3955
+ if (state.pasteShouldMove) {
3956
+ return handlePasteCut(state, nativeFiles);
3957
+ } else {
3958
+ return handlePasteCopy(state, nativeFiles);
3959
+ }
3907
3960
  };
3908
3961
 
3909
3962
  const handlePointerDown = (state, button, x, y) => {
@@ -5451,6 +5504,7 @@ const commandMap = {
5451
5504
  'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
5452
5505
  'Explorer.handleContextMenuKeyboard': wrapCommand(handleContextMenuKeyboard),
5453
5506
  'Explorer.handleCopy': wrapCommand(handleCopy),
5507
+ 'Explorer.handleCut': wrapCommand(handleCut),
5454
5508
  'Explorer.handleDragLeave': wrapCommand(handleDragLeave),
5455
5509
  'Explorer.handleDragOver': wrapCommand(handleDragOver),
5456
5510
  'Explorer.handleDrop': wrapCommand(handleDrop),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.56.0",
3
+ "version": "2.57.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",