@lvce-editor/text-search-worker 3.27.0 → 3.29.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 +75 -60
- package/package.json +1 -1
|
@@ -1653,7 +1653,7 @@ const focusSearchValueNext = state => {
|
|
|
1653
1653
|
};
|
|
1654
1654
|
|
|
1655
1655
|
const CheckBox = 'checkbox';
|
|
1656
|
-
const None = 'none';
|
|
1656
|
+
const None$1 = 'none';
|
|
1657
1657
|
const Status = 'status';
|
|
1658
1658
|
const Tree = 'tree';
|
|
1659
1659
|
const TreeItem$1 = 'treeitem';
|
|
@@ -1732,7 +1732,7 @@ const getIconVirtualDom = (icon, type = Div) => {
|
|
|
1732
1732
|
return {
|
|
1733
1733
|
type,
|
|
1734
1734
|
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
1735
|
-
role: None,
|
|
1735
|
+
role: None$1,
|
|
1736
1736
|
childCount: 0
|
|
1737
1737
|
};
|
|
1738
1738
|
};
|
|
@@ -1880,6 +1880,20 @@ const getActions = () => {
|
|
|
1880
1880
|
}];
|
|
1881
1881
|
};
|
|
1882
1882
|
|
|
1883
|
+
const None = 0;
|
|
1884
|
+
const Collapsed = 1;
|
|
1885
|
+
const Expanded = 2;
|
|
1886
|
+
|
|
1887
|
+
const getMatchCount = (results, startIndex) => {
|
|
1888
|
+
for (let i = startIndex + 1; i < results.length; i++) {
|
|
1889
|
+
const result = results[i];
|
|
1890
|
+
if (result.type === File) {
|
|
1891
|
+
return i - startIndex - 1;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
return results.length - startIndex - 1;
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1883
1897
|
// TODO this should be in FileSystem module
|
|
1884
1898
|
const pathBaseName = path => {
|
|
1885
1899
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
@@ -1891,7 +1905,8 @@ const getAbsolutePath = relativePath => {
|
|
|
1891
1905
|
return `/${relativePath}`; // TODO support windows paths
|
|
1892
1906
|
};
|
|
1893
1907
|
|
|
1894
|
-
const getDisplayResult = (
|
|
1908
|
+
const getDisplayResult = (results, fileIcons, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY) => {
|
|
1909
|
+
const result = results[i];
|
|
1895
1910
|
const {
|
|
1896
1911
|
type,
|
|
1897
1912
|
text,
|
|
@@ -1901,16 +1916,17 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1901
1916
|
const posInSet = i + 1;
|
|
1902
1917
|
const top = i * itemHeight;
|
|
1903
1918
|
const focused = i === focusedIndex;
|
|
1919
|
+
const relativeIndex = i - minLineY;
|
|
1904
1920
|
switch (type) {
|
|
1905
1921
|
case File:
|
|
1906
1922
|
const path = text;
|
|
1907
1923
|
const absolutePath = getAbsolutePath(path);
|
|
1908
1924
|
const baseName = pathBaseName(path);
|
|
1925
|
+
const matchCount = getMatchCount(results, i);
|
|
1909
1926
|
return {
|
|
1910
1927
|
title: absolutePath,
|
|
1911
|
-
type: File,
|
|
1912
1928
|
text: baseName,
|
|
1913
|
-
icon: fileIcons[
|
|
1929
|
+
icon: fileIcons[relativeIndex],
|
|
1914
1930
|
posInSet,
|
|
1915
1931
|
setSize,
|
|
1916
1932
|
top,
|
|
@@ -1919,14 +1935,13 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1919
1935
|
matchLength: 0,
|
|
1920
1936
|
replacement: '',
|
|
1921
1937
|
depth: 0,
|
|
1922
|
-
matchCount
|
|
1938
|
+
matchCount,
|
|
1923
1939
|
focused,
|
|
1924
|
-
expanded:
|
|
1940
|
+
expanded: collapsedPaths.includes(path) ? Collapsed : Expanded
|
|
1925
1941
|
};
|
|
1926
1942
|
case Match:
|
|
1927
1943
|
return {
|
|
1928
1944
|
title: text,
|
|
1929
|
-
type: Match,
|
|
1930
1945
|
text: text,
|
|
1931
1946
|
icon: '',
|
|
1932
1947
|
posInSet,
|
|
@@ -1939,7 +1954,7 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1939
1954
|
depth: 1,
|
|
1940
1955
|
matchCount: 0,
|
|
1941
1956
|
focused,
|
|
1942
|
-
expanded:
|
|
1957
|
+
expanded: None
|
|
1943
1958
|
};
|
|
1944
1959
|
default:
|
|
1945
1960
|
throw new Error('unexpected search result type');
|
|
@@ -1950,20 +1965,9 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1950
1965
|
const displayResults = [];
|
|
1951
1966
|
const setSize = resultCount;
|
|
1952
1967
|
const searchTermLength = searchTerm.length;
|
|
1953
|
-
let fileResult = {
|
|
1954
|
-
matchCount: 0
|
|
1955
|
-
};
|
|
1956
|
-
let fileIconIndex = 0;
|
|
1957
1968
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1958
|
-
const
|
|
1959
|
-
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths);
|
|
1969
|
+
const displayResult = getDisplayResult(results, fileIcons, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY);
|
|
1960
1970
|
displayResults.push(displayResult);
|
|
1961
|
-
if (result.type === File) {
|
|
1962
|
-
fileResult = displayResult;
|
|
1963
|
-
fileIconIndex++;
|
|
1964
|
-
} else {
|
|
1965
|
-
fileResult.matchCount++;
|
|
1966
|
-
}
|
|
1967
1971
|
}
|
|
1968
1972
|
return displayResults;
|
|
1969
1973
|
};
|
|
@@ -2098,7 +2102,7 @@ const getOutSideButtonsDom = outsideButtons => {
|
|
|
2098
2102
|
preNodes: [{
|
|
2099
2103
|
type: Div,
|
|
2100
2104
|
className: SearchFieldContainer,
|
|
2101
|
-
role: None,
|
|
2105
|
+
role: None$1,
|
|
2102
2106
|
childCount: 1 + outsideButtons.length
|
|
2103
2107
|
}],
|
|
2104
2108
|
postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
|
|
@@ -2114,7 +2118,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
2114
2118
|
const dom = [...preNodes, {
|
|
2115
2119
|
type: Div,
|
|
2116
2120
|
className: searchFieldClassName,
|
|
2117
|
-
role: None,
|
|
2121
|
+
role: None$1,
|
|
2118
2122
|
childCount: 2
|
|
2119
2123
|
}, {
|
|
2120
2124
|
type: TextArea,
|
|
@@ -2230,12 +2234,12 @@ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage = '') => {
|
|
|
2230
2234
|
const dom = [{
|
|
2231
2235
|
type: Div,
|
|
2232
2236
|
className: SearchHeaderTop,
|
|
2233
|
-
role: None,
|
|
2237
|
+
role: None$1,
|
|
2234
2238
|
childCount: 2
|
|
2235
2239
|
}, ...getSearchToggleVirtualDom(flags), {
|
|
2236
2240
|
type: Div,
|
|
2237
2241
|
className: SearchHeaderTopRight,
|
|
2238
|
-
role: None,
|
|
2242
|
+
role: None$1,
|
|
2239
2243
|
childCount: flags & ReplaceExpanded ? 2 : 1
|
|
2240
2244
|
}, ...getSearchFieldVirtualDom(SearchValue, 'Search', HandleInput, inputActions.inside, inputActions.outside, '', Boolean(searchInputErrorMessage))];
|
|
2241
2245
|
if (flags & ReplaceExpanded) {
|
|
@@ -2248,7 +2252,7 @@ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage) => {
|
|
|
2248
2252
|
const dom = [{
|
|
2249
2253
|
type: Div,
|
|
2250
2254
|
className: SearchHeader,
|
|
2251
|
-
role: None,
|
|
2255
|
+
role: None$1,
|
|
2252
2256
|
childCount: 2,
|
|
2253
2257
|
onClick: HandleHeaderClick,
|
|
2254
2258
|
onFocusIn: HandleHeaderFocusIn
|
|
@@ -2268,6 +2272,19 @@ const getSearchInputErrorVirtualDom = errorMessage => {
|
|
|
2268
2272
|
}, text(errorMessage)];
|
|
2269
2273
|
};
|
|
2270
2274
|
|
|
2275
|
+
// TODO instead of setting string, support enum in virtual dom and send enum to renderer process
|
|
2276
|
+
// which converts it to a boolean
|
|
2277
|
+
const getAriaExpanded = expanded => {
|
|
2278
|
+
switch (expanded) {
|
|
2279
|
+
case Collapsed:
|
|
2280
|
+
return 'false';
|
|
2281
|
+
case Expanded:
|
|
2282
|
+
return 'true';
|
|
2283
|
+
default:
|
|
2284
|
+
return undefined;
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
|
|
2271
2288
|
const getBadgeVirtualDom = (className, count) => {
|
|
2272
2289
|
return [{
|
|
2273
2290
|
type: Div,
|
|
@@ -2292,7 +2309,7 @@ const getFileIconVirtualDom = icon => {
|
|
|
2292
2309
|
type: Img,
|
|
2293
2310
|
className: FileIcon,
|
|
2294
2311
|
src: icon,
|
|
2295
|
-
role: None,
|
|
2312
|
+
role: None$1,
|
|
2296
2313
|
childCount: 0
|
|
2297
2314
|
};
|
|
2298
2315
|
};
|
|
@@ -2338,11 +2355,21 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
2338
2355
|
return [label1, text(displayText)];
|
|
2339
2356
|
};
|
|
2340
2357
|
|
|
2358
|
+
const getPaddingLeft = depth => {
|
|
2359
|
+
return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
|
|
2360
|
+
};
|
|
2361
|
+
|
|
2362
|
+
const getSearchResultClassName = focused => {
|
|
2363
|
+
if (focused) {
|
|
2364
|
+
return TreeItem + ' ' + TreeItemActive;
|
|
2365
|
+
}
|
|
2366
|
+
return TreeItem;
|
|
2367
|
+
};
|
|
2368
|
+
|
|
2341
2369
|
const PaddingRight = '12px';
|
|
2342
2370
|
|
|
2343
2371
|
const getSearchResultVirtualDom = rowInfo => {
|
|
2344
2372
|
const {
|
|
2345
|
-
type,
|
|
2346
2373
|
matchStart,
|
|
2347
2374
|
matchLength,
|
|
2348
2375
|
text: displayText,
|
|
@@ -2359,7 +2386,7 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2359
2386
|
const treeItem = {
|
|
2360
2387
|
type: Div,
|
|
2361
2388
|
role: TreeItem$1,
|
|
2362
|
-
className:
|
|
2389
|
+
className: getSearchResultClassName(focused),
|
|
2363
2390
|
title,
|
|
2364
2391
|
ariaSetSize: setSize,
|
|
2365
2392
|
ariaLevel: depth,
|
|
@@ -2367,27 +2394,20 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2367
2394
|
ariaLabel: title,
|
|
2368
2395
|
ariaDescription: '',
|
|
2369
2396
|
childCount: 1,
|
|
2370
|
-
paddingLeft:
|
|
2371
|
-
|
|
2372
|
-
|
|
2397
|
+
paddingLeft: getPaddingLeft(depth),
|
|
2398
|
+
paddingRight: PaddingRight,
|
|
2399
|
+
ariaExpanded: getAriaExpanded(expanded)
|
|
2373
2400
|
};
|
|
2374
|
-
if (focused) {
|
|
2375
|
-
treeItem.className += ' ' + TreeItemActive;
|
|
2376
|
-
}
|
|
2377
|
-
switch (type) {
|
|
2378
|
-
case File:
|
|
2379
|
-
treeItem.ariaExpanded = `${expanded}`;
|
|
2380
|
-
break;
|
|
2381
|
-
}
|
|
2382
2401
|
const dom = [];
|
|
2383
2402
|
dom.push(treeItem);
|
|
2384
|
-
if (
|
|
2403
|
+
if (expanded === Expanded) {
|
|
2404
|
+
// TODO move childcount computation to getDisplaySearchresults
|
|
2405
|
+
// TODO add chevronIcon and fileIcon properties to getDisplaySearchResults
|
|
2385
2406
|
treeItem.childCount += 2;
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
}
|
|
2407
|
+
dom.push(chevronDownVirtualDom, getFileIconVirtualDom(icon));
|
|
2408
|
+
} else if (expanded === Collapsed) {
|
|
2409
|
+
treeItem.childCount += 2;
|
|
2410
|
+
dom.push(chevronRightVirtualDom, getFileIconVirtualDom(icon));
|
|
2391
2411
|
}
|
|
2392
2412
|
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
2393
2413
|
if (matchCount) {
|
|
@@ -2433,22 +2453,17 @@ const handleError = error => {
|
|
|
2433
2453
|
console.error(`[text-search-worker] ${error}`);
|
|
2434
2454
|
};
|
|
2435
2455
|
|
|
2436
|
-
const
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
}
|
|
2442
|
-
|
|
2443
|
-
const getFileIcon = file => {
|
|
2444
|
-
return invoke$2('IconTheme.getFileIcon', {
|
|
2445
|
-
name: file.text
|
|
2446
|
-
});
|
|
2456
|
+
const getFileIcon = async result => {
|
|
2457
|
+
if (result.type === File) {
|
|
2458
|
+
return invoke$2('IconTheme.getFileIcon', {
|
|
2459
|
+
name: result.text
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
return '';
|
|
2447
2463
|
};
|
|
2448
2464
|
const getFileIcons = async matches => {
|
|
2449
2465
|
// TODO cache file icons
|
|
2450
|
-
const
|
|
2451
|
-
const promises = files.map(getFileIcon);
|
|
2466
|
+
const promises = matches.map(getFileIcon);
|
|
2452
2467
|
const icons = await Promise.all(promises);
|
|
2453
2468
|
return icons;
|
|
2454
2469
|
};
|
|
@@ -3271,7 +3286,7 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
3271
3286
|
isExcluded = false;
|
|
3272
3287
|
}
|
|
3273
3288
|
}
|
|
3274
|
-
if (!isExcluded) {
|
|
3289
|
+
if (result.type === Match && !isExcluded) {
|
|
3275
3290
|
filteredResults.push(result);
|
|
3276
3291
|
}
|
|
3277
3292
|
}
|