@lvce-editor/find-widget-worker 2.0.0 → 2.1.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/findWidgetWorkerMain.js +22 -15
- package/package.json +1 -1
|
@@ -1540,7 +1540,7 @@ const applyEdits = async (editorId, edits) => {
|
|
|
1540
1540
|
await invoke('Editor.applyDocumentEdits', editorId, edits);
|
|
1541
1541
|
};
|
|
1542
1542
|
|
|
1543
|
-
const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
|
|
1543
|
+
const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) => {
|
|
1544
1544
|
if (value.length === 0 || matches.length === 0) {
|
|
1545
1545
|
return [];
|
|
1546
1546
|
}
|
|
@@ -1552,17 +1552,22 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
|
|
|
1552
1552
|
const rowIndex = matches[i * 2];
|
|
1553
1553
|
const startColumnIndex = matches[i * 2 + 1];
|
|
1554
1554
|
const endColumnIndex = startColumnIndex + value.length;
|
|
1555
|
+
|
|
1556
|
+
// Convert row/column positions to character offsets
|
|
1557
|
+
let startOffset = 0;
|
|
1558
|
+
for (let row = 0; row < rowIndex; row++) {
|
|
1559
|
+
startOffset += lines[row].length + 1; // +1 for newline character
|
|
1560
|
+
}
|
|
1561
|
+
startOffset += startColumnIndex;
|
|
1562
|
+
let endOffset = 0;
|
|
1563
|
+
for (let row = 0; row < rowIndex; row++) {
|
|
1564
|
+
endOffset += lines[row].length + 1; // +1 for newline character
|
|
1565
|
+
}
|
|
1566
|
+
endOffset += endColumnIndex;
|
|
1555
1567
|
edits.push({
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
},
|
|
1560
|
-
end: {
|
|
1561
|
-
rowIndex,
|
|
1562
|
-
columnIndex: endColumnIndex
|
|
1563
|
-
},
|
|
1564
|
-
inserted: [replacement],
|
|
1565
|
-
deleted: [value],
|
|
1568
|
+
startOffset,
|
|
1569
|
+
endOffset,
|
|
1570
|
+
inserted: replacement,
|
|
1566
1571
|
origin: 'find-widget.replace'
|
|
1567
1572
|
});
|
|
1568
1573
|
}
|
|
@@ -1575,9 +1580,10 @@ const replace$1 = async state => {
|
|
|
1575
1580
|
value,
|
|
1576
1581
|
replacement,
|
|
1577
1582
|
matchIndex,
|
|
1578
|
-
editorUid
|
|
1583
|
+
editorUid,
|
|
1584
|
+
lines
|
|
1579
1585
|
} = state;
|
|
1580
|
-
const edits = getEdits(matches, value, replacement, matchIndex, false);
|
|
1586
|
+
const edits = getEdits(matches, value, replacement, matchIndex, false, lines);
|
|
1581
1587
|
await applyEdits(editorUid, edits);
|
|
1582
1588
|
// TODO ask editor worker to apply edit
|
|
1583
1589
|
// TODO ask editor worker for new lines?
|
|
@@ -1591,9 +1597,10 @@ const replaceAll$1 = state => {
|
|
|
1591
1597
|
matches,
|
|
1592
1598
|
value,
|
|
1593
1599
|
replacement,
|
|
1594
|
-
editorUid
|
|
1600
|
+
editorUid,
|
|
1601
|
+
lines
|
|
1595
1602
|
} = state;
|
|
1596
|
-
const edits = getEdits(matches, value, replacement, 0, true);
|
|
1603
|
+
const edits = getEdits(matches, value, replacement, 0, true, lines);
|
|
1597
1604
|
void applyEdits(editorUid, edits);
|
|
1598
1605
|
return {
|
|
1599
1606
|
...state
|