@lvce-editor/text-search-worker 7.22.0 → 7.22.1

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.
@@ -1635,23 +1635,6 @@ const textSearch$3 = async (scheme, root, query) => {
1635
1635
  };
1636
1636
  };
1637
1637
 
1638
- const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1639
- try {
1640
- // @ts-ignore
1641
- const result = await invoke$3('ExtensionHostTextSearch.textSearchMemory2', scheme, root, query, options, assetDir);
1642
- if (!result || !result.results) {
1643
- throw new Error(`new api not supported`);
1644
- }
1645
- return result;
1646
- } catch {
1647
- const results = await invoke$3('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
1648
- return {
1649
- limitHit: false,
1650
- results
1651
- };
1652
- }
1653
- };
1654
-
1655
1638
  const windowsDrivePathRegex = /^\/[A-Za-z]:\//;
1656
1639
  const windowsDriveRegex = /^[A-Za-z]:[\\/]/;
1657
1640
  const uriSchemeRegex = /^[A-Za-z][A-Za-z\d+.-]*:/;
@@ -1659,25 +1642,69 @@ const trailingSlashRegex = /\/$/;
1659
1642
  const normalizeWindowsDrive = path => {
1660
1643
  return windowsDrivePathRegex.test(path) ? path.slice(1) : path;
1661
1644
  };
1662
- const toPath = uri => {
1663
- if (uri.startsWith('file://')) {
1664
- return normalizeWindowsDrive(decodeURIComponent(new URL(uri).pathname)).replaceAll('\\', '/');
1665
- }
1645
+ const toPath = (uri, expectedUrl) => {
1666
1646
  if (windowsDriveRegex.test(uri)) {
1667
1647
  return uri.replaceAll('\\', '/');
1668
1648
  }
1649
+ if (URL.canParse(uri)) {
1650
+ const url = new URL(uri);
1651
+ if (expectedUrl && (url.protocol !== expectedUrl.protocol || url.host !== expectedUrl.host)) {
1652
+ return '';
1653
+ }
1654
+ if (url.protocol === 'file:' || expectedUrl) {
1655
+ return normalizeWindowsDrive(decodeURIComponent(url.pathname)).replaceAll('\\', '/');
1656
+ }
1657
+ return '';
1658
+ }
1669
1659
  if (uriSchemeRegex.test(uri)) {
1670
1660
  return '';
1671
1661
  }
1672
1662
  return uri.replaceAll('\\', '/');
1673
1663
  };
1674
1664
  const getOpenEditorPaths = (root, openEditorUris) => {
1675
- const rootPath = toPath(root).replace(trailingSlashRegex, '');
1665
+ const rootUrl = URL.canParse(root) ? new URL(root) : undefined;
1666
+ const rootPath = toPath(root, rootUrl).replace(trailingSlashRegex, '');
1676
1667
  const rootPrefix = `${rootPath}/`;
1677
- const paths = openEditorUris.map(toPath).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
1668
+ const paths = openEditorUris.map(uri => toPath(uri, rootUrl)).filter(path => path.startsWith(rootPrefix)).map(path => path.slice(rootPrefix.length));
1678
1669
  return [...new Set(paths)];
1679
1670
  };
1680
1671
 
1672
+ const File = 1;
1673
+
1674
+ const filterOpenEditorResults = (root, results, openEditorUris) => {
1675
+ const openEditorPaths = new Set(getOpenEditorPaths(root, openEditorUris));
1676
+ let isOpenEditor = false;
1677
+ return results.filter(result => {
1678
+ if (result.type === File) {
1679
+ isOpenEditor = openEditorPaths.has(result.text);
1680
+ }
1681
+ return isOpenEditor;
1682
+ });
1683
+ };
1684
+ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
1685
+ try {
1686
+ // @ts-ignore
1687
+ const result = await invoke$3('ExtensionHostTextSearch.textSearchMemory2', scheme, root, query, options, assetDir);
1688
+ if (!result || !result.results) {
1689
+ throw new Error(`new api not supported`);
1690
+ }
1691
+ if (options.openEditorUris) {
1692
+ return {
1693
+ ...result,
1694
+ results: filterOpenEditorResults(root, result.results, options.openEditorUris)
1695
+ };
1696
+ }
1697
+ return result;
1698
+ } catch {
1699
+ const results = await invoke$3('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
1700
+ const filteredResults = options.openEditorUris ? filterOpenEditorResults(root, results, options.openEditorUris) : results;
1701
+ return {
1702
+ limitHit: false,
1703
+ results: filteredResults
1704
+ };
1705
+ }
1706
+ };
1707
+
1681
1708
  const textSearch$1 = async (scheme, root, query, options, assetDir, _platform, searchId, uid) => {
1682
1709
  const openEditorPaths = options.openEditorUris ? getOpenEditorPaths(root, options.openEditorUris) : undefined;
1683
1710
  if (openEditorPaths && openEditorPaths.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "7.22.0",
3
+ "version": "7.22.1",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"