@lvce-editor/text-search-worker 2.6.0 → 2.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/textSearchWorkerMain.js +35 -12
- package/package.json +1 -1
|
@@ -503,7 +503,14 @@ const create = (uid, x, y, width, height, workspacePath) => {
|
|
|
503
503
|
focus: Empty$1,
|
|
504
504
|
loaded: false,
|
|
505
505
|
message: '',
|
|
506
|
-
collapsedPaths: []
|
|
506
|
+
collapsedPaths: [],
|
|
507
|
+
icons: [],
|
|
508
|
+
assetDir: '',
|
|
509
|
+
deltaY: 0,
|
|
510
|
+
finalDeltaY: 0,
|
|
511
|
+
focused: false,
|
|
512
|
+
focusedIndex: -1,
|
|
513
|
+
handleOffset: 0
|
|
507
514
|
};
|
|
508
515
|
set(uid, state, state);
|
|
509
516
|
};
|
|
@@ -961,10 +968,6 @@ const getActions = () => {
|
|
|
961
968
|
}];
|
|
962
969
|
};
|
|
963
970
|
|
|
964
|
-
const getFileIcon = () => {
|
|
965
|
-
return '';
|
|
966
|
-
};
|
|
967
|
-
|
|
968
971
|
// TODO this should be in FileSystem module
|
|
969
972
|
const pathBaseName = path => {
|
|
970
973
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
@@ -976,7 +979,7 @@ const getAbsolutePath = relativePath => {
|
|
|
976
979
|
return `/${relativePath}`; // TODO support windows paths
|
|
977
980
|
};
|
|
978
981
|
|
|
979
|
-
const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
982
|
+
const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
980
983
|
const {
|
|
981
984
|
type,
|
|
982
985
|
text,
|
|
@@ -995,7 +998,7 @@ const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, repl
|
|
|
995
998
|
title: absolutePath,
|
|
996
999
|
type: File$1,
|
|
997
1000
|
text: baseName,
|
|
998
|
-
icon:
|
|
1001
|
+
icon: fileIcons[fileIconIndex],
|
|
999
1002
|
posInSet,
|
|
1000
1003
|
setSize,
|
|
1001
1004
|
top,
|
|
@@ -1046,7 +1049,7 @@ const getFilteredResults = (results, collapsedPaths) => {
|
|
|
1046
1049
|
}
|
|
1047
1050
|
return filteredResults;
|
|
1048
1051
|
};
|
|
1049
|
-
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
|
|
1052
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, fileIcons, focusedIndex) => {
|
|
1050
1053
|
const displayResults = [];
|
|
1051
1054
|
const filteredResults = getFilteredResults(results, collapsedPaths);
|
|
1052
1055
|
const setSize = resultCount;
|
|
@@ -1054,12 +1057,14 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
|
|
|
1054
1057
|
let fileResult = {
|
|
1055
1058
|
matchCount: 0
|
|
1056
1059
|
};
|
|
1060
|
+
let fileIconIndex = 0;
|
|
1057
1061
|
for (let i = minLineY; i < maxLineY; i++) {
|
|
1058
1062
|
const result = filteredResults[i];
|
|
1059
|
-
const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1063
|
+
const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1060
1064
|
displayResults.push(displayResult);
|
|
1061
1065
|
if (result.type === File$1) {
|
|
1062
1066
|
fileResult = displayResult;
|
|
1067
|
+
fileIconIndex++;
|
|
1063
1068
|
} else {
|
|
1064
1069
|
fileResult.matchCount++;
|
|
1065
1070
|
}
|
|
@@ -1393,6 +1398,21 @@ const handleError = async (error, notify = true, prefix = '') => {
|
|
|
1393
1398
|
console.error(`[text-search-worker] ${error}`);
|
|
1394
1399
|
};
|
|
1395
1400
|
|
|
1401
|
+
const getFileIcons = async files => {
|
|
1402
|
+
// TODO cache file icons
|
|
1403
|
+
const promises = [];
|
|
1404
|
+
for (const file of files) {
|
|
1405
|
+
if (file.type === Match) {
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
promises.push(invoke$1('IconTheme.getFileIcon', {
|
|
1409
|
+
name: file.text
|
|
1410
|
+
}));
|
|
1411
|
+
}
|
|
1412
|
+
const icons = await Promise.all(promises);
|
|
1413
|
+
return icons;
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1396
1416
|
// TODO optimize this function to return the minimum number
|
|
1397
1417
|
// of visible items needed, e.g. when not scrolled 5 items with
|
|
1398
1418
|
// 20px fill 100px but when scrolled 6 items are needed
|
|
@@ -2145,6 +2165,8 @@ const handleUpdate = async (state, update) => {
|
|
|
2145
2165
|
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2146
2166
|
const maxLineY = Math.min(numberOfVisible, total);
|
|
2147
2167
|
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2168
|
+
const visible = results.slice(0, maxLineY);
|
|
2169
|
+
const icons = await getFileIcons(visible);
|
|
2148
2170
|
return {
|
|
2149
2171
|
...partialNewState,
|
|
2150
2172
|
minLineY: 0,
|
|
@@ -2158,7 +2180,8 @@ const handleUpdate = async (state, update) => {
|
|
|
2158
2180
|
threads,
|
|
2159
2181
|
fileCount,
|
|
2160
2182
|
matchCount: resultCount,
|
|
2161
|
-
loaded: true
|
|
2183
|
+
loaded: true,
|
|
2184
|
+
icons
|
|
2162
2185
|
};
|
|
2163
2186
|
} catch (error) {
|
|
2164
2187
|
handleError(error);
|
|
@@ -2561,7 +2584,7 @@ const renderItems = {
|
|
|
2561
2584
|
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCase === newState.matchCase && oldState.matchWholeWord === newState.matchWholeWord && oldState.useRegularExpression === newState.useRegularExpression && oldState.message === newState.message && oldState.detailsExpanded === newState.detailsExpanded && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused;
|
|
2562
2585
|
},
|
|
2563
2586
|
apply(oldState, newState) {
|
|
2564
|
-
const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.focusedIndex);
|
|
2587
|
+
const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.icons, newState.focusedIndex);
|
|
2565
2588
|
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
2566
2589
|
const dom = getSearchVirtualDom(displayResults, newState.replaceExpanded, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.message, newState.detailsExpanded, focusOutline);
|
|
2567
2590
|
return ['Viewlet.setDom2', newState.uid, dom];
|
|
@@ -2589,7 +2612,7 @@ const renderFocus = {
|
|
|
2589
2612
|
},
|
|
2590
2613
|
apply(newState) {
|
|
2591
2614
|
const selector = getSelector(newState.focus);
|
|
2592
|
-
return ['setFocus', selector];
|
|
2615
|
+
return ['Viewlet.send', newState.uid, 'setFocus', selector];
|
|
2593
2616
|
}
|
|
2594
2617
|
};
|
|
2595
2618
|
const render = [renderItems, renderFocus];
|