@lvce-editor/text-search-worker 2.1.0 → 2.2.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 +116 -15
- package/package.json +1 -1
|
@@ -275,6 +275,115 @@ const getActions = () => {
|
|
|
275
275
|
}];
|
|
276
276
|
};
|
|
277
277
|
|
|
278
|
+
const getFileIcon = () => {
|
|
279
|
+
return '';
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const File$1 = 1;
|
|
283
|
+
const Match = 2;
|
|
284
|
+
|
|
285
|
+
// TODO this should be in FileSystem module
|
|
286
|
+
const pathBaseName = path => {
|
|
287
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
288
|
+
};
|
|
289
|
+
const getAbsolutePath = relativePath => {
|
|
290
|
+
if (relativePath.startsWith('./')) {
|
|
291
|
+
return `/${relativePath.slice(2)}`; // TODO support windows paths
|
|
292
|
+
}
|
|
293
|
+
return `/${relativePath}`; // TODO support windows paths
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
297
|
+
const {
|
|
298
|
+
type,
|
|
299
|
+
text,
|
|
300
|
+
lineNumber,
|
|
301
|
+
start
|
|
302
|
+
} = result;
|
|
303
|
+
const posInSet = i + 1;
|
|
304
|
+
const top = i * itemHeight;
|
|
305
|
+
const focused = i === focusedIndex;
|
|
306
|
+
switch (type) {
|
|
307
|
+
case File$1:
|
|
308
|
+
const path = text;
|
|
309
|
+
const absolutePath = getAbsolutePath(path);
|
|
310
|
+
const baseName = pathBaseName(path);
|
|
311
|
+
return {
|
|
312
|
+
title: absolutePath,
|
|
313
|
+
type: File$1,
|
|
314
|
+
text: baseName,
|
|
315
|
+
icon: getFileIcon(),
|
|
316
|
+
posInSet,
|
|
317
|
+
setSize,
|
|
318
|
+
top,
|
|
319
|
+
lineNumber,
|
|
320
|
+
matchStart: 0,
|
|
321
|
+
matchLength: 0,
|
|
322
|
+
replacement: '',
|
|
323
|
+
depth: 0,
|
|
324
|
+
matchCount: 0,
|
|
325
|
+
focused
|
|
326
|
+
};
|
|
327
|
+
case Match:
|
|
328
|
+
return {
|
|
329
|
+
title: text,
|
|
330
|
+
type: Match,
|
|
331
|
+
text: text,
|
|
332
|
+
icon: '',
|
|
333
|
+
posInSet,
|
|
334
|
+
setSize,
|
|
335
|
+
top,
|
|
336
|
+
lineNumber,
|
|
337
|
+
matchStart: start,
|
|
338
|
+
matchLength: searchTermLength,
|
|
339
|
+
replacement,
|
|
340
|
+
depth: 1,
|
|
341
|
+
matchCount: 0,
|
|
342
|
+
focused
|
|
343
|
+
};
|
|
344
|
+
default:
|
|
345
|
+
throw new Error('unexpected search result type');
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const getFilteredResults = (results, collapsedPaths) => {
|
|
350
|
+
const filteredResults = [];
|
|
351
|
+
let isExcluded = false;
|
|
352
|
+
for (const result of results) {
|
|
353
|
+
if (result.type === File$1) {
|
|
354
|
+
if (collapsedPaths.includes(result.text)) {
|
|
355
|
+
isExcluded = true;
|
|
356
|
+
} else {
|
|
357
|
+
isExcluded = false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (!isExcluded) {
|
|
361
|
+
filteredResults.push(result);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return filteredResults;
|
|
365
|
+
};
|
|
366
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
|
|
367
|
+
const displayResults = [];
|
|
368
|
+
const filteredResults = getFilteredResults(results, collapsedPaths);
|
|
369
|
+
const setSize = resultCount;
|
|
370
|
+
const searchTermLength = searchTerm.length;
|
|
371
|
+
let fileResult = {
|
|
372
|
+
matchCount: 0
|
|
373
|
+
};
|
|
374
|
+
for (let i = minLineY; i < maxLineY; i++) {
|
|
375
|
+
const result = filteredResults[i];
|
|
376
|
+
const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
377
|
+
displayResults.push(displayResult);
|
|
378
|
+
if (result.type === File$1) {
|
|
379
|
+
fileResult = displayResult;
|
|
380
|
+
} else {
|
|
381
|
+
fileResult.matchCount++;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return displayResults;
|
|
385
|
+
};
|
|
386
|
+
|
|
278
387
|
const HandleClick = 'handleClick';
|
|
279
388
|
const HandleHeaderClick = 'handleHeaderClick';
|
|
280
389
|
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
@@ -443,11 +552,6 @@ const getFileIconVirtualDom = icon => {
|
|
|
443
552
|
};
|
|
444
553
|
};
|
|
445
554
|
|
|
446
|
-
const File$1 = 1;
|
|
447
|
-
const Match = 2;
|
|
448
|
-
|
|
449
|
-
const PaddingRight = '12px';
|
|
450
|
-
|
|
451
555
|
const deleted = {
|
|
452
556
|
type: Del,
|
|
453
557
|
className: HighlightDeleted,
|
|
@@ -487,10 +591,11 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
487
591
|
}
|
|
488
592
|
return dom;
|
|
489
593
|
};
|
|
490
|
-
|
|
491
|
-
|
|
594
|
+
|
|
595
|
+
const PaddingRight = '12px';
|
|
596
|
+
|
|
597
|
+
const getSearchResultVirtualDom = rowInfo => {
|
|
492
598
|
const {
|
|
493
|
-
top,
|
|
494
599
|
type,
|
|
495
600
|
matchStart,
|
|
496
601
|
matchLength,
|
|
@@ -550,8 +655,9 @@ const renderRow = rowInfo => {
|
|
|
550
655
|
});
|
|
551
656
|
return dom;
|
|
552
657
|
};
|
|
658
|
+
|
|
553
659
|
const getSearchResultsVirtualDom = visibleItems => {
|
|
554
|
-
return visibleItems.flatMap(
|
|
660
|
+
return visibleItems.flatMap(getSearchResultVirtualDom);
|
|
555
661
|
};
|
|
556
662
|
|
|
557
663
|
const mergeClassNames = (...classNames) => {
|
|
@@ -1518,11 +1624,6 @@ const isNotReadableError = error => {
|
|
|
1518
1624
|
return error && error.name === NotReadableError;
|
|
1519
1625
|
};
|
|
1520
1626
|
|
|
1521
|
-
/**
|
|
1522
|
-
*
|
|
1523
|
-
* @param {FileSystemFileHandle} handle
|
|
1524
|
-
* @returns
|
|
1525
|
-
*/
|
|
1526
1627
|
const getFile = handle => {
|
|
1527
1628
|
return handle.getFile();
|
|
1528
1629
|
};
|
|
@@ -1595,7 +1696,6 @@ const textSearch$3 = async (scheme, root, query) => {
|
|
|
1595
1696
|
const relativeRoot = root.slice('html://'.length);
|
|
1596
1697
|
const handle = await getDirectoryHandle(relativeRoot);
|
|
1597
1698
|
if (!handle) {
|
|
1598
|
-
// @ts-ignore
|
|
1599
1699
|
throw new VError$1(`Folder not found ${relativeRoot}`);
|
|
1600
1700
|
}
|
|
1601
1701
|
const all = [];
|
|
@@ -1703,6 +1803,7 @@ const commandMap = {
|
|
|
1703
1803
|
'TextSearch.focusSearchValueNext': focusSearchValueNext,
|
|
1704
1804
|
'TextSearch.getActions': getActions,
|
|
1705
1805
|
'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
|
|
1806
|
+
'TextSearch.getSearchDisplayResults': getDisplayResults,
|
|
1706
1807
|
'TextSearch.getVirtualDom': getSearchVirtualDom,
|
|
1707
1808
|
'TextSearch.textSearch': textSearch
|
|
1708
1809
|
};
|