@lvce-editor/text-search-worker 3.28.0 → 3.30.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/textSearchWorkerMain.js +77 -54
- package/package.json +1 -1
|
@@ -1670,13 +1670,16 @@ const FileIcon = 'FileIcon';
|
|
|
1670
1670
|
const FocusOutline = 'FocusOutline';
|
|
1671
1671
|
const Grow = 'Grow';
|
|
1672
1672
|
const Highlight = 'Highlight';
|
|
1673
|
+
const ScrollBarThumb = 'ScrollBarThumb';
|
|
1673
1674
|
const HighlightDeleted = 'HighlightDeleted';
|
|
1675
|
+
const ScrollBar = 'ScrollBar';
|
|
1674
1676
|
const HighlightInserted = 'HighlightInserted';
|
|
1675
1677
|
const IconButton = 'IconButton';
|
|
1676
1678
|
const Label = 'Label';
|
|
1677
1679
|
const List = 'List';
|
|
1678
1680
|
const MaskIcon = 'MaskIcon';
|
|
1679
1681
|
const MaskIconBook = 'MaskIconBook';
|
|
1682
|
+
const ScrollBarVertical = 'ScrollBarVertical';
|
|
1680
1683
|
const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
|
|
1681
1684
|
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
1682
1685
|
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
@@ -1884,6 +1887,16 @@ const None = 0;
|
|
|
1884
1887
|
const Collapsed = 1;
|
|
1885
1888
|
const Expanded = 2;
|
|
1886
1889
|
|
|
1890
|
+
const getMatchCount = (results, startIndex) => {
|
|
1891
|
+
for (let i = startIndex + 1; i < results.length; i++) {
|
|
1892
|
+
const result = results[i];
|
|
1893
|
+
if (result.type === File) {
|
|
1894
|
+
return i - startIndex - 1;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
return results.length - startIndex - 1;
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1887
1900
|
// TODO this should be in FileSystem module
|
|
1888
1901
|
const pathBaseName = path => {
|
|
1889
1902
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
@@ -1895,7 +1908,8 @@ const getAbsolutePath = relativePath => {
|
|
|
1895
1908
|
return `/${relativePath}`; // TODO support windows paths
|
|
1896
1909
|
};
|
|
1897
1910
|
|
|
1898
|
-
const getDisplayResult = (
|
|
1911
|
+
const getDisplayResult = (results, fileIcons, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY) => {
|
|
1912
|
+
const result = results[i];
|
|
1899
1913
|
const {
|
|
1900
1914
|
type,
|
|
1901
1915
|
text,
|
|
@@ -1905,15 +1919,17 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1905
1919
|
const posInSet = i + 1;
|
|
1906
1920
|
const top = i * itemHeight;
|
|
1907
1921
|
const focused = i === focusedIndex;
|
|
1922
|
+
const relativeIndex = i - minLineY;
|
|
1908
1923
|
switch (type) {
|
|
1909
1924
|
case File:
|
|
1910
1925
|
const path = text;
|
|
1911
1926
|
const absolutePath = getAbsolutePath(path);
|
|
1912
1927
|
const baseName = pathBaseName(path);
|
|
1928
|
+
const matchCount = getMatchCount(results, i);
|
|
1913
1929
|
return {
|
|
1914
1930
|
title: absolutePath,
|
|
1915
1931
|
text: baseName,
|
|
1916
|
-
icon: fileIcons[
|
|
1932
|
+
icon: fileIcons[relativeIndex],
|
|
1917
1933
|
posInSet,
|
|
1918
1934
|
setSize,
|
|
1919
1935
|
top,
|
|
@@ -1922,7 +1938,7 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1922
1938
|
matchLength: 0,
|
|
1923
1939
|
replacement: '',
|
|
1924
1940
|
depth: 0,
|
|
1925
|
-
matchCount
|
|
1941
|
+
matchCount,
|
|
1926
1942
|
focused,
|
|
1927
1943
|
expanded: collapsedPaths.includes(path) ? Collapsed : Expanded
|
|
1928
1944
|
};
|
|
@@ -1952,32 +1968,22 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1952
1968
|
const displayResults = [];
|
|
1953
1969
|
const setSize = resultCount;
|
|
1954
1970
|
const searchTermLength = searchTerm.length;
|
|
1955
|
-
let fileResult = {
|
|
1956
|
-
matchCount: 0
|
|
1957
|
-
};
|
|
1958
|
-
let fileIconIndex = 0;
|
|
1959
1971
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1960
|
-
const
|
|
1961
|
-
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths);
|
|
1972
|
+
const displayResult = getDisplayResult(results, fileIcons, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY);
|
|
1962
1973
|
displayResults.push(displayResult);
|
|
1963
|
-
if (result.type === File) {
|
|
1964
|
-
fileResult = displayResult;
|
|
1965
|
-
fileIconIndex++;
|
|
1966
|
-
} else {
|
|
1967
|
-
fileResult.matchCount++;
|
|
1968
|
-
}
|
|
1969
1974
|
}
|
|
1970
1975
|
return displayResults;
|
|
1971
1976
|
};
|
|
1972
1977
|
|
|
1973
1978
|
const HandleClick = 'handleClick';
|
|
1979
|
+
const HandleExcludeInput = 'handleExcludeInput';
|
|
1974
1980
|
const HandleHeaderClick = 'handleHeaderClick';
|
|
1975
1981
|
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
1976
|
-
const
|
|
1982
|
+
const HandleIncludeInput = 'handleIncludeInput';
|
|
1977
1983
|
const HandleInput = 'handleInput';
|
|
1984
|
+
const HandleListBlur = 'handleListBlur';
|
|
1978
1985
|
const HandleReplaceInput = 'handleReplaceInput';
|
|
1979
|
-
const
|
|
1980
|
-
const HandleExcludeInput = 'handleExcludeInput';
|
|
1986
|
+
const HandleWheel = 'handleWheel';
|
|
1981
1987
|
|
|
1982
1988
|
const FilesToExclude = 'FilesToExclude';
|
|
1983
1989
|
const FilesToInclude = 'FilesToInclude';
|
|
@@ -2270,6 +2276,36 @@ const getSearchInputErrorVirtualDom = errorMessage => {
|
|
|
2270
2276
|
}, text(errorMessage)];
|
|
2271
2277
|
};
|
|
2272
2278
|
|
|
2279
|
+
const getScrollBarVirtualDom = (scrollBarHeight, scrollBarY) => {
|
|
2280
|
+
if (scrollBarHeight === 0) {
|
|
2281
|
+
return [];
|
|
2282
|
+
}
|
|
2283
|
+
return [{
|
|
2284
|
+
type: Div,
|
|
2285
|
+
className: mergeClassNames(ScrollBar, ScrollBarVertical),
|
|
2286
|
+
childCount: 1
|
|
2287
|
+
}, {
|
|
2288
|
+
type: Div,
|
|
2289
|
+
className: ScrollBarThumb,
|
|
2290
|
+
height: scrollBarHeight,
|
|
2291
|
+
translate: `0 ${scrollBarY}px`,
|
|
2292
|
+
childCount: 0
|
|
2293
|
+
}];
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2296
|
+
// TODO instead of setting string, support enum in virtual dom and send enum to renderer process
|
|
2297
|
+
// which converts it to a boolean
|
|
2298
|
+
const getAriaExpanded = expanded => {
|
|
2299
|
+
switch (expanded) {
|
|
2300
|
+
case Collapsed:
|
|
2301
|
+
return 'false';
|
|
2302
|
+
case Expanded:
|
|
2303
|
+
return 'true';
|
|
2304
|
+
default:
|
|
2305
|
+
return undefined;
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
|
|
2273
2309
|
const getBadgeVirtualDom = (className, count) => {
|
|
2274
2310
|
return [{
|
|
2275
2311
|
type: Div,
|
|
@@ -2340,30 +2376,19 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
2340
2376
|
return [label1, text(displayText)];
|
|
2341
2377
|
};
|
|
2342
2378
|
|
|
2343
|
-
const PaddingRight = '12px';
|
|
2344
|
-
|
|
2345
2379
|
const getPaddingLeft = depth => {
|
|
2346
2380
|
return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
|
|
2347
2381
|
};
|
|
2348
|
-
|
|
2382
|
+
|
|
2383
|
+
const getSearchResultClassName = focused => {
|
|
2349
2384
|
if (focused) {
|
|
2350
2385
|
return TreeItem + ' ' + TreeItemActive;
|
|
2351
2386
|
}
|
|
2352
2387
|
return TreeItem;
|
|
2353
2388
|
};
|
|
2354
2389
|
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
const getAriaExpanded = expanded => {
|
|
2358
|
-
switch (expanded) {
|
|
2359
|
-
case Collapsed:
|
|
2360
|
-
return 'false';
|
|
2361
|
-
case Expanded:
|
|
2362
|
-
return 'true';
|
|
2363
|
-
default:
|
|
2364
|
-
return undefined;
|
|
2365
|
-
}
|
|
2366
|
-
};
|
|
2390
|
+
const PaddingRight = '12px';
|
|
2391
|
+
|
|
2367
2392
|
const getSearchResultVirtualDom = rowInfo => {
|
|
2368
2393
|
const {
|
|
2369
2394
|
matchStart,
|
|
@@ -2382,7 +2407,7 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2382
2407
|
const treeItem = {
|
|
2383
2408
|
type: Div,
|
|
2384
2409
|
role: TreeItem$1,
|
|
2385
|
-
className:
|
|
2410
|
+
className: getSearchResultClassName(focused),
|
|
2386
2411
|
title,
|
|
2387
2412
|
ariaSetSize: setSize,
|
|
2388
2413
|
ariaLevel: depth,
|
|
@@ -2423,48 +2448,45 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2423
2448
|
return dom;
|
|
2424
2449
|
};
|
|
2425
2450
|
|
|
2426
|
-
const getSearchResultsVirtualDom = (visibleItems, focusOutline) => {
|
|
2451
|
+
const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight, scrollBarY) => {
|
|
2452
|
+
const scrollBarDomNodes = scrollbarHeight === 0 ? 0 : 1;
|
|
2427
2453
|
return [{
|
|
2428
2454
|
type: Div,
|
|
2429
2455
|
className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
|
|
2430
2456
|
role: Tree,
|
|
2431
2457
|
tabIndex: 0,
|
|
2432
|
-
childCount: visibleItems.length,
|
|
2458
|
+
childCount: visibleItems.length + scrollBarDomNodes,
|
|
2433
2459
|
onClick: HandleClick,
|
|
2434
|
-
onBlur: HandleListBlur
|
|
2435
|
-
|
|
2460
|
+
onBlur: HandleListBlur,
|
|
2461
|
+
onWheel: HandleWheel
|
|
2462
|
+
}, ...visibleItems.flatMap(getSearchResultVirtualDom), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY)];
|
|
2436
2463
|
};
|
|
2437
2464
|
|
|
2438
|
-
const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage) => {
|
|
2465
|
+
const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY) => {
|
|
2439
2466
|
const errorDom = getSearchInputErrorVirtualDom(searchInputErrorMessage);
|
|
2440
2467
|
const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
|
|
2441
2468
|
return [{
|
|
2442
2469
|
type: Div,
|
|
2443
2470
|
className: mergeClassNames(Viewlet, Search$1),
|
|
2444
2471
|
childCount
|
|
2445
|
-
}, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline)];
|
|
2472
|
+
}, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY)];
|
|
2446
2473
|
};
|
|
2447
2474
|
|
|
2448
2475
|
const handleError = error => {
|
|
2449
2476
|
console.error(`[text-search-worker] ${error}`);
|
|
2450
2477
|
};
|
|
2451
2478
|
|
|
2452
|
-
const
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
const getFileIcon = file => {
|
|
2460
|
-
return invoke$2('IconTheme.getFileIcon', {
|
|
2461
|
-
name: file.text
|
|
2462
|
-
});
|
|
2479
|
+
const getFileIcon = async result => {
|
|
2480
|
+
if (result.type === File) {
|
|
2481
|
+
return invoke$2('IconTheme.getFileIcon', {
|
|
2482
|
+
name: result.text
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
return '';
|
|
2463
2486
|
};
|
|
2464
2487
|
const getFileIcons = async matches => {
|
|
2465
2488
|
// TODO cache file icons
|
|
2466
|
-
const
|
|
2467
|
-
const promises = files.map(getFileIcon);
|
|
2489
|
+
const promises = matches.map(getFileIcon);
|
|
2468
2490
|
const icons = await Promise.all(promises);
|
|
2469
2491
|
return icons;
|
|
2470
2492
|
};
|
|
@@ -3619,7 +3641,8 @@ const renderItems = {
|
|
|
3619
3641
|
apply(oldState, newState) {
|
|
3620
3642
|
const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex, newState.collapsedPaths);
|
|
3621
3643
|
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
3622
|
-
const
|
|
3644
|
+
const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, newState.scrollBarHeight);
|
|
3645
|
+
const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage, newState.scrollBarHeight, scrollBarY);
|
|
3623
3646
|
return ['Viewlet.setDom2', newState.uid, dom];
|
|
3624
3647
|
}
|
|
3625
3648
|
};
|