@lvce-editor/search-process 15.8.0 → 15.8.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.
- package/dist/index.js +29 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1629,6 +1629,30 @@ const getStringIndexFromByteOffset = (text, byteOffset) => {
|
|
|
1629
1629
|
return Buffer.from(text).subarray(0, byteOffset).toString().length;
|
|
1630
1630
|
};
|
|
1631
1631
|
|
|
1632
|
+
const ellipsis = '...';
|
|
1633
|
+
const seamSearchRadius = 8;
|
|
1634
|
+
const isNaturalSeam = character => {
|
|
1635
|
+
return /[\s./\\_:;,()[\]{}'"-]/.test(character);
|
|
1636
|
+
};
|
|
1637
|
+
const getPreviewStart = (text, matchStart, charsBefore) => {
|
|
1638
|
+
const preferredStart = Math.max(matchStart - charsBefore, 0);
|
|
1639
|
+
if (preferredStart === 0) {
|
|
1640
|
+
return 0;
|
|
1641
|
+
}
|
|
1642
|
+
const minimumSeamIndex = Math.max(preferredStart - seamSearchRadius, 0);
|
|
1643
|
+
for (let seamIndex = preferredStart - 1; seamIndex >= minimumSeamIndex; seamIndex--) {
|
|
1644
|
+
if (isNaturalSeam(text[seamIndex])) {
|
|
1645
|
+
return seamIndex + 1;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
const maximumSeamIndex = Math.min(preferredStart + seamSearchRadius, matchStart - 1);
|
|
1649
|
+
for (let seamIndex = preferredStart; seamIndex <= maximumSeamIndex; seamIndex++) {
|
|
1650
|
+
if (isNaturalSeam(text[seamIndex])) {
|
|
1651
|
+
return seamIndex + 1;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return preferredStart;
|
|
1655
|
+
};
|
|
1632
1656
|
const toTextSearchResult = (parsedLine, remaining, charsBefore, charsAfter) => {
|
|
1633
1657
|
const results = [];
|
|
1634
1658
|
const parsedLineData = parsedLine.data;
|
|
@@ -1640,15 +1664,16 @@ const toTextSearchResult = (parsedLine, remaining, charsBefore, charsAfter) => {
|
|
|
1640
1664
|
for (const submatch of submatches) {
|
|
1641
1665
|
const startColumnIndex = getStringIndexFromByteOffset(lines, submatch.start);
|
|
1642
1666
|
const endColumnIndex = getStringIndexFromByteOffset(lines, submatch.end);
|
|
1643
|
-
const previewStart =
|
|
1667
|
+
const previewStart = getPreviewStart(lines, startColumnIndex, charsBefore);
|
|
1644
1668
|
const previewEnd = Math.min(endColumnIndex + charsAfter, lines.length);
|
|
1645
|
-
const
|
|
1669
|
+
const prefix = previewStart === 0 ? '' : ellipsis;
|
|
1670
|
+
const previewText = prefix + lines.slice(previewStart, previewEnd);
|
|
1646
1671
|
results.push({
|
|
1647
|
-
end: endColumnIndex - previewStart,
|
|
1672
|
+
end: endColumnIndex - previewStart + prefix.length,
|
|
1648
1673
|
endColumnIndex,
|
|
1649
1674
|
lineNumber,
|
|
1650
1675
|
rowIndex: lineNumber - 1,
|
|
1651
|
-
start: startColumnIndex - previewStart,
|
|
1676
|
+
start: startColumnIndex - previewStart + prefix.length,
|
|
1652
1677
|
startColumnIndex,
|
|
1653
1678
|
text: previewText,
|
|
1654
1679
|
type: Match
|