@lvce-editor/search-process 15.1.0 → 15.1.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.
Files changed (2) hide show
  1. package/dist/index.js +13 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1552,6 +1552,10 @@ const Summary = 'summary';
1552
1552
  const File = 1;
1553
1553
  const Match = 2;
1554
1554
 
1555
+ const getStringIndexFromByteOffset = (text, byteOffset) => {
1556
+ return Buffer.from(text).subarray(0, byteOffset).toString().length;
1557
+ };
1558
+
1555
1559
  const parseRipGrepLines = parsedLineData => {
1556
1560
  if (parsedLineData.lines.text) {
1557
1561
  return parsedLineData.lines.text;
@@ -1570,16 +1574,18 @@ const toTextSearchResult = (parsedLine, remaining, charsBefore, charsAfter) => {
1570
1574
  const {
1571
1575
  submatches
1572
1576
  } = parsedLineData;
1573
- const linesLength = lines.length;
1574
1577
  for (const submatch of submatches) {
1575
- const previewStart = Math.max(submatch.start - charsBefore, 0);
1576
- const actualStart = previewStart;
1577
- const previewEnd = Math.min(submatch.end + charsAfter, linesLength);
1578
- const previewText = lines.slice(actualStart, previewEnd);
1578
+ const startColumnIndex = getStringIndexFromByteOffset(lines, submatch.start);
1579
+ const endColumnIndex = getStringIndexFromByteOffset(lines, submatch.end);
1580
+ const previewStart = Math.max(startColumnIndex - charsBefore, 0);
1581
+ const previewEnd = Math.min(endColumnIndex + charsAfter, lines.length);
1582
+ const previewText = lines.slice(previewStart, previewEnd);
1579
1583
  results.push({
1580
- end: submatch.end - actualStart,
1584
+ end: endColumnIndex - previewStart,
1585
+ endColumnIndex,
1581
1586
  lineNumber,
1582
- start: submatch.start - actualStart,
1587
+ start: startColumnIndex - previewStart,
1588
+ startColumnIndex,
1583
1589
  text: previewText,
1584
1590
  type: Match
1585
1591
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/search-process",
3
- "version": "15.1.0",
3
+ "version": "15.1.1",
4
4
  "description": "Search Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",