@lvce-editor/file-search-worker 3.5.0 → 3.7.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/fileSearchWorkerMain.js +859 -79
- package/package.json +1 -1
|
@@ -82,12 +82,30 @@ const getType = value => {
|
|
|
82
82
|
return 'unknown';
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
const object = value => {
|
|
86
|
+
const type = getType(value);
|
|
87
|
+
if (type !== 'object') {
|
|
88
|
+
throw new AssertionError('expected value to be of type object');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const number = value => {
|
|
92
|
+
const type = getType(value);
|
|
93
|
+
if (type !== 'number') {
|
|
94
|
+
throw new AssertionError('expected value to be of type number');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
85
97
|
const array = value => {
|
|
86
98
|
const type = getType(value);
|
|
87
99
|
if (type !== 'array') {
|
|
88
100
|
throw new AssertionError('expected value to be of type array');
|
|
89
101
|
}
|
|
90
102
|
};
|
|
103
|
+
const string = value => {
|
|
104
|
+
const type = getType(value);
|
|
105
|
+
if (type !== 'string') {
|
|
106
|
+
throw new AssertionError('expected value to be of type string');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
91
109
|
|
|
92
110
|
const isMessagePort = value => {
|
|
93
111
|
return value && value instanceof MessagePort;
|
|
@@ -416,7 +434,7 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
416
434
|
};
|
|
417
435
|
|
|
418
436
|
const Two = '2.0';
|
|
419
|
-
const create$4 = (method, params) => {
|
|
437
|
+
const create$4$1 = (method, params) => {
|
|
420
438
|
return {
|
|
421
439
|
jsonrpc: Two,
|
|
422
440
|
method,
|
|
@@ -751,7 +769,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
751
769
|
return unwrapJsonRpcResult(responseMessage);
|
|
752
770
|
};
|
|
753
771
|
const send = (transport, method, ...params) => {
|
|
754
|
-
const message = create$4(method, params);
|
|
772
|
+
const message = create$4$1(method, params);
|
|
755
773
|
transport.send(message);
|
|
756
774
|
};
|
|
757
775
|
const invoke$2 = (ipc, method, ...params) => {
|
|
@@ -825,7 +843,7 @@ const listen$1 = async (module, options) => {
|
|
|
825
843
|
const ipc = module.wrap(rawIpc);
|
|
826
844
|
return ipc;
|
|
827
845
|
};
|
|
828
|
-
const create$
|
|
846
|
+
const create$4 = async ({
|
|
829
847
|
commandMap
|
|
830
848
|
}) => {
|
|
831
849
|
// TODO create a commandMap per rpc instance
|
|
@@ -837,7 +855,7 @@ const create$3 = async ({
|
|
|
837
855
|
};
|
|
838
856
|
const WebWorkerRpcClient = {
|
|
839
857
|
__proto__: null,
|
|
840
|
-
create: create$
|
|
858
|
+
create: create$4
|
|
841
859
|
};
|
|
842
860
|
|
|
843
861
|
const User = 1;
|
|
@@ -875,63 +893,58 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
875
893
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
876
894
|
};
|
|
877
895
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
SelectToOpen: 'Select to open',
|
|
893
|
-
ShowAndRunCommands: 'Show And Run Commands',
|
|
894
|
-
TypeNameOfCommandToRun: 'Type the name of a command to run.',
|
|
895
|
-
TypeTheNameOfAViewToOpen: 'Type the name of a view, output channel or terminal to open.'
|
|
896
|
-
};
|
|
896
|
+
const Files = 'Files';
|
|
897
|
+
const GoToFile = 'Go to file';
|
|
898
|
+
const NoMatchingColorThemesFound = 'No matching color themes found';
|
|
899
|
+
const NoMatchingResults = 'No matching results';
|
|
900
|
+
const NoRecentlyOpenedFoldersFound = 'No recently opened folders found';
|
|
901
|
+
const NoResults = 'No Results';
|
|
902
|
+
const NoSymbolFound = 'No symbol found';
|
|
903
|
+
const NoWorkspaceSymbolsFound = 'no workspace symbols found';
|
|
904
|
+
const OpenRecent = 'Open Recent';
|
|
905
|
+
const SelectColorTheme = 'Select Color Theme';
|
|
906
|
+
const SelectToOpen = 'Select to open';
|
|
907
|
+
const ShowAndRunCommands = 'Show And Run Commands';
|
|
908
|
+
const TypeNameOfCommandToRun = 'Type the name of a command to run.';
|
|
909
|
+
|
|
897
910
|
const noMatchingColorThemesFound = () => {
|
|
898
|
-
return i18nString(
|
|
911
|
+
return i18nString(NoMatchingColorThemesFound);
|
|
899
912
|
};
|
|
900
913
|
const selectColorTheme = () => {
|
|
901
|
-
return i18nString(
|
|
914
|
+
return i18nString(SelectColorTheme);
|
|
902
915
|
};
|
|
903
916
|
const typeNameofCommandToRun = () => {
|
|
904
|
-
return i18nString(
|
|
917
|
+
return i18nString(TypeNameOfCommandToRun);
|
|
905
918
|
};
|
|
906
919
|
const showAndRunCommands = () => {
|
|
907
|
-
return i18nString(
|
|
920
|
+
return i18nString(ShowAndRunCommands);
|
|
908
921
|
};
|
|
909
922
|
const noMatchingResults = () => {
|
|
910
|
-
return i18nString(
|
|
923
|
+
return i18nString(NoMatchingResults);
|
|
911
924
|
};
|
|
912
925
|
const files = () => {
|
|
913
|
-
return i18nString(
|
|
926
|
+
return i18nString(Files);
|
|
914
927
|
};
|
|
915
928
|
const goToFile = () => {
|
|
916
|
-
return i18nString(
|
|
929
|
+
return i18nString(GoToFile);
|
|
917
930
|
};
|
|
918
931
|
const noResults = () => {
|
|
919
|
-
return i18nString(
|
|
932
|
+
return i18nString(NoResults);
|
|
920
933
|
};
|
|
921
934
|
const selectToOpen = () => {
|
|
922
|
-
return i18nString(
|
|
935
|
+
return i18nString(SelectToOpen);
|
|
923
936
|
};
|
|
924
937
|
const openRecent = () => {
|
|
925
|
-
return i18nString(
|
|
938
|
+
return i18nString(OpenRecent);
|
|
926
939
|
};
|
|
927
940
|
const noRecentlyOpenedFoldersFound = () => {
|
|
928
|
-
return i18nString(
|
|
941
|
+
return i18nString(NoRecentlyOpenedFoldersFound);
|
|
929
942
|
};
|
|
930
943
|
const noSymbolFound = () => {
|
|
931
|
-
return i18nString(
|
|
944
|
+
return i18nString(NoSymbolFound);
|
|
932
945
|
};
|
|
933
946
|
const noWorkspaceSymbolsFound = () => {
|
|
934
|
-
return i18nString(
|
|
947
|
+
return i18nString(NoWorkspaceSymbolsFound);
|
|
935
948
|
};
|
|
936
949
|
|
|
937
950
|
const state$4 = {
|
|
@@ -1281,7 +1294,7 @@ const getFiles = () => {
|
|
|
1281
1294
|
return state$3.files;
|
|
1282
1295
|
};
|
|
1283
1296
|
|
|
1284
|
-
const searchFile$
|
|
1297
|
+
const searchFile$5 = async () => {
|
|
1285
1298
|
const files = await getFiles();
|
|
1286
1299
|
const keys = Object.keys(files);
|
|
1287
1300
|
return keys;
|
|
@@ -1289,7 +1302,7 @@ const searchFile$4 = async () => {
|
|
|
1289
1302
|
|
|
1290
1303
|
const SearchFileMemfs = {
|
|
1291
1304
|
__proto__: null,
|
|
1292
|
-
searchFile: searchFile$
|
|
1305
|
+
searchFile: searchFile$5
|
|
1293
1306
|
};
|
|
1294
1307
|
|
|
1295
1308
|
const assetDir = '';
|
|
@@ -1319,7 +1332,7 @@ const removeLeadingSlash = path => {
|
|
|
1319
1332
|
// TODO simplify code
|
|
1320
1333
|
// 1. don't have playground prefix in fileMap json
|
|
1321
1334
|
// 2. remove code here that removes the prefix
|
|
1322
|
-
const searchFile$
|
|
1335
|
+
const searchFile$4 = async path => {
|
|
1323
1336
|
const fileList = await getJson(fileMapUrl);
|
|
1324
1337
|
const result = fileList.map(removeLeadingSlash);
|
|
1325
1338
|
const prefixLength = path.length - 'file:///'.length;
|
|
@@ -1332,7 +1345,7 @@ const searchFile$3 = async path => {
|
|
|
1332
1345
|
|
|
1333
1346
|
const SearchFileFetch = {
|
|
1334
1347
|
__proto__: null,
|
|
1335
|
-
searchFile: searchFile$
|
|
1348
|
+
searchFile: searchFile$4
|
|
1336
1349
|
};
|
|
1337
1350
|
|
|
1338
1351
|
const Directory = 'directory';
|
|
@@ -1616,11 +1629,7 @@ replaceTraps(oldTraps => ({
|
|
|
1616
1629
|
}));
|
|
1617
1630
|
|
|
1618
1631
|
const state$2 = {
|
|
1619
|
-
|
|
1620
|
-
eventId: 0,
|
|
1621
|
-
dbVersion: 1,
|
|
1622
|
-
cachedDb: undefined
|
|
1623
|
-
};
|
|
1632
|
+
dbVersion: 1};
|
|
1624
1633
|
|
|
1625
1634
|
// TODO high memory usage in idb because of transactionDoneMap
|
|
1626
1635
|
|
|
@@ -1683,7 +1692,7 @@ const searchFilesRecursively = async (all, parent, handle) => {
|
|
|
1683
1692
|
}
|
|
1684
1693
|
await Promise.all(promises);
|
|
1685
1694
|
};
|
|
1686
|
-
const searchFile$
|
|
1695
|
+
const searchFile$3 = async uri => {
|
|
1687
1696
|
const path = uri.slice('html://'.length);
|
|
1688
1697
|
const handle = await getDirectoryHandle(path);
|
|
1689
1698
|
if (!handle) {
|
|
@@ -1697,7 +1706,7 @@ const searchFile$2 = async uri => {
|
|
|
1697
1706
|
|
|
1698
1707
|
const SearchFileHtml = {
|
|
1699
1708
|
__proto__: null,
|
|
1700
|
-
searchFile: searchFile$
|
|
1709
|
+
searchFile: searchFile$3
|
|
1701
1710
|
};
|
|
1702
1711
|
|
|
1703
1712
|
const emptyMatches = [];
|
|
@@ -1908,7 +1917,7 @@ const splitLines = lines => {
|
|
|
1908
1917
|
|
|
1909
1918
|
// TODO create direct connection from electron to file search worker using message ports
|
|
1910
1919
|
|
|
1911
|
-
const searchFile$
|
|
1920
|
+
const searchFile$2 = async (path, value, prepare) => {
|
|
1912
1921
|
const ripGrepArgs = getFileSearchRipGrepArgs();
|
|
1913
1922
|
const options = {
|
|
1914
1923
|
ripGrepArgs,
|
|
@@ -1926,7 +1935,7 @@ const searchFile$1 = async (path, value, prepare) => {
|
|
|
1926
1935
|
|
|
1927
1936
|
const SearchFileRipGrep = {
|
|
1928
1937
|
__proto__: null,
|
|
1929
|
-
searchFile: searchFile$
|
|
1938
|
+
searchFile: searchFile$2
|
|
1930
1939
|
};
|
|
1931
1940
|
|
|
1932
1941
|
const getModule = protocol => {
|
|
@@ -1941,7 +1950,8 @@ const getModule = protocol => {
|
|
|
1941
1950
|
return SearchFileRipGrep;
|
|
1942
1951
|
}
|
|
1943
1952
|
};
|
|
1944
|
-
|
|
1953
|
+
|
|
1954
|
+
const searchFile$1 = async (path, value, prepare, assetDir) => {
|
|
1945
1955
|
const protocol = getProtocol(path);
|
|
1946
1956
|
// TODO call different providers depending on protocol
|
|
1947
1957
|
const module = await getModule(protocol);
|
|
@@ -1964,6 +1974,12 @@ const pathDirName = path => {
|
|
|
1964
1974
|
return path.slice(0, index);
|
|
1965
1975
|
};
|
|
1966
1976
|
|
|
1977
|
+
const searchFile = async (path, value) => {
|
|
1978
|
+
const prepare = true;
|
|
1979
|
+
// @ts-ignore
|
|
1980
|
+
const files = await searchFile$1(/* path */path, /* searchTerm */value, prepare);
|
|
1981
|
+
return files;
|
|
1982
|
+
};
|
|
1967
1983
|
const name$7 = 'file';
|
|
1968
1984
|
const getPlaceholder$a = () => {
|
|
1969
1985
|
return '';
|
|
@@ -1985,9 +2001,14 @@ const getNoResults$9 = () => {
|
|
|
1985
2001
|
};
|
|
1986
2002
|
};
|
|
1987
2003
|
const getPicks$a = async searchValue => {
|
|
1988
|
-
|
|
2004
|
+
// TODO cache workspace path
|
|
2005
|
+
const workspace = await invoke$1('Workspace.getPath');
|
|
2006
|
+
if (!workspace) {
|
|
1989
2007
|
return [];
|
|
1990
2008
|
}
|
|
2009
|
+
const files = await searchFile(workspace, searchValue);
|
|
2010
|
+
// const picks = files.map(toPick)
|
|
2011
|
+
return files;
|
|
1991
2012
|
};
|
|
1992
2013
|
const selectPick$a = async pick => {
|
|
1993
2014
|
if (typeof pick === 'object') {
|
|
@@ -2016,7 +2037,7 @@ const getPickLabel$4 = pick => {
|
|
|
2016
2037
|
const baseName = pathBaseName(pick);
|
|
2017
2038
|
return baseName;
|
|
2018
2039
|
};
|
|
2019
|
-
const getPickDescription$
|
|
2040
|
+
const getPickDescription$4 = pick => {
|
|
2020
2041
|
if (typeof pick === 'object') {
|
|
2021
2042
|
pick = pick.pick;
|
|
2022
2043
|
}
|
|
@@ -2042,7 +2063,7 @@ const QuickPickEntriesFile = {
|
|
|
2042
2063
|
getHelpEntries: getHelpEntries$9,
|
|
2043
2064
|
getLabel: getLabel$4,
|
|
2044
2065
|
getNoResults: getNoResults$9,
|
|
2045
|
-
getPickDescription: getPickDescription$
|
|
2066
|
+
getPickDescription: getPickDescription$4,
|
|
2046
2067
|
getPickFileIcon: getPickFileIcon$2,
|
|
2047
2068
|
getPickFilterValue: getPickFilterValue$5,
|
|
2048
2069
|
getPickIcon: getPickIcon$4,
|
|
@@ -2254,7 +2275,7 @@ const Symbol$2 = '@';
|
|
|
2254
2275
|
const WorkspaceSymbol$1 = '#';
|
|
2255
2276
|
const GoToLine = ':';
|
|
2256
2277
|
const View$1 = 'view ';
|
|
2257
|
-
const None$
|
|
2278
|
+
const None$2 = '';
|
|
2258
2279
|
|
|
2259
2280
|
// TODO avoid global variable
|
|
2260
2281
|
|
|
@@ -2296,7 +2317,7 @@ const getPrefix = value => {
|
|
|
2296
2317
|
if (value.startsWith(View$1)) {
|
|
2297
2318
|
return View$1;
|
|
2298
2319
|
}
|
|
2299
|
-
return None$
|
|
2320
|
+
return None$2;
|
|
2300
2321
|
};
|
|
2301
2322
|
const getQuickPickProvider = prefix => {
|
|
2302
2323
|
// TODO could use enum for prefix
|
|
@@ -2351,7 +2372,7 @@ const getPickFilterValue$3 = pick => {
|
|
|
2351
2372
|
} = state$1;
|
|
2352
2373
|
return provider.getPickFilterValue(pick);
|
|
2353
2374
|
};
|
|
2354
|
-
const getPickDescription$
|
|
2375
|
+
const getPickDescription$3 = pick => {
|
|
2355
2376
|
const {
|
|
2356
2377
|
provider
|
|
2357
2378
|
} = state$1;
|
|
@@ -2405,7 +2426,7 @@ const QuickPickEntriesEverything = {
|
|
|
2405
2426
|
getHelpEntries: getHelpEntries$3,
|
|
2406
2427
|
getLabel: getLabel$3,
|
|
2407
2428
|
getNoResults: getNoResults$4,
|
|
2408
|
-
getPickDescription: getPickDescription$
|
|
2429
|
+
getPickDescription: getPickDescription$3,
|
|
2409
2430
|
getPickFileIcon: getPickFileIcon$1,
|
|
2410
2431
|
getPickFilterValue: getPickFilterValue$3,
|
|
2411
2432
|
getPickIcon: getPickIcon$3,
|
|
@@ -2423,7 +2444,7 @@ const QuickPickEntriesEverything = {
|
|
|
2423
2444
|
const Default = 0;
|
|
2424
2445
|
const Finished = 2;
|
|
2425
2446
|
|
|
2426
|
-
const create$
|
|
2447
|
+
const create$3 = () => {
|
|
2427
2448
|
const states = Object.create(null);
|
|
2428
2449
|
return {
|
|
2429
2450
|
get(uid) {
|
|
@@ -2441,9 +2462,9 @@ const create$2 = () => {
|
|
|
2441
2462
|
const {
|
|
2442
2463
|
get,
|
|
2443
2464
|
set
|
|
2444
|
-
} = create$
|
|
2465
|
+
} = create$3();
|
|
2445
2466
|
|
|
2446
|
-
const create$
|
|
2467
|
+
const create$2 = ({
|
|
2447
2468
|
itemHeight,
|
|
2448
2469
|
headerHeight = 0,
|
|
2449
2470
|
minimumSliderSize = 20
|
|
@@ -2465,6 +2486,82 @@ const create$1 = ({
|
|
|
2465
2486
|
scrollBarActive: false
|
|
2466
2487
|
};
|
|
2467
2488
|
};
|
|
2489
|
+
const getListHeight = (height, headerHeight) => {
|
|
2490
|
+
if (headerHeight) {
|
|
2491
|
+
return height - headerHeight;
|
|
2492
|
+
}
|
|
2493
|
+
return headerHeight;
|
|
2494
|
+
};
|
|
2495
|
+
const setDeltaY = (state, deltaY) => {
|
|
2496
|
+
object(state);
|
|
2497
|
+
number(deltaY);
|
|
2498
|
+
const {
|
|
2499
|
+
itemHeight,
|
|
2500
|
+
items,
|
|
2501
|
+
height,
|
|
2502
|
+
headerHeight
|
|
2503
|
+
} = state;
|
|
2504
|
+
const listHeight = getListHeight(height, headerHeight);
|
|
2505
|
+
const itemsLength = items.length;
|
|
2506
|
+
const finalDeltaY = itemsLength * itemHeight - listHeight;
|
|
2507
|
+
if (deltaY < 0) {
|
|
2508
|
+
deltaY = 0;
|
|
2509
|
+
} else if (deltaY > finalDeltaY) {
|
|
2510
|
+
deltaY = Math.max(finalDeltaY, 0);
|
|
2511
|
+
}
|
|
2512
|
+
if (state.deltaY === deltaY) {
|
|
2513
|
+
return state;
|
|
2514
|
+
}
|
|
2515
|
+
const minLineY = Math.round(deltaY / itemHeight);
|
|
2516
|
+
const maxLineY = minLineY + Math.round(listHeight / itemHeight);
|
|
2517
|
+
number(minLineY);
|
|
2518
|
+
number(maxLineY);
|
|
2519
|
+
return {
|
|
2520
|
+
...state,
|
|
2521
|
+
deltaY,
|
|
2522
|
+
minLineY,
|
|
2523
|
+
maxLineY
|
|
2524
|
+
};
|
|
2525
|
+
};
|
|
2526
|
+
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2527
|
+
object(state);
|
|
2528
|
+
number(deltaMode);
|
|
2529
|
+
number(deltaY);
|
|
2530
|
+
return setDeltaY(state, state.deltaY + deltaY);
|
|
2531
|
+
};
|
|
2532
|
+
|
|
2533
|
+
const create$1 = (uid, uri, listItemHeight, x, y, width, height, platform, args) => {
|
|
2534
|
+
const state = {
|
|
2535
|
+
uid,
|
|
2536
|
+
state: Default,
|
|
2537
|
+
picks: [],
|
|
2538
|
+
recentPicks: [],
|
|
2539
|
+
recentPickIds: new Map(),
|
|
2540
|
+
// TODO use object.create(null) instead
|
|
2541
|
+
versionId: 0,
|
|
2542
|
+
provider: QuickPickEntriesEverything,
|
|
2543
|
+
// TODO make this dynamic again
|
|
2544
|
+
warned: [],
|
|
2545
|
+
visiblePicks: [],
|
|
2546
|
+
maxVisibleItems: 10,
|
|
2547
|
+
uri,
|
|
2548
|
+
cursorOffset: 0,
|
|
2549
|
+
height: 300,
|
|
2550
|
+
top: 50,
|
|
2551
|
+
width: 600,
|
|
2552
|
+
...create$2({
|
|
2553
|
+
itemHeight: listItemHeight,
|
|
2554
|
+
headerHeight: 30,
|
|
2555
|
+
minimumSliderSize: minimumSliderSize
|
|
2556
|
+
}),
|
|
2557
|
+
inputSource: User,
|
|
2558
|
+
args,
|
|
2559
|
+
focused: false,
|
|
2560
|
+
platform,
|
|
2561
|
+
value: ''
|
|
2562
|
+
};
|
|
2563
|
+
set(uid, state, state);
|
|
2564
|
+
};
|
|
2468
2565
|
|
|
2469
2566
|
const create = (uid, uri, listItemHeight, x, y, width, height, platform, args) => {
|
|
2470
2567
|
const state = {
|
|
@@ -2485,7 +2582,7 @@ const create = (uid, uri, listItemHeight, x, y, width, height, platform, args) =
|
|
|
2485
2582
|
height: 300,
|
|
2486
2583
|
top: 50,
|
|
2487
2584
|
width: 600,
|
|
2488
|
-
...create$
|
|
2585
|
+
...create$2({
|
|
2489
2586
|
itemHeight: listItemHeight,
|
|
2490
2587
|
headerHeight: 30,
|
|
2491
2588
|
minimumSliderSize: minimumSliderSize
|
|
@@ -2576,6 +2673,95 @@ const getBlob = async (uri, type) => {
|
|
|
2576
2673
|
return blob;
|
|
2577
2674
|
};
|
|
2578
2675
|
|
|
2676
|
+
const focusIndex = async (state, index) => {
|
|
2677
|
+
const {
|
|
2678
|
+
provider,
|
|
2679
|
+
maxVisibleItems,
|
|
2680
|
+
items,
|
|
2681
|
+
minLineY,
|
|
2682
|
+
maxLineY
|
|
2683
|
+
} = state;
|
|
2684
|
+
// TODO get types working
|
|
2685
|
+
// @ts-ignore
|
|
2686
|
+
if (provider.focusPick) {
|
|
2687
|
+
// @ts-ignore
|
|
2688
|
+
await provider.focusPick(items[index].pick);
|
|
2689
|
+
}
|
|
2690
|
+
if (index < minLineY + 1) {
|
|
2691
|
+
const minLineY = index;
|
|
2692
|
+
const maxLineY = Math.min(index + maxVisibleItems, items.length - 1);
|
|
2693
|
+
// TODO need to scroll up
|
|
2694
|
+
return {
|
|
2695
|
+
...state,
|
|
2696
|
+
minLineY,
|
|
2697
|
+
maxLineY,
|
|
2698
|
+
focusedIndex: index
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
if (index >= maxLineY - 1) {
|
|
2702
|
+
// TODO need to scroll down
|
|
2703
|
+
const maxLineY = index + 1;
|
|
2704
|
+
const minLineY = Math.max(maxLineY - maxVisibleItems, 0);
|
|
2705
|
+
return {
|
|
2706
|
+
...state,
|
|
2707
|
+
minLineY,
|
|
2708
|
+
maxLineY,
|
|
2709
|
+
focusedIndex: index
|
|
2710
|
+
};
|
|
2711
|
+
}
|
|
2712
|
+
return {
|
|
2713
|
+
...state,
|
|
2714
|
+
focusedIndex: index
|
|
2715
|
+
};
|
|
2716
|
+
};
|
|
2717
|
+
|
|
2718
|
+
const first = () => {
|
|
2719
|
+
return 0;
|
|
2720
|
+
};
|
|
2721
|
+
const last = items => {
|
|
2722
|
+
return items.length - 1;
|
|
2723
|
+
};
|
|
2724
|
+
const next = (items, index) => {
|
|
2725
|
+
return (index + 1) % items.length;
|
|
2726
|
+
};
|
|
2727
|
+
const previous = (items, index) => {
|
|
2728
|
+
return index === 0 ? items.length - 1 : index - 1;
|
|
2729
|
+
};
|
|
2730
|
+
|
|
2731
|
+
const focusFirst = state => {
|
|
2732
|
+
return focusIndex(state, first());
|
|
2733
|
+
};
|
|
2734
|
+
|
|
2735
|
+
const focusLast = state => {
|
|
2736
|
+
const {
|
|
2737
|
+
items
|
|
2738
|
+
} = state;
|
|
2739
|
+
return focusIndex(state, last(items));
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
const focusNext = state => {
|
|
2743
|
+
const {
|
|
2744
|
+
items,
|
|
2745
|
+
focusedIndex
|
|
2746
|
+
} = state;
|
|
2747
|
+
const nextIndex = next(items, focusedIndex);
|
|
2748
|
+
return focusIndex(state, nextIndex);
|
|
2749
|
+
};
|
|
2750
|
+
|
|
2751
|
+
const focusPrevious = state => {
|
|
2752
|
+
const {
|
|
2753
|
+
items,
|
|
2754
|
+
focusedIndex
|
|
2755
|
+
} = state;
|
|
2756
|
+
const previousIndex = previous(items, focusedIndex);
|
|
2757
|
+
return focusIndex(state, previousIndex);
|
|
2758
|
+
};
|
|
2759
|
+
|
|
2760
|
+
const commandIds = ['handleBlur', 'handleClickAt', 'handleWheel', 'selectCurrentIndex', 'selectIndex', 'selectItem', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'handleInput', 'handleBeforeInput'];
|
|
2761
|
+
const getCommandIds = () => {
|
|
2762
|
+
return commandIds;
|
|
2763
|
+
};
|
|
2764
|
+
|
|
2579
2765
|
const Enter = 3;
|
|
2580
2766
|
const Escape = 8;
|
|
2581
2767
|
const PageUp = 10;
|
|
@@ -2614,6 +2800,191 @@ const getKeyBindings = () => {
|
|
|
2614
2800
|
}];
|
|
2615
2801
|
};
|
|
2616
2802
|
|
|
2803
|
+
const InsertText = 'insertText';
|
|
2804
|
+
const DeleteContentBackward = 'deleteContentBackward';
|
|
2805
|
+
const DeleteContentForward = 'deleteContentForward';
|
|
2806
|
+
const DeleteWordForward = 'deleteWordForward';
|
|
2807
|
+
const DeleteWordBackward = 'deleteWordBackward';
|
|
2808
|
+
const InsertLineBreak = 'insertLineBreak';
|
|
2809
|
+
const InsertCompositionText = 'insertCompositionText';
|
|
2810
|
+
const InsertFromPaste = 'insertFromPaste';
|
|
2811
|
+
|
|
2812
|
+
const getNewValueInsertText = (value, selectionStart, selectionEnd, data) => {
|
|
2813
|
+
if (selectionStart === value.length) {
|
|
2814
|
+
const newValue = value + data;
|
|
2815
|
+
return {
|
|
2816
|
+
newValue,
|
|
2817
|
+
cursorOffset: newValue.length
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
const before = value.slice(0, selectionStart);
|
|
2821
|
+
const after = value.slice(selectionEnd);
|
|
2822
|
+
const newValue = before + data + after;
|
|
2823
|
+
return {
|
|
2824
|
+
newValue,
|
|
2825
|
+
cursorOffset: selectionStart + data.length
|
|
2826
|
+
};
|
|
2827
|
+
};
|
|
2828
|
+
const getNewValueDeleteContentBackward = (value, selectionStart, selectionEnd, data) => {
|
|
2829
|
+
const after = value.slice(selectionEnd);
|
|
2830
|
+
if (selectionStart === selectionEnd) {
|
|
2831
|
+
const before = value.slice(0, selectionStart - 1);
|
|
2832
|
+
const newValue = before + after;
|
|
2833
|
+
return {
|
|
2834
|
+
newValue,
|
|
2835
|
+
cursorOffset: before.length
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
const before = value.slice(0, selectionStart);
|
|
2839
|
+
const newValue = before + after;
|
|
2840
|
+
return {
|
|
2841
|
+
newValue,
|
|
2842
|
+
cursorOffset: selectionStart
|
|
2843
|
+
};
|
|
2844
|
+
};
|
|
2845
|
+
const RE_ALPHA_NUMERIC = /[a-z\d]/i;
|
|
2846
|
+
const isAlphaNumeric = character => {
|
|
2847
|
+
return RE_ALPHA_NUMERIC.test(character);
|
|
2848
|
+
};
|
|
2849
|
+
const getNewValueDeleteWordBackward = (value, selectionStart, selectionEnd, data) => {
|
|
2850
|
+
const after = value.slice(selectionEnd);
|
|
2851
|
+
if (selectionStart === selectionEnd) {
|
|
2852
|
+
let startIndex = Math.max(selectionStart - 1, 0);
|
|
2853
|
+
while (startIndex > 0 && isAlphaNumeric(value[startIndex])) {
|
|
2854
|
+
startIndex--;
|
|
2855
|
+
}
|
|
2856
|
+
const before = value.slice(0, startIndex);
|
|
2857
|
+
const newValue = before + after;
|
|
2858
|
+
return {
|
|
2859
|
+
newValue,
|
|
2860
|
+
cursorOffset: before.length
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
const before = value.slice(0, selectionStart);
|
|
2864
|
+
const newValue = before + after;
|
|
2865
|
+
return {
|
|
2866
|
+
newValue,
|
|
2867
|
+
cursorOffset: selectionStart
|
|
2868
|
+
};
|
|
2869
|
+
};
|
|
2870
|
+
const getNewValueDeleteContentForward = (value, selectionStart, selectionEnd, data) => {
|
|
2871
|
+
const before = value.slice(0, selectionStart);
|
|
2872
|
+
if (selectionStart === selectionEnd) {
|
|
2873
|
+
const after = value.slice(selectionEnd + 1);
|
|
2874
|
+
const newValue = before + after;
|
|
2875
|
+
return {
|
|
2876
|
+
newValue,
|
|
2877
|
+
cursorOffset: selectionStart
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2880
|
+
const after = value.slice(selectionEnd);
|
|
2881
|
+
const newValue = before + after;
|
|
2882
|
+
return {
|
|
2883
|
+
newValue,
|
|
2884
|
+
cursorOffset: selectionStart
|
|
2885
|
+
};
|
|
2886
|
+
};
|
|
2887
|
+
const getNewValueDeleteWordForward = (value, selectionStart, selectionEnd, data) => {
|
|
2888
|
+
const before = value.slice(0, selectionStart);
|
|
2889
|
+
if (selectionStart === selectionEnd) {
|
|
2890
|
+
let startIndex = Math.min(selectionStart + 1, value.length - 1);
|
|
2891
|
+
while (startIndex < value.length && isAlphaNumeric(value[startIndex])) {
|
|
2892
|
+
startIndex++;
|
|
2893
|
+
}
|
|
2894
|
+
const after = value.slice(startIndex);
|
|
2895
|
+
const newValue = before + after;
|
|
2896
|
+
return {
|
|
2897
|
+
newValue,
|
|
2898
|
+
cursorOffset: before.length
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
const after = value.slice(selectionEnd);
|
|
2902
|
+
const newValue = before + after;
|
|
2903
|
+
return {
|
|
2904
|
+
newValue,
|
|
2905
|
+
cursorOffset: selectionStart
|
|
2906
|
+
};
|
|
2907
|
+
};
|
|
2908
|
+
const getNewValueInsertCompositionText = (value, selectionStart, selectionEnd, data) => {
|
|
2909
|
+
return getNewValueInsertText(value, selectionStart, selectionEnd, data);
|
|
2910
|
+
};
|
|
2911
|
+
const getNewValueInsertLineBreak = (value, selectionStart, selectionEnd, data) => {
|
|
2912
|
+
return {
|
|
2913
|
+
newValue: value,
|
|
2914
|
+
cursorOffset: selectionEnd
|
|
2915
|
+
};
|
|
2916
|
+
};
|
|
2917
|
+
const getFn = inputType => {
|
|
2918
|
+
switch (inputType) {
|
|
2919
|
+
case InsertFromPaste:
|
|
2920
|
+
case InsertText:
|
|
2921
|
+
return getNewValueInsertText;
|
|
2922
|
+
case DeleteContentBackward:
|
|
2923
|
+
return getNewValueDeleteContentBackward;
|
|
2924
|
+
case DeleteContentForward:
|
|
2925
|
+
return getNewValueDeleteContentForward;
|
|
2926
|
+
case DeleteWordForward:
|
|
2927
|
+
return getNewValueDeleteWordForward;
|
|
2928
|
+
case DeleteWordBackward:
|
|
2929
|
+
return getNewValueDeleteWordBackward;
|
|
2930
|
+
case InsertLineBreak:
|
|
2931
|
+
return getNewValueInsertLineBreak;
|
|
2932
|
+
case InsertCompositionText:
|
|
2933
|
+
return getNewValueInsertCompositionText;
|
|
2934
|
+
default:
|
|
2935
|
+
throw new Error(`unsupported input type ${inputType}`);
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
const getNewValue = (value, inputType, data, selectionStart, selectionEnd) => {
|
|
2939
|
+
const fn = getFn(inputType);
|
|
2940
|
+
return fn(value, selectionStart, selectionEnd, data);
|
|
2941
|
+
};
|
|
2942
|
+
|
|
2943
|
+
// TODO when user types letters -> no need to query provider again -> just filter existing results
|
|
2944
|
+
const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
|
|
2945
|
+
if (state.value === newValue) {
|
|
2946
|
+
return state;
|
|
2947
|
+
}
|
|
2948
|
+
// @ts-ignore
|
|
2949
|
+
state.value = newValue;
|
|
2950
|
+
// @ts-ignore
|
|
2951
|
+
state.inputSource = inputSource;
|
|
2952
|
+
const newPicks = await state.provider.getPicks(newValue);
|
|
2953
|
+
const filterValue = state.provider.getFilterValue(newValue);
|
|
2954
|
+
const items = filterQuickPickItems(newPicks, filterValue);
|
|
2955
|
+
const focusedIndex = items.length === 0 ? -1 : 0;
|
|
2956
|
+
return {
|
|
2957
|
+
...state,
|
|
2958
|
+
picks: newPicks,
|
|
2959
|
+
items,
|
|
2960
|
+
focusedIndex,
|
|
2961
|
+
cursorOffset
|
|
2962
|
+
};
|
|
2963
|
+
};
|
|
2964
|
+
|
|
2965
|
+
const handleBeforeInput = (state, inputType, data, selectionStart, selectionEnd) => {
|
|
2966
|
+
string(inputType);
|
|
2967
|
+
number(selectionStart);
|
|
2968
|
+
number(selectionEnd);
|
|
2969
|
+
const {
|
|
2970
|
+
value
|
|
2971
|
+
} = state;
|
|
2972
|
+
const {
|
|
2973
|
+
newValue,
|
|
2974
|
+
cursorOffset
|
|
2975
|
+
} = getNewValue(value, inputType, data, selectionStart, selectionEnd);
|
|
2976
|
+
return handleInput(state, newValue, cursorOffset, User);
|
|
2977
|
+
};
|
|
2978
|
+
|
|
2979
|
+
const closeWidget = async id => {
|
|
2980
|
+
await invoke$1('Viewlet.closeWidget', id);
|
|
2981
|
+
};
|
|
2982
|
+
|
|
2983
|
+
const handleBlur = async state => {
|
|
2984
|
+
await closeWidget(state.uid);
|
|
2985
|
+
return state;
|
|
2986
|
+
};
|
|
2987
|
+
|
|
2617
2988
|
const getDefaultValue = uri => {
|
|
2618
2989
|
switch (uri) {
|
|
2619
2990
|
case 'quickPick://everything':
|
|
@@ -2685,7 +3056,7 @@ const QuickPickEntriesColorTheme = {
|
|
|
2685
3056
|
const Tag$1 = 'Tag';
|
|
2686
3057
|
const Cloud$1 = 'Cloud';
|
|
2687
3058
|
const SourceControl$1 = 'SourceControl';
|
|
2688
|
-
const None = '';
|
|
3059
|
+
const None$1 = '';
|
|
2689
3060
|
|
|
2690
3061
|
const SourceControl = 1;
|
|
2691
3062
|
const Cloud = 2;
|
|
@@ -2737,7 +3108,7 @@ const getPickFilterValue$1 = pick => {
|
|
|
2737
3108
|
const getPickLabel$1 = pick => {
|
|
2738
3109
|
return pick.label;
|
|
2739
3110
|
};
|
|
2740
|
-
const getPickDescription$
|
|
3111
|
+
const getPickDescription$2 = pick => {
|
|
2741
3112
|
return pick.description || '';
|
|
2742
3113
|
};
|
|
2743
3114
|
const convertIcon = icon => {
|
|
@@ -2749,7 +3120,7 @@ const convertIcon = icon => {
|
|
|
2749
3120
|
case Tag:
|
|
2750
3121
|
return Tag$1;
|
|
2751
3122
|
default:
|
|
2752
|
-
return None;
|
|
3123
|
+
return None$1;
|
|
2753
3124
|
}
|
|
2754
3125
|
};
|
|
2755
3126
|
const getPickIcon$1 = pick => {
|
|
@@ -2762,7 +3133,7 @@ const QuickPickEntriesCustom = {
|
|
|
2762
3133
|
getHelpEntries: getHelpEntries$2,
|
|
2763
3134
|
getLabel: getLabel$1,
|
|
2764
3135
|
getNoResults: getNoResults$2,
|
|
2765
|
-
getPickDescription: getPickDescription$
|
|
3136
|
+
getPickDescription: getPickDescription$2,
|
|
2766
3137
|
getPickFilterValue: getPickFilterValue$1,
|
|
2767
3138
|
getPickIcon: getPickIcon$1,
|
|
2768
3139
|
getPickLabel: getPickLabel$1,
|
|
@@ -2879,7 +3250,7 @@ const getPickFilterValue = pick => {
|
|
|
2879
3250
|
const getPickLabel = pick => {
|
|
2880
3251
|
return pathBaseName(pick);
|
|
2881
3252
|
};
|
|
2882
|
-
const getPickDescription = pick => {
|
|
3253
|
+
const getPickDescription$1 = pick => {
|
|
2883
3254
|
return pathDirName(pick);
|
|
2884
3255
|
};
|
|
2885
3256
|
const getPickIcon = () => {
|
|
@@ -2895,7 +3266,7 @@ const QuickPickEntriesOpenRecent = {
|
|
|
2895
3266
|
getHelpEntries,
|
|
2896
3267
|
getLabel,
|
|
2897
3268
|
getNoResults,
|
|
2898
|
-
getPickDescription,
|
|
3269
|
+
getPickDescription: getPickDescription$1,
|
|
2899
3270
|
getPickFileIcon,
|
|
2900
3271
|
getPickFilterValue,
|
|
2901
3272
|
getPickIcon,
|
|
@@ -2956,7 +3327,7 @@ const loadContent = async state => {
|
|
|
2956
3327
|
array(newPicks);
|
|
2957
3328
|
// @ts-ignore
|
|
2958
3329
|
const filterValue = provider.getFilterValue(value);
|
|
2959
|
-
const items = filterQuickPickItems(
|
|
3330
|
+
const items = filterQuickPickItems(newPicks, filterValue);
|
|
2960
3331
|
// @ts-ignore
|
|
2961
3332
|
provider.getLabel();
|
|
2962
3333
|
const minLineY = 0;
|
|
@@ -2986,7 +3357,426 @@ const loadQuickPickEntries = moduleId => {
|
|
|
2986
3357
|
}
|
|
2987
3358
|
};
|
|
2988
3359
|
|
|
3360
|
+
const RenderItems = 1;
|
|
3361
|
+
const RenderFocus = 2;
|
|
3362
|
+
const RenderValue = 3;
|
|
3363
|
+
const RenderCursorOffset = 7;
|
|
3364
|
+
const RenderFocusedIndex = 8;
|
|
3365
|
+
const Height = 9;
|
|
3366
|
+
|
|
3367
|
+
const FileIcon = 'FileIcon';
|
|
3368
|
+
const Label = 'Label';
|
|
3369
|
+
const QuickPickHighlight = 'QuickPickHighlight';
|
|
3370
|
+
const QuickPickItem = 'QuickPickItem';
|
|
3371
|
+
const QuickPickItemActive = 'QuickPickItemActive';
|
|
3372
|
+
const QuickPickItemDescription = 'QuickPickItemDescription';
|
|
3373
|
+
const QuickPickItemLabel = 'QuickPickItemLabel';
|
|
3374
|
+
|
|
3375
|
+
const None = 'none';
|
|
3376
|
+
const Option = 'option';
|
|
3377
|
+
|
|
3378
|
+
const Div = 4;
|
|
3379
|
+
const Span = 8;
|
|
3380
|
+
const Text = 12;
|
|
3381
|
+
const Img = 17;
|
|
3382
|
+
|
|
3383
|
+
const getFileIconVirtualDom = icon => {
|
|
3384
|
+
return {
|
|
3385
|
+
type: Img,
|
|
3386
|
+
className: FileIcon,
|
|
3387
|
+
src: icon,
|
|
3388
|
+
role: None,
|
|
3389
|
+
childCount: 0
|
|
3390
|
+
};
|
|
3391
|
+
};
|
|
3392
|
+
|
|
3393
|
+
const text = data => {
|
|
3394
|
+
return {
|
|
3395
|
+
type: Text,
|
|
3396
|
+
text: data,
|
|
3397
|
+
childCount: 0
|
|
3398
|
+
};
|
|
3399
|
+
};
|
|
3400
|
+
|
|
3401
|
+
const quickPickHighlight = {
|
|
3402
|
+
type: Span,
|
|
3403
|
+
className: QuickPickHighlight,
|
|
3404
|
+
childCount: 1
|
|
3405
|
+
};
|
|
3406
|
+
const addHighlights = (dom, highlights, label) => {
|
|
3407
|
+
const labelDom = {
|
|
3408
|
+
type: Div,
|
|
3409
|
+
className: QuickPickItemLabel,
|
|
3410
|
+
childCount: 0
|
|
3411
|
+
};
|
|
3412
|
+
dom.push(labelDom);
|
|
3413
|
+
let position = 0;
|
|
3414
|
+
for (let i = 0; i < highlights.length; i += 2) {
|
|
3415
|
+
const highlightStart = highlights[i];
|
|
3416
|
+
const highlightEnd = highlights[i + 1];
|
|
3417
|
+
if (position < highlightStart) {
|
|
3418
|
+
const beforeText = label.slice(position, highlightStart);
|
|
3419
|
+
labelDom.childCount++;
|
|
3420
|
+
dom.push(text(beforeText));
|
|
3421
|
+
}
|
|
3422
|
+
const highlightText = label.slice(highlightStart, highlightEnd);
|
|
3423
|
+
labelDom.childCount++;
|
|
3424
|
+
dom.push(quickPickHighlight, text(highlightText));
|
|
3425
|
+
position = highlightEnd;
|
|
3426
|
+
}
|
|
3427
|
+
if (position < label.length) {
|
|
3428
|
+
const afterText = label.slice(position);
|
|
3429
|
+
labelDom.childCount++;
|
|
3430
|
+
dom.push(text(afterText));
|
|
3431
|
+
}
|
|
3432
|
+
};
|
|
3433
|
+
const getQuickPickItemVirtualDom = visibleItem => {
|
|
3434
|
+
const {
|
|
3435
|
+
posInSet,
|
|
3436
|
+
label,
|
|
3437
|
+
setSize,
|
|
3438
|
+
isActive,
|
|
3439
|
+
description,
|
|
3440
|
+
icon,
|
|
3441
|
+
matches,
|
|
3442
|
+
fileIcon
|
|
3443
|
+
} = visibleItem;
|
|
3444
|
+
const highlights = matches.slice(1);
|
|
3445
|
+
const dom = [];
|
|
3446
|
+
dom.push({
|
|
3447
|
+
type: Div,
|
|
3448
|
+
className: QuickPickItem,
|
|
3449
|
+
role: Option,
|
|
3450
|
+
ariaPosInSet: posInSet,
|
|
3451
|
+
ariaSetSize: setSize,
|
|
3452
|
+
childCount: 1
|
|
3453
|
+
});
|
|
3454
|
+
const parent = dom[0];
|
|
3455
|
+
if (isActive) {
|
|
3456
|
+
// @ts-ignore
|
|
3457
|
+
parent.id = 'QuickPickItemActive';
|
|
3458
|
+
parent.className += ' ' + QuickPickItemActive;
|
|
3459
|
+
}
|
|
3460
|
+
if (fileIcon) {
|
|
3461
|
+
parent.childCount++;
|
|
3462
|
+
dom.push(getFileIconVirtualDom(fileIcon));
|
|
3463
|
+
} else if (icon) {
|
|
3464
|
+
parent.childCount++;
|
|
3465
|
+
dom.push({
|
|
3466
|
+
type: Div,
|
|
3467
|
+
className: `QuickPickMaskIcon MaskIcon MaskIcon${icon}`,
|
|
3468
|
+
childCount: 0
|
|
3469
|
+
});
|
|
3470
|
+
}
|
|
3471
|
+
addHighlights(dom, highlights, label);
|
|
3472
|
+
if (description) {
|
|
3473
|
+
parent.childCount++;
|
|
3474
|
+
dom.push({
|
|
3475
|
+
type: Div,
|
|
3476
|
+
className: QuickPickItemDescription,
|
|
3477
|
+
childCount: 1
|
|
3478
|
+
}, text(description));
|
|
3479
|
+
}
|
|
3480
|
+
return dom;
|
|
3481
|
+
};
|
|
3482
|
+
|
|
3483
|
+
const getQuickPickItemsVirtualDom = visibleItems => {
|
|
3484
|
+
if (visibleItems.length === 0) {
|
|
3485
|
+
return [{
|
|
3486
|
+
type: Div,
|
|
3487
|
+
className: 'QuickPickItem QuickPickItemActive QuickPickStatus',
|
|
3488
|
+
childCount: 1
|
|
3489
|
+
}, {
|
|
3490
|
+
type: Div,
|
|
3491
|
+
className: Label,
|
|
3492
|
+
childCount: 1
|
|
3493
|
+
}, text('No Results')];
|
|
3494
|
+
}
|
|
3495
|
+
const dom = visibleItems.flatMap(getQuickPickItemVirtualDom);
|
|
3496
|
+
return dom;
|
|
3497
|
+
};
|
|
3498
|
+
|
|
3499
|
+
const getPickDescription = (provider, pick) => {
|
|
3500
|
+
if (provider.getPickDescription) {
|
|
3501
|
+
return provider.getPickDescription(pick);
|
|
3502
|
+
}
|
|
3503
|
+
return '';
|
|
3504
|
+
};
|
|
3505
|
+
const getFileIcon = (provider, pick) => {
|
|
3506
|
+
if (provider.getPickFileIcon) {
|
|
3507
|
+
return provider.getPickFileIcon(pick);
|
|
3508
|
+
}
|
|
3509
|
+
return '';
|
|
3510
|
+
};
|
|
3511
|
+
const getVisible = (provider, items, minLineY, maxLineY, focusedIndex) => {
|
|
3512
|
+
const visibleItems = [];
|
|
3513
|
+
const setSize = items.length;
|
|
3514
|
+
const max = Math.min(setSize, maxLineY);
|
|
3515
|
+
for (let i = minLineY; i < max; i++) {
|
|
3516
|
+
const item = items[i];
|
|
3517
|
+
const pick = item.pick;
|
|
3518
|
+
const label = provider.getPickLabel(pick);
|
|
3519
|
+
const description = getPickDescription(provider, pick);
|
|
3520
|
+
const icon = provider.getPickIcon(pick);
|
|
3521
|
+
const fileIcon = getFileIcon(provider, pick);
|
|
3522
|
+
visibleItems.push({
|
|
3523
|
+
label,
|
|
3524
|
+
description,
|
|
3525
|
+
icon,
|
|
3526
|
+
fileIcon,
|
|
3527
|
+
posInSet: i + 1,
|
|
3528
|
+
setSize,
|
|
3529
|
+
isActive: i === focusedIndex,
|
|
3530
|
+
matches: item.matches
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
return visibleItems;
|
|
3534
|
+
};
|
|
3535
|
+
|
|
3536
|
+
const SetCursorOffset = 'setCursorOffset';
|
|
3537
|
+
const SetFocusedIndex = 'setFocusedIndex';
|
|
3538
|
+
const SetItemsHeight = 'setItemsHeight';
|
|
3539
|
+
const SetValue = 'setValue';
|
|
3540
|
+
|
|
3541
|
+
const renderValue = (oldState, newState) => {
|
|
3542
|
+
return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
|
|
3543
|
+
};
|
|
3544
|
+
const renderCursorOffset = (oldState, newState) => {
|
|
3545
|
+
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3546
|
+
};
|
|
3547
|
+
const renderItems = (oldState, newState) => {
|
|
3548
|
+
const visibleItems = getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
|
|
3549
|
+
const dom = getQuickPickItemsVirtualDom(visibleItems);
|
|
3550
|
+
return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
|
|
3551
|
+
};
|
|
3552
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
3553
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3554
|
+
const newFocusedIndex = newState.focusedIndex - newState.minLineY;
|
|
3555
|
+
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
|
|
3556
|
+
};
|
|
3557
|
+
const renderHeight = (oldState, newState) => {
|
|
3558
|
+
if (newState.items.length === 0) {
|
|
3559
|
+
return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.itemHeight];
|
|
3560
|
+
}
|
|
3561
|
+
const maxLineY = Math.min(newState.maxLineY, newState.items.length);
|
|
3562
|
+
const itemCount = maxLineY - newState.minLineY;
|
|
3563
|
+
const height = itemCount * newState.itemHeight;
|
|
3564
|
+
return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */height];
|
|
3565
|
+
};
|
|
3566
|
+
const renderFocus = (oldState, newState) => {
|
|
3567
|
+
const selector = newState.focused ? '.InputBox' : '';
|
|
3568
|
+
return ['Viewlet.focusSelector', selector];
|
|
3569
|
+
};
|
|
3570
|
+
const getRenderer = diffType => {
|
|
3571
|
+
switch (diffType) {
|
|
3572
|
+
case RenderValue:
|
|
3573
|
+
return renderValue;
|
|
3574
|
+
case RenderCursorOffset:
|
|
3575
|
+
return renderCursorOffset;
|
|
3576
|
+
case RenderItems:
|
|
3577
|
+
return renderItems;
|
|
3578
|
+
case RenderFocusedIndex:
|
|
3579
|
+
return renderFocusedIndex;
|
|
3580
|
+
case Height:
|
|
3581
|
+
return renderHeight;
|
|
3582
|
+
case RenderFocus:
|
|
3583
|
+
return renderFocus;
|
|
3584
|
+
default:
|
|
3585
|
+
throw new Error('unknown renderer');
|
|
3586
|
+
}
|
|
3587
|
+
};
|
|
3588
|
+
|
|
3589
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
3590
|
+
const commands = [];
|
|
3591
|
+
for (const item of diffResult) {
|
|
3592
|
+
const fn = getRenderer(item);
|
|
3593
|
+
commands.push(fn(oldState, newState));
|
|
3594
|
+
}
|
|
3595
|
+
return commands;
|
|
3596
|
+
};
|
|
3597
|
+
|
|
3598
|
+
const diffType$4 = RenderFocus;
|
|
3599
|
+
const isEqual$4 = (oldState, newState) => {
|
|
3600
|
+
return oldState.focused === newState.focused;
|
|
3601
|
+
};
|
|
3602
|
+
|
|
3603
|
+
const DiffFocus = {
|
|
3604
|
+
__proto__: null,
|
|
3605
|
+
diffType: diffType$4,
|
|
3606
|
+
isEqual: isEqual$4
|
|
3607
|
+
};
|
|
3608
|
+
|
|
3609
|
+
const diffType$3 = RenderFocusedIndex;
|
|
3610
|
+
const isEqual$3 = (oldState, newState) => {
|
|
3611
|
+
return oldState.focusedIndex === newState.focusedIndex;
|
|
3612
|
+
};
|
|
3613
|
+
|
|
3614
|
+
const DiffFocusedIndex = {
|
|
3615
|
+
__proto__: null,
|
|
3616
|
+
diffType: diffType$3,
|
|
3617
|
+
isEqual: isEqual$3
|
|
3618
|
+
};
|
|
3619
|
+
|
|
3620
|
+
const diffType$2 = Height;
|
|
3621
|
+
const isEqual$2 = (oldState, newState) => {
|
|
3622
|
+
return oldState.items.length === newState.items.length;
|
|
3623
|
+
};
|
|
3624
|
+
|
|
3625
|
+
const DiffHeight = {
|
|
3626
|
+
__proto__: null,
|
|
3627
|
+
diffType: diffType$2,
|
|
3628
|
+
isEqual: isEqual$2
|
|
3629
|
+
};
|
|
3630
|
+
|
|
3631
|
+
const diffType$1 = RenderItems;
|
|
3632
|
+
const isEqual$1 = (oldState, newState) => {
|
|
3633
|
+
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
|
|
3634
|
+
};
|
|
3635
|
+
|
|
3636
|
+
const DiffItems = {
|
|
3637
|
+
__proto__: null,
|
|
3638
|
+
diffType: diffType$1,
|
|
3639
|
+
isEqual: isEqual$1
|
|
3640
|
+
};
|
|
3641
|
+
|
|
3642
|
+
const diffType = RenderValue;
|
|
3643
|
+
const isEqual = (oldState, newState) => {
|
|
3644
|
+
return newState.inputSource === User || oldState.value === newState.value;
|
|
3645
|
+
};
|
|
3646
|
+
|
|
3647
|
+
const DiffValue = {
|
|
3648
|
+
__proto__: null,
|
|
3649
|
+
diffType,
|
|
3650
|
+
isEqual
|
|
3651
|
+
};
|
|
3652
|
+
|
|
3653
|
+
const modules = [DiffHeight, DiffItems, DiffFocus, DiffFocus, DiffValue, DiffFocusedIndex];
|
|
3654
|
+
|
|
3655
|
+
const diff = (oldState, newState) => {
|
|
3656
|
+
const diffResult = [];
|
|
3657
|
+
for (const module of modules) {
|
|
3658
|
+
if (!module.isEqual(oldState, newState)) {
|
|
3659
|
+
diffResult.push(module.diffType);
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
return diffResult;
|
|
3663
|
+
};
|
|
3664
|
+
|
|
3665
|
+
const doRender = uid => {
|
|
3666
|
+
const {
|
|
3667
|
+
oldState,
|
|
3668
|
+
newState
|
|
3669
|
+
} = get(uid);
|
|
3670
|
+
const diffResult = diff(oldState, newState);
|
|
3671
|
+
return applyRender(oldState, newState, diffResult);
|
|
3672
|
+
};
|
|
3673
|
+
|
|
3674
|
+
const getPick = (items, index) => {
|
|
3675
|
+
array(items);
|
|
3676
|
+
number(index);
|
|
3677
|
+
// if (index < state.recentPicks.length) {
|
|
3678
|
+
// return state.recentPicks[index]
|
|
3679
|
+
// }
|
|
3680
|
+
// index -= state.recentPicks.length
|
|
3681
|
+
if (index < items.length) {
|
|
3682
|
+
return items[index].pick;
|
|
3683
|
+
}
|
|
3684
|
+
console.warn('no pick matching index', index);
|
|
3685
|
+
};
|
|
3686
|
+
|
|
3687
|
+
const selectIndex = async (state, index, button = /* left */0) => {
|
|
3688
|
+
const {
|
|
3689
|
+
minLineY,
|
|
3690
|
+
provider,
|
|
3691
|
+
items
|
|
3692
|
+
} = state;
|
|
3693
|
+
const actualIndex = index + minLineY;
|
|
3694
|
+
const pick = getPick(items, actualIndex);
|
|
3695
|
+
const selectPickResult = await provider.selectPick(pick, actualIndex, button);
|
|
3696
|
+
object(selectPickResult);
|
|
3697
|
+
string(selectPickResult.command);
|
|
3698
|
+
const {
|
|
3699
|
+
command
|
|
3700
|
+
} = selectPickResult;
|
|
3701
|
+
switch (command) {
|
|
3702
|
+
case Hide:
|
|
3703
|
+
await closeWidget(state.uid);
|
|
3704
|
+
return state;
|
|
3705
|
+
default:
|
|
3706
|
+
return state;
|
|
3707
|
+
}
|
|
3708
|
+
|
|
3709
|
+
// TODO recent picks should be per provider
|
|
3710
|
+
// if (!state.recentPickIds.has(pick.id)) {
|
|
3711
|
+
// state.recentPicks.unshift(pick)
|
|
3712
|
+
// state.recentPickIds.add(pick.id)
|
|
3713
|
+
// }
|
|
3714
|
+
// if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
|
|
3715
|
+
// const last = state.recentPicks.pop()
|
|
3716
|
+
// state.recentPickIds.delete(last.id)
|
|
3717
|
+
// }
|
|
3718
|
+
};
|
|
3719
|
+
|
|
3720
|
+
const selectCurrentIndex = state => {
|
|
3721
|
+
return selectIndex(state, state.focusedIndex);
|
|
3722
|
+
};
|
|
3723
|
+
|
|
3724
|
+
const findLabelIndex = (items, label) => {
|
|
3725
|
+
for (let i = 0; i < items.length; i++) {
|
|
3726
|
+
if (items[i].pick.label === label) {
|
|
3727
|
+
return i;
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
return -1;
|
|
3731
|
+
};
|
|
3732
|
+
|
|
3733
|
+
const selectItem = async (state, label) => {
|
|
3734
|
+
string(label);
|
|
3735
|
+
const index = findLabelIndex(state.items, label);
|
|
3736
|
+
if (index === -1) {
|
|
3737
|
+
return state;
|
|
3738
|
+
}
|
|
3739
|
+
return selectIndex(state, index);
|
|
3740
|
+
};
|
|
3741
|
+
|
|
3742
|
+
const wrapCommand = fn => {
|
|
3743
|
+
const wrapped = async (uid, ...args) => {
|
|
3744
|
+
const {
|
|
3745
|
+
newState
|
|
3746
|
+
} = get(uid);
|
|
3747
|
+
const newerState = await fn(newState, ...args);
|
|
3748
|
+
set(uid, newState, newerState);
|
|
3749
|
+
};
|
|
3750
|
+
return wrapped;
|
|
3751
|
+
};
|
|
3752
|
+
|
|
2989
3753
|
const commandMap = {
|
|
3754
|
+
'QuickPick.create2': create$1,
|
|
3755
|
+
'QuickPick.focusFirst': wrapCommand(focusFirst),
|
|
3756
|
+
'QuickPick.focusIndex': wrapCommand(focusIndex),
|
|
3757
|
+
'QuickPick.focusLast': wrapCommand(focusLast),
|
|
3758
|
+
'QuickPick.focusNext': wrapCommand(focusNext),
|
|
3759
|
+
'QuickPick.focusPrevious': wrapCommand(focusPrevious),
|
|
3760
|
+
'QuickPick.getCommandIds': getCommandIds,
|
|
3761
|
+
'QuickPick.getKeyBindings': getKeyBindings,
|
|
3762
|
+
'QuickPick.handleBeforeInput': wrapCommand(handleBeforeInput),
|
|
3763
|
+
'QuickPick.handleBlur': wrapCommand(handleBlur),
|
|
3764
|
+
'QuickPick.handleWheel': wrapCommand(handleWheel),
|
|
3765
|
+
'QuickPick.loadContent': wrapCommand(loadContent),
|
|
3766
|
+
'QuickPick.loadEntries2': load,
|
|
3767
|
+
'QuickPick.render': doRender,
|
|
3768
|
+
'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
|
|
3769
|
+
'QuickPick.selectIndex': wrapCommand(selectIndex),
|
|
3770
|
+
'QuickPick.selectItem': wrapCommand(selectItem),
|
|
3771
|
+
'QuickPick.setDeltaY': wrapCommand(setDeltaY),
|
|
3772
|
+
'SearchFile.filter': filterQuickPickItems,
|
|
3773
|
+
'SearchFile.searchFile': searchFile$1,
|
|
3774
|
+
'SearchFile.searchFileWithFetch': searchFile$4,
|
|
3775
|
+
'SearchFile.searchFileWithHtml': searchFile$3,
|
|
3776
|
+
'SearchFile.searchFileWithRipGrep': searchFile$2,
|
|
3777
|
+
// deprecated
|
|
3778
|
+
'QuickPick.create': create,
|
|
3779
|
+
'QuickPick.loadEntries': loadQuickPickEntries,
|
|
2990
3780
|
'FileSystemFetch.chmod': chmod,
|
|
2991
3781
|
'FileSystemFetch.getBlob': getBlob,
|
|
2992
3782
|
'FileSystemFetch.mkdir': mkdir,
|
|
@@ -3002,17 +3792,7 @@ const commandMap = {
|
|
|
3002
3792
|
'FileSystemMemory.readDirWithFileTypes': readDirWithFileTypes$1,
|
|
3003
3793
|
'FileSystemMemory.readFile': readFile$1,
|
|
3004
3794
|
'FileSystemMemory.remove': remove$1,
|
|
3005
|
-
'FileSystemMemory.writeFile': writeFile$1
|
|
3006
|
-
'QuickPick.create': create,
|
|
3007
|
-
'QuickPick.getKeyBindings': getKeyBindings,
|
|
3008
|
-
'QuickPick.loadContent': loadContent,
|
|
3009
|
-
'QuickPick.loadEntries': loadQuickPickEntries,
|
|
3010
|
-
'QuickPick.loadEntries2': load,
|
|
3011
|
-
'SearchFile.filter': filterQuickPickItems,
|
|
3012
|
-
'SearchFile.searchFile': searchFile,
|
|
3013
|
-
'SearchFile.searchFileWithFetch': searchFile$3,
|
|
3014
|
-
'SearchFile.searchFileWithHtml': searchFile$2,
|
|
3015
|
-
'SearchFile.searchFileWithRipGrep': searchFile$1
|
|
3795
|
+
'FileSystemMemory.writeFile': writeFile$1
|
|
3016
3796
|
};
|
|
3017
3797
|
|
|
3018
3798
|
const listen = async () => {
|