@lvce-editor/explorer-view 1.2.0 → 1.3.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 +334 -108
- package/package.json +1 -1
|
@@ -943,7 +943,7 @@ const computeExplorerRenamedDirent = (dirents, index, newName) => {
|
|
|
943
943
|
};
|
|
944
944
|
};
|
|
945
945
|
|
|
946
|
-
const None$
|
|
946
|
+
const None$2 = 0;
|
|
947
947
|
const CreateFile = 1;
|
|
948
948
|
const CreateFolder = 2;
|
|
949
949
|
const Rename = 3;
|
|
@@ -955,7 +955,7 @@ const getRealPath = async path => {};
|
|
|
955
955
|
const stat = async dirent => {};
|
|
956
956
|
const createFile = async uri => {};
|
|
957
957
|
const mkdir = async uri => {};
|
|
958
|
-
const rename = async (oldUri, newUri) => {};
|
|
958
|
+
const rename$1 = async (oldUri, newUri) => {};
|
|
959
959
|
|
|
960
960
|
class AssertionError extends Error {
|
|
961
961
|
constructor(message) {
|
|
@@ -1097,7 +1097,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
|
|
|
1097
1097
|
items: newDirents,
|
|
1098
1098
|
editingIndex: -1,
|
|
1099
1099
|
focusedIndex: insertIndex + 1,
|
|
1100
|
-
editingType: None$
|
|
1100
|
+
editingType: None$2,
|
|
1101
1101
|
maxLineY: newMaxlineY
|
|
1102
1102
|
};
|
|
1103
1103
|
};
|
|
@@ -1114,7 +1114,7 @@ const acceptRename = async state => {
|
|
|
1114
1114
|
const oldAbsolutePath = renamedDirent.path;
|
|
1115
1115
|
const oldParentPath = dirname(pathSeparator, oldAbsolutePath);
|
|
1116
1116
|
const newAbsolutePath = [oldParentPath, editingValue].join(pathSeparator);
|
|
1117
|
-
await rename(oldAbsolutePath, newAbsolutePath);
|
|
1117
|
+
await rename$1(oldAbsolutePath, newAbsolutePath);
|
|
1118
1118
|
} catch (error) {
|
|
1119
1119
|
// TODO
|
|
1120
1120
|
// await ErrorHandling.showErrorDialog(error)
|
|
@@ -1130,7 +1130,7 @@ const acceptRename = async state => {
|
|
|
1130
1130
|
...state,
|
|
1131
1131
|
editingIndex: -1,
|
|
1132
1132
|
editingValue: '',
|
|
1133
|
-
editingType: None$
|
|
1133
|
+
editingType: None$2,
|
|
1134
1134
|
editingIcon: '',
|
|
1135
1135
|
focusedIndex,
|
|
1136
1136
|
focused: true
|
|
@@ -1152,77 +1152,51 @@ const acceptEdit = state => {
|
|
|
1152
1152
|
}
|
|
1153
1153
|
};
|
|
1154
1154
|
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1155
|
+
const getFocusedDirent$1 = state => {
|
|
1156
|
+
const {
|
|
1157
|
+
focusedIndex,
|
|
1158
|
+
minLineY,
|
|
1159
|
+
items
|
|
1160
|
+
} = state;
|
|
1161
|
+
const dirent = items[focusedIndex + minLineY];
|
|
1162
|
+
return dirent;
|
|
1159
1163
|
};
|
|
1160
1164
|
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const toDisplayDirent = (rawDirent, index) => {
|
|
1165
|
-
const path = [parentDirent.path, rawDirent.name].join(pathSeparator);
|
|
1166
|
-
return {
|
|
1167
|
-
name: rawDirent.name,
|
|
1168
|
-
posInSet: index + 1,
|
|
1169
|
-
setSize: rawDirents.length,
|
|
1170
|
-
depth: parentDirent.depth + 1,
|
|
1171
|
-
type: rawDirent.type,
|
|
1172
|
-
path,
|
|
1173
|
-
// TODO storing absolute path might be too costly, could also store relative path here
|
|
1174
|
-
icon: getIcon()
|
|
1175
|
-
};
|
|
1176
|
-
};
|
|
1177
|
-
const result = [];
|
|
1178
|
-
let i = 0;
|
|
1179
|
-
for (const rawDirent of rawDirents) {
|
|
1180
|
-
if (excluded.includes(rawDirent.name)) {
|
|
1181
|
-
continue;
|
|
1182
|
-
}
|
|
1183
|
-
result.push(toDisplayDirent(rawDirent, i));
|
|
1184
|
-
i++;
|
|
1185
|
-
}
|
|
1186
|
-
return result;
|
|
1165
|
+
const copyPath$1 = async state => {
|
|
1166
|
+
// await Command.execute(RendererWorkerCommandType.ClipBoardWriteText, /* text */ path)
|
|
1167
|
+
return state;
|
|
1187
1168
|
};
|
|
1188
1169
|
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
y,
|
|
1192
|
-
itemHeight,
|
|
1193
|
-
items
|
|
1194
|
-
} = state;
|
|
1195
|
-
const index = Math.floor((eventY - y) / itemHeight);
|
|
1196
|
-
if (index < 0) {
|
|
1197
|
-
return 0;
|
|
1198
|
-
}
|
|
1199
|
-
if (index >= items.length) {
|
|
1200
|
-
return -1;
|
|
1201
|
-
}
|
|
1202
|
-
return index;
|
|
1170
|
+
const state = {
|
|
1171
|
+
rpc: undefined
|
|
1203
1172
|
};
|
|
1204
|
-
const
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
startIndex--;
|
|
1209
|
-
}
|
|
1210
|
-
return startIndex;
|
|
1173
|
+
const invoke = (method, ...params) => {
|
|
1174
|
+
const rpc = state.rpc;
|
|
1175
|
+
// @ts-ignore
|
|
1176
|
+
return rpc.invoke(method, ...params);
|
|
1211
1177
|
};
|
|
1212
|
-
const
|
|
1213
|
-
|
|
1214
|
-
let endIndex = index + 1;
|
|
1215
|
-
while (endIndex < dirents.length && dirents[endIndex].depth > dirent.depth) {
|
|
1216
|
-
endIndex++;
|
|
1217
|
-
}
|
|
1218
|
-
return endIndex;
|
|
1178
|
+
const setRpc = rpc => {
|
|
1179
|
+
state.rpc = rpc;
|
|
1219
1180
|
};
|
|
1181
|
+
|
|
1182
|
+
const writeText = async text => {
|
|
1183
|
+
await invoke('ClipBoard.writeText', /* text */text);
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
const copyRelativePath$1 = async state => {
|
|
1187
|
+
const dirent = getFocusedDirent$1(state);
|
|
1188
|
+
const relativePath = dirent.path.slice(1);
|
|
1189
|
+
// TODO handle error
|
|
1190
|
+
await writeText(relativePath);
|
|
1191
|
+
return state;
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1220
1194
|
const isSymbolicLink = dirent => {
|
|
1221
1195
|
return dirent.type === Symlink;
|
|
1222
1196
|
};
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1197
|
+
|
|
1198
|
+
const ENOENT = 'ENOENT';
|
|
1199
|
+
|
|
1226
1200
|
const getSymlinkType = type => {
|
|
1227
1201
|
switch (type) {
|
|
1228
1202
|
case File:
|
|
@@ -1233,6 +1207,7 @@ const getSymlinkType = type => {
|
|
|
1233
1207
|
return Symlink;
|
|
1234
1208
|
}
|
|
1235
1209
|
};
|
|
1210
|
+
|
|
1236
1211
|
// TODO maybe resolving of symbolic links should happen in shared process?
|
|
1237
1212
|
// so that there is less code and less work in the frontend
|
|
1238
1213
|
const resolveSymbolicLink = async (uri, rawDirent) => {
|
|
@@ -1270,6 +1245,42 @@ const resolveSymbolicLinks = async (uri, rawDirents) => {
|
|
|
1270
1245
|
const resolvedDirents = await Promise.all(promises);
|
|
1271
1246
|
return resolvedDirents;
|
|
1272
1247
|
};
|
|
1248
|
+
|
|
1249
|
+
const sortExplorerItems = rawDirents => {
|
|
1250
|
+
rawDirents.sort(compareDirent);
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
const toDisplayDirents = (pathSeparator, rawDirents, parentDirent, excluded) => {
|
|
1254
|
+
sortExplorerItems(rawDirents);
|
|
1255
|
+
// TODO figure out whether this uses too much memory (name,path -> redundant, depth could be computed on demand)
|
|
1256
|
+
const toDisplayDirent = (rawDirent, index) => {
|
|
1257
|
+
const path = [parentDirent.path, rawDirent.name].join(pathSeparator);
|
|
1258
|
+
return {
|
|
1259
|
+
name: rawDirent.name,
|
|
1260
|
+
posInSet: index + 1,
|
|
1261
|
+
setSize: rawDirents.length,
|
|
1262
|
+
depth: parentDirent.depth + 1,
|
|
1263
|
+
type: rawDirent.type,
|
|
1264
|
+
path,
|
|
1265
|
+
// TODO storing absolute path might be too costly, could also store relative path here
|
|
1266
|
+
icon: getIcon()
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1269
|
+
const result = [];
|
|
1270
|
+
let i = 0;
|
|
1271
|
+
for (const rawDirent of rawDirents) {
|
|
1272
|
+
if (excluded.includes(rawDirent.name)) {
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
result.push(toDisplayDirent(rawDirent, i));
|
|
1276
|
+
i++;
|
|
1277
|
+
}
|
|
1278
|
+
return result;
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1281
|
+
const hasSymbolicLinks = rawDirents => {
|
|
1282
|
+
return rawDirents.some(isSymbolicLink);
|
|
1283
|
+
};
|
|
1273
1284
|
const getChildDirentsRaw = async uri => {
|
|
1274
1285
|
const rawDirents = await readDirWithFileTypes();
|
|
1275
1286
|
array(rawDirents);
|
|
@@ -1347,6 +1358,85 @@ const expandAll = async state => {
|
|
|
1347
1358
|
};
|
|
1348
1359
|
};
|
|
1349
1360
|
|
|
1361
|
+
const getParentEndIndex = (dirents, index) => {
|
|
1362
|
+
const dirent = dirents[index];
|
|
1363
|
+
let endIndex = index + 1;
|
|
1364
|
+
while (endIndex < dirents.length && dirents[endIndex].depth > dirent.depth) {
|
|
1365
|
+
endIndex++;
|
|
1366
|
+
}
|
|
1367
|
+
return endIndex;
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
const makeExpanded = dirent => {
|
|
1371
|
+
if (dirent.type === Directory) {
|
|
1372
|
+
return {
|
|
1373
|
+
...dirent,
|
|
1374
|
+
type: DirectoryExpanded
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
return dirent;
|
|
1378
|
+
};
|
|
1379
|
+
const expandRecursively = async state => {
|
|
1380
|
+
const {
|
|
1381
|
+
items,
|
|
1382
|
+
focusedIndex,
|
|
1383
|
+
pathSeparator,
|
|
1384
|
+
root,
|
|
1385
|
+
height,
|
|
1386
|
+
itemHeight,
|
|
1387
|
+
minLineY
|
|
1388
|
+
} = state;
|
|
1389
|
+
const dirent = focusedIndex < 0 ? {
|
|
1390
|
+
type: Directory,
|
|
1391
|
+
path: root,
|
|
1392
|
+
depth: 0
|
|
1393
|
+
} : items[focusedIndex];
|
|
1394
|
+
if (dirent.type !== Directory && dirent.type !== DirectoryExpanding && dirent.type !== DirectoryExpanded) {
|
|
1395
|
+
return state;
|
|
1396
|
+
}
|
|
1397
|
+
// TODO this is very inefficient
|
|
1398
|
+
const getChildDirentsRecursively = async dirent => {
|
|
1399
|
+
switch (dirent.type) {
|
|
1400
|
+
case File:
|
|
1401
|
+
return [dirent];
|
|
1402
|
+
case Directory:
|
|
1403
|
+
case DirectoryExpanding:
|
|
1404
|
+
case DirectoryExpanded:
|
|
1405
|
+
const childDirents = await getChildDirents(pathSeparator, dirent);
|
|
1406
|
+
const all = [makeExpanded(dirent)];
|
|
1407
|
+
for (const childDirent of childDirents) {
|
|
1408
|
+
const childAll = await getChildDirentsRecursively(childDirent);
|
|
1409
|
+
all.push(...childAll);
|
|
1410
|
+
}
|
|
1411
|
+
return all;
|
|
1412
|
+
default:
|
|
1413
|
+
return [];
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
// TODO race condition: what if folder is being collapse while it is recursively expanding?
|
|
1417
|
+
// TODO race condition: what if folder is being deleted while it is recursively expanding?
|
|
1418
|
+
// TODO race condition: what if a new file/folder is created while the folder is recursively expanding?
|
|
1419
|
+
const childDirents = await getChildDirentsRecursively(dirent);
|
|
1420
|
+
const startIndex = focusedIndex;
|
|
1421
|
+
if (focusedIndex >= 0) {
|
|
1422
|
+
const endIndex = getParentEndIndex(items, focusedIndex);
|
|
1423
|
+
const newDirents = [...items.slice(0, startIndex), ...childDirents, ...items.slice(endIndex)];
|
|
1424
|
+
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
|
|
1425
|
+
return {
|
|
1426
|
+
...state,
|
|
1427
|
+
items: newDirents,
|
|
1428
|
+
maxLineY
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
const newDirents = childDirents.slice(1);
|
|
1432
|
+
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
|
|
1433
|
+
return {
|
|
1434
|
+
...state,
|
|
1435
|
+
items: newDirents,
|
|
1436
|
+
maxLineY
|
|
1437
|
+
};
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1350
1440
|
const focusIndex = (state, index) => {
|
|
1351
1441
|
const {
|
|
1352
1442
|
minLineY,
|
|
@@ -1442,7 +1532,7 @@ const focusPrevious = state => {
|
|
|
1442
1532
|
}
|
|
1443
1533
|
};
|
|
1444
1534
|
|
|
1445
|
-
const None = 'none';
|
|
1535
|
+
const None$1 = 'none';
|
|
1446
1536
|
const Tree = 'tree';
|
|
1447
1537
|
const TreeItem$1 = 'treeitem';
|
|
1448
1538
|
|
|
@@ -1501,6 +1591,39 @@ const UiStrings = {
|
|
|
1501
1591
|
OpenFolder: 'Open folder',
|
|
1502
1592
|
NoFolderOpen: 'No Folder Open'
|
|
1503
1593
|
};
|
|
1594
|
+
const newFile = () => {
|
|
1595
|
+
return i18nString(UiStrings.NewFile);
|
|
1596
|
+
};
|
|
1597
|
+
const newFolder = () => {
|
|
1598
|
+
return i18nString(UiStrings.NewFolder);
|
|
1599
|
+
};
|
|
1600
|
+
const openContainingFolder$1 = () => {
|
|
1601
|
+
return i18nString(UiStrings.OpenContainingFolder);
|
|
1602
|
+
};
|
|
1603
|
+
const openInIntegratedTerminal = () => {
|
|
1604
|
+
return i18nString(UiStrings.OpenInIntegratedTerminal);
|
|
1605
|
+
};
|
|
1606
|
+
const cut = () => {
|
|
1607
|
+
return i18nString(UiStrings.Cut);
|
|
1608
|
+
};
|
|
1609
|
+
const copy = () => {
|
|
1610
|
+
return i18nString(UiStrings.Copy);
|
|
1611
|
+
};
|
|
1612
|
+
const paste = () => {
|
|
1613
|
+
return i18nString(UiStrings.Paste);
|
|
1614
|
+
};
|
|
1615
|
+
const copyPath = () => {
|
|
1616
|
+
return i18nString(UiStrings.CopyPath);
|
|
1617
|
+
};
|
|
1618
|
+
const copyRelativePath = () => {
|
|
1619
|
+
return i18nString(UiStrings.CopyRelativePath);
|
|
1620
|
+
};
|
|
1621
|
+
const rename = () => {
|
|
1622
|
+
return i18nString(UiStrings.Rename);
|
|
1623
|
+
};
|
|
1624
|
+
const deleteItem = () => {
|
|
1625
|
+
return i18nString(UiStrings.Delete);
|
|
1626
|
+
};
|
|
1504
1627
|
const filesExplorer = () => {
|
|
1505
1628
|
return i18nString(UiStrings.FilesExplorer);
|
|
1506
1629
|
};
|
|
@@ -1523,7 +1646,7 @@ const getFileIconVirtualDom = icon => {
|
|
|
1523
1646
|
type: Img,
|
|
1524
1647
|
className: FileIcon,
|
|
1525
1648
|
src: icon,
|
|
1526
|
-
role: None,
|
|
1649
|
+
role: None$1,
|
|
1527
1650
|
childCount: 0
|
|
1528
1651
|
};
|
|
1529
1652
|
};
|
|
@@ -1805,6 +1928,121 @@ const getKeyBindings = () => {
|
|
|
1805
1928
|
}];
|
|
1806
1929
|
};
|
|
1807
1930
|
|
|
1931
|
+
const Separator = 1;
|
|
1932
|
+
const None = 0;
|
|
1933
|
+
const RestoreFocus = 6;
|
|
1934
|
+
|
|
1935
|
+
const menuEntrySeparator = {
|
|
1936
|
+
id: 'separator',
|
|
1937
|
+
label: '',
|
|
1938
|
+
flags: Separator,
|
|
1939
|
+
command: ''
|
|
1940
|
+
};
|
|
1941
|
+
|
|
1942
|
+
const menuEntryNewFile = {
|
|
1943
|
+
id: 'newFile',
|
|
1944
|
+
label: newFile(),
|
|
1945
|
+
flags: None,
|
|
1946
|
+
command: 'Explorer.newFile'
|
|
1947
|
+
};
|
|
1948
|
+
const menuEntryNewFolder = {
|
|
1949
|
+
id: 'newFolder',
|
|
1950
|
+
label: newFolder(),
|
|
1951
|
+
flags: None,
|
|
1952
|
+
command: 'Explorer.newFolder'
|
|
1953
|
+
};
|
|
1954
|
+
const menuEntryOpenContainingFolder = {
|
|
1955
|
+
id: 'openContainingFolder',
|
|
1956
|
+
label: openContainingFolder$1(),
|
|
1957
|
+
flags: RestoreFocus,
|
|
1958
|
+
command: 'Explorer.openContainingFolder'
|
|
1959
|
+
};
|
|
1960
|
+
const menuEntryOpenInIntegratedTerminal = {
|
|
1961
|
+
id: 'openInIntegratedTerminal',
|
|
1962
|
+
label: openInIntegratedTerminal(),
|
|
1963
|
+
flags: None,
|
|
1964
|
+
command: /* TODO */-1
|
|
1965
|
+
};
|
|
1966
|
+
const menuEntryCut = {
|
|
1967
|
+
id: 'cut',
|
|
1968
|
+
label: cut(),
|
|
1969
|
+
flags: RestoreFocus,
|
|
1970
|
+
command: /* TODO */-1
|
|
1971
|
+
};
|
|
1972
|
+
const menuEntryCopy = {
|
|
1973
|
+
id: 'copy',
|
|
1974
|
+
label: copy(),
|
|
1975
|
+
flags: RestoreFocus,
|
|
1976
|
+
command: 'Explorer.handleCopy'
|
|
1977
|
+
};
|
|
1978
|
+
const menuEntryPaste = {
|
|
1979
|
+
id: 'paste',
|
|
1980
|
+
label: paste(),
|
|
1981
|
+
flags: None,
|
|
1982
|
+
command: 'Explorer.handlePaste'
|
|
1983
|
+
};
|
|
1984
|
+
const menuEntryCopyPath = {
|
|
1985
|
+
id: 'copyPath',
|
|
1986
|
+
label: copyPath(),
|
|
1987
|
+
flags: RestoreFocus,
|
|
1988
|
+
command: 'Explorer.copyPath'
|
|
1989
|
+
};
|
|
1990
|
+
const menuEntryCopyRelativePath = {
|
|
1991
|
+
id: 'copyRelativePath',
|
|
1992
|
+
label: copyRelativePath(),
|
|
1993
|
+
flags: RestoreFocus,
|
|
1994
|
+
command: 'Explorer.copyRelativePath'
|
|
1995
|
+
};
|
|
1996
|
+
const menuEntryRename = {
|
|
1997
|
+
id: 'rename',
|
|
1998
|
+
label: rename(),
|
|
1999
|
+
flags: None,
|
|
2000
|
+
command: 'Explorer.renameDirent'
|
|
2001
|
+
};
|
|
2002
|
+
const menuEntryDelete = {
|
|
2003
|
+
id: 'delete',
|
|
2004
|
+
label: deleteItem(),
|
|
2005
|
+
flags: None,
|
|
2006
|
+
command: 'Explorer.removeDirent'
|
|
2007
|
+
};
|
|
2008
|
+
const ALL_ENTRIES = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryRename, menuEntryDelete];
|
|
2009
|
+
|
|
2010
|
+
// TODO there are two possible ways of getting the focused dirent of explorer
|
|
2011
|
+
// 1. directly access state of explorer (bad because it directly accesses state of another component)
|
|
2012
|
+
// 2. expose getFocusedDirent method in explorer (bad because explorer code should not know about for menuEntriesExplorer, which needs that method)
|
|
2013
|
+
const getFocusedDirent = explorerState => {
|
|
2014
|
+
if (!explorerState || explorerState.focusedIndex < 0) {
|
|
2015
|
+
return undefined;
|
|
2016
|
+
}
|
|
2017
|
+
return explorerState.items[explorerState.focusedIndex];
|
|
2018
|
+
};
|
|
2019
|
+
const getMenuEntriesDirectory = () => {
|
|
2020
|
+
return ALL_ENTRIES;
|
|
2021
|
+
};
|
|
2022
|
+
const getMenuEntriesFile = () => {
|
|
2023
|
+
return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryRename, menuEntryDelete];
|
|
2024
|
+
};
|
|
2025
|
+
const getMenuEntriesDefault = () => {
|
|
2026
|
+
return ALL_ENTRIES;
|
|
2027
|
+
};
|
|
2028
|
+
const getMenuEntriesRoot = () => {
|
|
2029
|
+
return [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath];
|
|
2030
|
+
};
|
|
2031
|
+
const getMenuEntries = state => {
|
|
2032
|
+
const focusedDirent = getFocusedDirent(state);
|
|
2033
|
+
if (!focusedDirent) {
|
|
2034
|
+
return getMenuEntriesRoot();
|
|
2035
|
+
}
|
|
2036
|
+
switch (focusedDirent.type) {
|
|
2037
|
+
case Directory:
|
|
2038
|
+
return getMenuEntriesDirectory();
|
|
2039
|
+
case File:
|
|
2040
|
+
return getMenuEntriesFile();
|
|
2041
|
+
default:
|
|
2042
|
+
return getMenuEntriesDefault();
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
|
|
1808
2046
|
const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue) => {
|
|
1809
2047
|
const visible = [];
|
|
1810
2048
|
for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
|
|
@@ -1825,7 +2063,7 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
1825
2063
|
});
|
|
1826
2064
|
}
|
|
1827
2065
|
}
|
|
1828
|
-
if (editingType !== None$
|
|
2066
|
+
if (editingType !== None$2 && editingIndex === -1) {
|
|
1829
2067
|
visible.push({
|
|
1830
2068
|
depth: 3,
|
|
1831
2069
|
posInSet: 1,
|
|
@@ -1841,14 +2079,29 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
1841
2079
|
return visible;
|
|
1842
2080
|
};
|
|
1843
2081
|
|
|
1844
|
-
const
|
|
2082
|
+
const getIndexFromPosition = (state, eventX, eventY) => {
|
|
1845
2083
|
const {
|
|
1846
|
-
|
|
1847
|
-
|
|
2084
|
+
y,
|
|
2085
|
+
itemHeight,
|
|
1848
2086
|
items
|
|
1849
2087
|
} = state;
|
|
1850
|
-
const
|
|
1851
|
-
|
|
2088
|
+
const index = Math.floor((eventY - y) / itemHeight);
|
|
2089
|
+
if (index < 0) {
|
|
2090
|
+
return 0;
|
|
2091
|
+
}
|
|
2092
|
+
if (index >= items.length) {
|
|
2093
|
+
return -1;
|
|
2094
|
+
}
|
|
2095
|
+
return index;
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2098
|
+
const getParentStartIndex = (dirents, index) => {
|
|
2099
|
+
const dirent = dirents[index];
|
|
2100
|
+
let startIndex = index - 1;
|
|
2101
|
+
while (startIndex >= 0 && dirents[startIndex].depth >= dirent.depth) {
|
|
2102
|
+
startIndex--;
|
|
2103
|
+
}
|
|
2104
|
+
return startIndex;
|
|
1852
2105
|
};
|
|
1853
2106
|
|
|
1854
2107
|
const Keyboard = -1;
|
|
@@ -1917,7 +2170,7 @@ const removeDirent = async state => {
|
|
|
1917
2170
|
if (state.focusedIndex < 0) {
|
|
1918
2171
|
return state;
|
|
1919
2172
|
}
|
|
1920
|
-
const dirent = getFocusedDirent(state);
|
|
2173
|
+
const dirent = getFocusedDirent$1(state);
|
|
1921
2174
|
const absolutePath = dirent.path;
|
|
1922
2175
|
try {
|
|
1923
2176
|
// TODO handle error
|
|
@@ -1992,7 +2245,7 @@ const cancelEdit = state => {
|
|
|
1992
2245
|
focused: true,
|
|
1993
2246
|
editingIndex: -1,
|
|
1994
2247
|
editingValue: '',
|
|
1995
|
-
editingType: None$
|
|
2248
|
+
editingType: None$2
|
|
1996
2249
|
};
|
|
1997
2250
|
};
|
|
1998
2251
|
|
|
@@ -2225,7 +2478,7 @@ const handleBlur = state => {
|
|
|
2225
2478
|
const {
|
|
2226
2479
|
editingType
|
|
2227
2480
|
} = state;
|
|
2228
|
-
if (editingType !== None$
|
|
2481
|
+
if (editingType !== None$2) {
|
|
2229
2482
|
return state;
|
|
2230
2483
|
}
|
|
2231
2484
|
return {
|
|
@@ -2241,18 +2494,6 @@ const handleClickOpenFolder = async state => {
|
|
|
2241
2494
|
return state;
|
|
2242
2495
|
};
|
|
2243
2496
|
|
|
2244
|
-
const state = {
|
|
2245
|
-
rpc: undefined
|
|
2246
|
-
};
|
|
2247
|
-
const invoke = (method, ...params) => {
|
|
2248
|
-
const rpc = state.rpc;
|
|
2249
|
-
// @ts-ignore
|
|
2250
|
-
return rpc.invoke(method, ...params);
|
|
2251
|
-
};
|
|
2252
|
-
const setRpc = rpc => {
|
|
2253
|
-
state.rpc = rpc;
|
|
2254
|
-
};
|
|
2255
|
-
|
|
2256
2497
|
const show = async (x, y, id, ...args) => {
|
|
2257
2498
|
return invoke('ContextMenu.show', x, y, id, ...args);
|
|
2258
2499
|
};
|
|
@@ -2294,18 +2535,6 @@ const handleContextMenu = (state, button, x, y) => {
|
|
|
2294
2535
|
}
|
|
2295
2536
|
};
|
|
2296
2537
|
|
|
2297
|
-
const writeText = async text => {
|
|
2298
|
-
await invoke('ClipBoard.writeText', /* text */text);
|
|
2299
|
-
};
|
|
2300
|
-
|
|
2301
|
-
const copyRelativePath = async state => {
|
|
2302
|
-
const dirent = getFocusedDirent(state);
|
|
2303
|
-
const relativePath = dirent.path.slice(1);
|
|
2304
|
-
// TODO handle error
|
|
2305
|
-
await writeText(relativePath);
|
|
2306
|
-
return state;
|
|
2307
|
-
};
|
|
2308
|
-
|
|
2309
2538
|
const handlePointerDown = (state, button, x, y) => {
|
|
2310
2539
|
const index = getIndexFromPosition(state, x, y);
|
|
2311
2540
|
if (button === LeftClick && index === -1) {
|
|
@@ -2428,11 +2657,6 @@ const restoreState = savedState => {
|
|
|
2428
2657
|
};
|
|
2429
2658
|
};
|
|
2430
2659
|
|
|
2431
|
-
const copyPath = async state => {
|
|
2432
|
-
// await Command.execute(RendererWorkerCommandType.ClipBoardWriteText, /* text */ path)
|
|
2433
|
-
return state;
|
|
2434
|
-
};
|
|
2435
|
-
|
|
2436
2660
|
const isExpandedDirectory = dirent => {
|
|
2437
2661
|
return dirent.type === DirectoryExpanded;
|
|
2438
2662
|
};
|
|
@@ -2460,15 +2684,17 @@ const saveState = state => {
|
|
|
2460
2684
|
const commandMap = {
|
|
2461
2685
|
'Explorer.acceptEdit': acceptEdit,
|
|
2462
2686
|
'Explorer.cancelEdit': cancelEdit,
|
|
2463
|
-
'Explorer.copyPath': copyPath,
|
|
2464
|
-
'Explorer.copyRelativePath': copyRelativePath,
|
|
2687
|
+
'Explorer.copyPath': copyPath$1,
|
|
2688
|
+
'Explorer.copyRelativePath': copyRelativePath$1,
|
|
2465
2689
|
'Explorer.expandAll': expandAll,
|
|
2690
|
+
'Explorer.expandRecursively': expandRecursively,
|
|
2466
2691
|
'Explorer.focusFirst': focusFirst,
|
|
2467
2692
|
'Explorer.focusIndex': focusIndex,
|
|
2468
2693
|
'Explorer.focusLast': focusLast,
|
|
2469
2694
|
'Explorer.focusNext': focusNext,
|
|
2470
2695
|
'Explorer.focusPrevious': focusPrevious,
|
|
2471
2696
|
'Explorer.getKeyBindings': getKeyBindings,
|
|
2697
|
+
'Explorer.getMenuEntries': getMenuEntries,
|
|
2472
2698
|
'Explorer.getVirtualDom': getExplorerVirtualDom,
|
|
2473
2699
|
'Explorer.getVisibleItems': getVisibleExplorerItems,
|
|
2474
2700
|
'Explorer.handleArrowLeft': handleArrowLeft,
|