@lvce-editor/extension-host-worker 3.13.0 → 3.15.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/extensionHostWorkerMain.js +70 -19
- package/package.json +1 -1
|
@@ -4596,34 +4596,72 @@ const searchFile = async uri => {
|
|
|
4596
4596
|
return all;
|
|
4597
4597
|
};
|
|
4598
4598
|
|
|
4599
|
+
const getTextSearchRegex = (query, matchCase) => {
|
|
4600
|
+
const flags = matchCase ? 'u' : 'iu';
|
|
4601
|
+
const regex = new RegExp(query, flags);
|
|
4602
|
+
return regex;
|
|
4603
|
+
};
|
|
4604
|
+
|
|
4605
|
+
const getLineMatchRegex = (line, lineNumber, query, matchCase) => {
|
|
4606
|
+
const regex = getTextSearchRegex(query, matchCase);
|
|
4607
|
+
const match = line.match(regex);
|
|
4608
|
+
if (match && typeof match.index === 'number') {
|
|
4609
|
+
return [{
|
|
4610
|
+
type: Match,
|
|
4611
|
+
text: line,
|
|
4612
|
+
start: match.index,
|
|
4613
|
+
end: match.index + match[0].length,
|
|
4614
|
+
lineNumber
|
|
4615
|
+
}];
|
|
4616
|
+
}
|
|
4617
|
+
return [];
|
|
4618
|
+
};
|
|
4619
|
+
|
|
4620
|
+
const getLineMatchText = (line, lineNumber, query, queryLower, matchCase) => {
|
|
4621
|
+
const lineToQuery = matchCase ? line : line.toLowerCase();
|
|
4622
|
+
const actualQuery = matchCase ? query : queryLower;
|
|
4623
|
+
const index = lineToQuery.indexOf(actualQuery);
|
|
4624
|
+
if (index !== -1) {
|
|
4625
|
+
return [{
|
|
4626
|
+
type: Match,
|
|
4627
|
+
text: line,
|
|
4628
|
+
start: index,
|
|
4629
|
+
end: index + query.length,
|
|
4630
|
+
lineNumber
|
|
4631
|
+
}];
|
|
4632
|
+
}
|
|
4633
|
+
return [];
|
|
4634
|
+
};
|
|
4635
|
+
|
|
4636
|
+
const getLineMatch = (line, lineNumber, query, queryLower, useRegularExpression, matchCase) => {
|
|
4637
|
+
if (useRegularExpression) {
|
|
4638
|
+
return getLineMatchRegex(line, lineNumber, query, matchCase);
|
|
4639
|
+
}
|
|
4640
|
+
return getLineMatchText(line, lineNumber, query, queryLower, matchCase);
|
|
4641
|
+
};
|
|
4642
|
+
|
|
4643
|
+
const UseRegularExpression = 1 << 1; // 2
|
|
4644
|
+
const MatchCase = 1 << 4; // 16
|
|
4645
|
+
// 128
|
|
4646
|
+
|
|
4599
4647
|
const splitLines = lines => {
|
|
4600
4648
|
return lines.split('\n');
|
|
4601
4649
|
};
|
|
4602
4650
|
|
|
4603
|
-
const textSearchInText = (file, content, query) => {
|
|
4604
|
-
const
|
|
4651
|
+
const textSearchInText = (file, content, query, flags = 0) => {
|
|
4652
|
+
const matchCase = flags & MatchCase;
|
|
4653
|
+
const useRegularExpression = flags & UseRegularExpression;
|
|
4605
4654
|
const lines = splitLines(content);
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
const index = line.indexOf(query);
|
|
4609
|
-
if (index !== -1) {
|
|
4610
|
-
results.push({
|
|
4611
|
-
type: Match,
|
|
4612
|
-
text: line,
|
|
4613
|
-
start: index,
|
|
4614
|
-
end: index + query.length,
|
|
4615
|
-
lineNumber: i
|
|
4616
|
-
});
|
|
4617
|
-
}
|
|
4618
|
-
}
|
|
4655
|
+
const queryLower = query.toLowerCase();
|
|
4656
|
+
const results = lines.flatMap((line, i) => getLineMatch(line, i, query, queryLower, useRegularExpression, matchCase));
|
|
4619
4657
|
if (results.length > 0) {
|
|
4620
|
-
|
|
4658
|
+
return [{
|
|
4621
4659
|
type: File$3,
|
|
4622
4660
|
text: file,
|
|
4623
4661
|
start: 0,
|
|
4624
4662
|
end: 0,
|
|
4625
4663
|
lineNumber: 0
|
|
4626
|
-
}
|
|
4664
|
+
}, ...results];
|
|
4627
4665
|
}
|
|
4628
4666
|
return results;
|
|
4629
4667
|
};
|
|
@@ -4722,6 +4760,18 @@ const textSearch$1 = async (scheme, root, query) => {
|
|
|
4722
4760
|
return all;
|
|
4723
4761
|
};
|
|
4724
4762
|
|
|
4763
|
+
const matchesUri = (uri, relativeRoot, include, exclude) => {
|
|
4764
|
+
if (!uri.startsWith(relativeRoot)) {
|
|
4765
|
+
return false;
|
|
4766
|
+
}
|
|
4767
|
+
if (include && typeof include === 'string' && !uri.includes(include)) {
|
|
4768
|
+
return false;
|
|
4769
|
+
}
|
|
4770
|
+
if (exclude && typeof exclude === 'string' && uri.includes(exclude)) {
|
|
4771
|
+
return false;
|
|
4772
|
+
}
|
|
4773
|
+
return true;
|
|
4774
|
+
};
|
|
4725
4775
|
const textSearch = async (scheme, root, query, options, assetDir) => {
|
|
4726
4776
|
string(scheme);
|
|
4727
4777
|
string(root);
|
|
@@ -4729,13 +4779,14 @@ const textSearch = async (scheme, root, query, options, assetDir) => {
|
|
|
4729
4779
|
const files = getFiles();
|
|
4730
4780
|
const relativeRoot = root.slice('memfs://'.length);
|
|
4731
4781
|
const allResults = [];
|
|
4782
|
+
const flags = options.flags || 0;
|
|
4732
4783
|
for (const [key, value] of Object.entries(files)) {
|
|
4733
|
-
if (!key.
|
|
4784
|
+
if (!matchesUri(key, relativeRoot, options.include, options.exclude)) {
|
|
4734
4785
|
continue;
|
|
4735
4786
|
}
|
|
4736
4787
|
if (value.type === File$1) {
|
|
4737
4788
|
const relativeUri = key.slice(relativeRoot.length + 1);
|
|
4738
|
-
const results = textSearchInText(relativeUri, value.content, query);
|
|
4789
|
+
const results = textSearchInText(relativeUri, value.content, query, flags);
|
|
4739
4790
|
allResults.push(...results);
|
|
4740
4791
|
}
|
|
4741
4792
|
}
|
package/package.json
CHANGED