@lvce-editor/text-search-worker 3.28.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 +43 -44
- package/package.json +1 -1
|
@@ -1884,6 +1884,16 @@ const None = 0;
|
|
|
1884
1884
|
const Collapsed = 1;
|
|
1885
1885
|
const Expanded = 2;
|
|
1886
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
|
+
|
|
1887
1897
|
// TODO this should be in FileSystem module
|
|
1888
1898
|
const pathBaseName = path => {
|
|
1889
1899
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
@@ -1895,7 +1905,8 @@ const getAbsolutePath = relativePath => {
|
|
|
1895
1905
|
return `/${relativePath}`; // TODO support windows paths
|
|
1896
1906
|
};
|
|
1897
1907
|
|
|
1898
|
-
const getDisplayResult = (
|
|
1908
|
+
const getDisplayResult = (results, fileIcons, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY) => {
|
|
1909
|
+
const result = results[i];
|
|
1899
1910
|
const {
|
|
1900
1911
|
type,
|
|
1901
1912
|
text,
|
|
@@ -1905,15 +1916,17 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1905
1916
|
const posInSet = i + 1;
|
|
1906
1917
|
const top = i * itemHeight;
|
|
1907
1918
|
const focused = i === focusedIndex;
|
|
1919
|
+
const relativeIndex = i - minLineY;
|
|
1908
1920
|
switch (type) {
|
|
1909
1921
|
case File:
|
|
1910
1922
|
const path = text;
|
|
1911
1923
|
const absolutePath = getAbsolutePath(path);
|
|
1912
1924
|
const baseName = pathBaseName(path);
|
|
1925
|
+
const matchCount = getMatchCount(results, i);
|
|
1913
1926
|
return {
|
|
1914
1927
|
title: absolutePath,
|
|
1915
1928
|
text: baseName,
|
|
1916
|
-
icon: fileIcons[
|
|
1929
|
+
icon: fileIcons[relativeIndex],
|
|
1917
1930
|
posInSet,
|
|
1918
1931
|
setSize,
|
|
1919
1932
|
top,
|
|
@@ -1922,7 +1935,7 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
|
|
|
1922
1935
|
matchLength: 0,
|
|
1923
1936
|
replacement: '',
|
|
1924
1937
|
depth: 0,
|
|
1925
|
-
matchCount
|
|
1938
|
+
matchCount,
|
|
1926
1939
|
focused,
|
|
1927
1940
|
expanded: collapsedPaths.includes(path) ? Collapsed : Expanded
|
|
1928
1941
|
};
|
|
@@ -1952,20 +1965,9 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1952
1965
|
const displayResults = [];
|
|
1953
1966
|
const setSize = resultCount;
|
|
1954
1967
|
const searchTermLength = searchTerm.length;
|
|
1955
|
-
let fileResult = {
|
|
1956
|
-
matchCount: 0
|
|
1957
|
-
};
|
|
1958
|
-
let fileIconIndex = 0;
|
|
1959
1968
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1960
|
-
const
|
|
1961
|
-
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);
|
|
1962
1970
|
displayResults.push(displayResult);
|
|
1963
|
-
if (result.type === File) {
|
|
1964
|
-
fileResult = displayResult;
|
|
1965
|
-
fileIconIndex++;
|
|
1966
|
-
} else {
|
|
1967
|
-
fileResult.matchCount++;
|
|
1968
|
-
}
|
|
1969
1971
|
}
|
|
1970
1972
|
return displayResults;
|
|
1971
1973
|
};
|
|
@@ -2270,6 +2272,19 @@ const getSearchInputErrorVirtualDom = errorMessage => {
|
|
|
2270
2272
|
}, text(errorMessage)];
|
|
2271
2273
|
};
|
|
2272
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
|
+
|
|
2273
2288
|
const getBadgeVirtualDom = (className, count) => {
|
|
2274
2289
|
return [{
|
|
2275
2290
|
type: Div,
|
|
@@ -2340,30 +2355,19 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
2340
2355
|
return [label1, text(displayText)];
|
|
2341
2356
|
};
|
|
2342
2357
|
|
|
2343
|
-
const PaddingRight = '12px';
|
|
2344
|
-
|
|
2345
2358
|
const getPaddingLeft = depth => {
|
|
2346
2359
|
return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
|
|
2347
2360
|
};
|
|
2348
|
-
|
|
2361
|
+
|
|
2362
|
+
const getSearchResultClassName = focused => {
|
|
2349
2363
|
if (focused) {
|
|
2350
2364
|
return TreeItem + ' ' + TreeItemActive;
|
|
2351
2365
|
}
|
|
2352
2366
|
return TreeItem;
|
|
2353
2367
|
};
|
|
2354
2368
|
|
|
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
|
-
};
|
|
2369
|
+
const PaddingRight = '12px';
|
|
2370
|
+
|
|
2367
2371
|
const getSearchResultVirtualDom = rowInfo => {
|
|
2368
2372
|
const {
|
|
2369
2373
|
matchStart,
|
|
@@ -2382,7 +2386,7 @@ const getSearchResultVirtualDom = rowInfo => {
|
|
|
2382
2386
|
const treeItem = {
|
|
2383
2387
|
type: Div,
|
|
2384
2388
|
role: TreeItem$1,
|
|
2385
|
-
className:
|
|
2389
|
+
className: getSearchResultClassName(focused),
|
|
2386
2390
|
title,
|
|
2387
2391
|
ariaSetSize: setSize,
|
|
2388
2392
|
ariaLevel: depth,
|
|
@@ -2449,22 +2453,17 @@ const handleError = error => {
|
|
|
2449
2453
|
console.error(`[text-search-worker] ${error}`);
|
|
2450
2454
|
};
|
|
2451
2455
|
|
|
2452
|
-
const
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
const getFileIcon = file => {
|
|
2460
|
-
return invoke$2('IconTheme.getFileIcon', {
|
|
2461
|
-
name: file.text
|
|
2462
|
-
});
|
|
2456
|
+
const getFileIcon = async result => {
|
|
2457
|
+
if (result.type === File) {
|
|
2458
|
+
return invoke$2('IconTheme.getFileIcon', {
|
|
2459
|
+
name: result.text
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
return '';
|
|
2463
2463
|
};
|
|
2464
2464
|
const getFileIcons = async matches => {
|
|
2465
2465
|
// TODO cache file icons
|
|
2466
|
-
const
|
|
2467
|
-
const promises = files.map(getFileIcon);
|
|
2466
|
+
const promises = matches.map(getFileIcon);
|
|
2468
2467
|
const icons = await Promise.all(promises);
|
|
2469
2468
|
return icons;
|
|
2470
2469
|
};
|