@lvce-editor/text-search-worker 7.13.1 → 7.14.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.
@@ -1444,12 +1444,17 @@ const getContextArgs = contextLines => {
1444
1444
  }
1445
1445
  return [];
1446
1446
  };
1447
+ const getIncludeArgs = include => {
1448
+ return (include || '').split(',').map(part => part.trim()).filter(Boolean).flatMap(pattern => ['--glob', pattern]);
1449
+ };
1447
1450
  const getRipGrepArgs = ({
1448
1451
  contextLines,
1449
1452
  defaultExcludes,
1450
1453
  exclude,
1454
+ include,
1451
1455
  isCaseSensitive,
1452
1456
  matchWholeWord,
1457
+ paths,
1453
1458
  searchString,
1454
1459
  threads,
1455
1460
  useIgnoreFiles = true,
@@ -1472,6 +1477,7 @@ const getRipGrepArgs = ({
1472
1477
  ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
1473
1478
  }
1474
1479
  }
1480
+ ripGrepArgs.push(...getIncludeArgs(include));
1475
1481
  if (isCaseSensitive) {
1476
1482
  ripGrepArgs.push('--case-sensitive');
1477
1483
  } else {
@@ -1487,7 +1493,7 @@ const getRipGrepArgs = ({
1487
1493
  ripGrepArgs.push('--');
1488
1494
  ripGrepArgs.push(searchString);
1489
1495
  }
1490
- ripGrepArgs.push('.');
1496
+ ripGrepArgs.push(...(paths || ['.']));
1491
1497
  return ripGrepArgs;
1492
1498
  };
1493
1499
 
@@ -1559,9 +1565,41 @@ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1559
1565
  }
1560
1566
  };
1561
1567
 
1568
+ const normalizeWindowsDrive = path => {
1569
+ return /^\/[A-Za-z]:\//.test(path) ? path.slice(1) : path;
1570
+ };
1571
+ const toPath = uri => {
1572
+ if (uri.startsWith('file://')) {
1573
+ return normalizeWindowsDrive(decodeURIComponent(new URL(uri).pathname)).replaceAll('\\', '/');
1574
+ }
1575
+ if (/^[A-Za-z]:[\\/]/.test(uri)) {
1576
+ return uri.replaceAll('\\', '/');
1577
+ }
1578
+ if (/^[A-Za-z][A-Za-z\d+.-]*:/.test(uri)) {
1579
+ return '';
1580
+ }
1581
+ return uri.replaceAll('\\', '/');
1582
+ };
1583
+ const getOpenEditorPaths = (root, openEditorUris) => {
1584
+ const rootPath = toPath(root).replace(/\/$/, '');
1585
+ const rootPrefix = `${rootPath}/`;
1586
+ const paths = openEditorUris.map(toPath).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
1587
+ return [...new Set(paths)];
1588
+ };
1589
+
1562
1590
  const textSearch$1 = async (scheme, root, query, options, assetDir, _platform, searchId, uid) => {
1591
+ const openEditorPaths = options.openEditorUris ? getOpenEditorPaths(root, options.openEditorUris) : undefined;
1592
+ if (openEditorPaths && openEditorPaths.length === 0) {
1593
+ return {
1594
+ limitHit: false,
1595
+ results: []
1596
+ };
1597
+ }
1563
1598
  const ripGrepArgs = getRipGrepArgs({
1564
1599
  ...options,
1600
+ ...(openEditorPaths && {
1601
+ paths: openEditorPaths
1602
+ }),
1565
1603
  searchString: query
1566
1604
  });
1567
1605
  if (options.usePullBasedSearch && searchId && (scheme === '' || scheme === 'file')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "7.13.1",
3
+ "version": "7.14.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"