@lvce-editor/find-widget-worker 1.14.0 → 1.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/findWidgetWorkerMain.js +227 -149
- package/package.json +1 -1
|
@@ -1013,6 +1013,10 @@ const RenderFocus = 15;
|
|
|
1013
1013
|
const RenderValue = 16;
|
|
1014
1014
|
const RenderReplaceValue = 17;
|
|
1015
1015
|
|
|
1016
|
+
const CheckBox = 'checkbox';
|
|
1017
|
+
const Group = 'group';
|
|
1018
|
+
const None = 'none';
|
|
1019
|
+
|
|
1016
1020
|
const Button = 1;
|
|
1017
1021
|
const Div = 4;
|
|
1018
1022
|
const Text = 12;
|
|
@@ -1126,7 +1130,7 @@ const activateByEvent = async event => {
|
|
|
1126
1130
|
// @ts-ignore
|
|
1127
1131
|
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1128
1132
|
};
|
|
1129
|
-
const applyEdit
|
|
1133
|
+
const applyEdit = async (editorUid, changes) => {
|
|
1130
1134
|
// @ts-ignore
|
|
1131
1135
|
await invoke$1('Editor.applyEdit2', editorUid, changes);
|
|
1132
1136
|
};
|
|
@@ -1191,7 +1195,7 @@ const registerMockRpc = commandMap => {
|
|
|
1191
1195
|
const EditorWorker = {
|
|
1192
1196
|
__proto__: null,
|
|
1193
1197
|
activateByEvent,
|
|
1194
|
-
applyEdit
|
|
1198
|
+
applyEdit,
|
|
1195
1199
|
applyWorkspaceEdit,
|
|
1196
1200
|
closeWidget,
|
|
1197
1201
|
dispose,
|
|
@@ -1215,9 +1219,7 @@ const EditorWorker = {
|
|
|
1215
1219
|
|
|
1216
1220
|
const {
|
|
1217
1221
|
invoke,
|
|
1218
|
-
set
|
|
1219
|
-
applyEdit
|
|
1220
|
-
} = EditorWorker;
|
|
1222
|
+
set} = EditorWorker;
|
|
1221
1223
|
|
|
1222
1224
|
const setSelections = async (editorUid, selections) => {
|
|
1223
1225
|
// @ts-ignore
|
|
@@ -1290,21 +1292,21 @@ const handleBlur = async state => {
|
|
|
1290
1292
|
};
|
|
1291
1293
|
};
|
|
1292
1294
|
|
|
1293
|
-
const
|
|
1294
|
-
return state;
|
|
1295
|
-
};
|
|
1296
|
-
|
|
1297
|
-
const close$1 = async state => {
|
|
1298
|
-
const {
|
|
1299
|
-
editorUid
|
|
1300
|
-
} = state;
|
|
1295
|
+
const escapeRegExpCharacters = value => {
|
|
1301
1296
|
// @ts-ignore
|
|
1302
|
-
|
|
1303
|
-
return state;
|
|
1297
|
+
return RegExp.escape(value);
|
|
1304
1298
|
};
|
|
1305
1299
|
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1300
|
+
const buildRegex = (searchString, options) => {
|
|
1301
|
+
const {
|
|
1302
|
+
matchCase,
|
|
1303
|
+
useRegularExpression,
|
|
1304
|
+
matchWholeWord
|
|
1305
|
+
} = options;
|
|
1306
|
+
const flags = matchCase ? 'g' : 'gi';
|
|
1307
|
+
const pattern = useRegularExpression ? searchString : escapeRegExpCharacters(searchString);
|
|
1308
|
+
const wrapped = matchWholeWord ? `\\b(?:${pattern})\\b` : pattern;
|
|
1309
|
+
return new RegExp(wrapped, flags);
|
|
1308
1310
|
};
|
|
1309
1311
|
|
|
1310
1312
|
const findRegexMatches = (lines, regex) => {
|
|
@@ -1329,22 +1331,11 @@ const findRegexMatches = (lines, regex) => {
|
|
|
1329
1331
|
return new Uint32Array(matches);
|
|
1330
1332
|
};
|
|
1331
1333
|
|
|
1332
|
-
const
|
|
1333
|
-
// @ts-ignore
|
|
1334
|
-
return RegExp.escape(value);
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
|
-
const regexFlags = 'gi';
|
|
1338
|
-
const getSearchRegex = searchString => {
|
|
1339
|
-
const escaped = escapeRegExpCharacters(searchString);
|
|
1340
|
-
return new RegExp(escaped, regexFlags);
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
const findMatchesCaseInsensitive = (lines, searchString) => {
|
|
1334
|
+
const findMatches = (lines, searchString, options) => {
|
|
1344
1335
|
if (searchString.length === 0) {
|
|
1345
1336
|
return new Uint32Array([]);
|
|
1346
1337
|
}
|
|
1347
|
-
const regex =
|
|
1338
|
+
const regex = buildRegex(searchString, options);
|
|
1348
1339
|
return findRegexMatches(lines, regex);
|
|
1349
1340
|
};
|
|
1350
1341
|
|
|
@@ -1354,9 +1345,17 @@ const getMatchCount = matches => {
|
|
|
1354
1345
|
|
|
1355
1346
|
const refresh$1 = (state, value, inputSource) => {
|
|
1356
1347
|
const {
|
|
1357
|
-
lines
|
|
1348
|
+
lines,
|
|
1349
|
+
matchCase,
|
|
1350
|
+
useRegularExpression,
|
|
1351
|
+
matchWholeWord
|
|
1358
1352
|
} = state;
|
|
1359
|
-
const
|
|
1353
|
+
const options = {
|
|
1354
|
+
matchCase,
|
|
1355
|
+
useRegularExpression,
|
|
1356
|
+
matchWholeWord
|
|
1357
|
+
};
|
|
1358
|
+
const matches = findMatches(lines, value, options);
|
|
1360
1359
|
const matchCount = getMatchCount(matches);
|
|
1361
1360
|
return {
|
|
1362
1361
|
...state,
|
|
@@ -1372,21 +1371,169 @@ const refresh = (state, value = state.value, inputSource = User) => {
|
|
|
1372
1371
|
return refresh$1(state, value, inputSource);
|
|
1373
1372
|
};
|
|
1374
1373
|
|
|
1375
|
-
const handleInput = (state, value, inputSource = User) => {
|
|
1376
|
-
return refresh(state, value, inputSource);
|
|
1377
|
-
};
|
|
1378
|
-
|
|
1379
1374
|
const toggleMatchCase = state => {
|
|
1380
1375
|
const {
|
|
1381
1376
|
matchCase
|
|
1382
1377
|
} = state;
|
|
1378
|
+
const newState = {
|
|
1379
|
+
...state,
|
|
1380
|
+
matchCase: !matchCase
|
|
1381
|
+
};
|
|
1382
|
+
return refresh(newState, newState.value, User);
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
const toggleMatchWholeWord = state => {
|
|
1386
|
+
const {
|
|
1387
|
+
matchWholeWord
|
|
1388
|
+
} = state;
|
|
1389
|
+
const newState = {
|
|
1390
|
+
...state,
|
|
1391
|
+
matchWholeWord: !matchWholeWord
|
|
1392
|
+
};
|
|
1393
|
+
return refresh(newState, newState.value, User);
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
const togglePreserveCase = state => {
|
|
1397
|
+
const {
|
|
1398
|
+
preserveCase
|
|
1399
|
+
} = state;
|
|
1383
1400
|
// TODO update search results
|
|
1384
1401
|
return {
|
|
1385
1402
|
...state,
|
|
1386
|
-
|
|
1403
|
+
preserveCase: !preserveCase
|
|
1404
|
+
};
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
const toggleUseRegularExpression = state => {
|
|
1408
|
+
const {
|
|
1409
|
+
useRegularExpression
|
|
1410
|
+
} = state;
|
|
1411
|
+
const newState = {
|
|
1412
|
+
...state,
|
|
1413
|
+
useRegularExpression: !useRegularExpression
|
|
1414
|
+
};
|
|
1415
|
+
return refresh(newState, newState.value, User);
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
const Close$2 = 'Close';
|
|
1419
|
+
const FocusNext = 'FocusNext';
|
|
1420
|
+
const FocusPrevious = 'FocusPrevious';
|
|
1421
|
+
const MatchCase$1 = 'MatchCase';
|
|
1422
|
+
const MatchWholeWord$1 = 'MatchWholeWord';
|
|
1423
|
+
const PreserveCase = 'PreserveCase';
|
|
1424
|
+
const Replace$2 = 'Replace';
|
|
1425
|
+
const ReplaceAll$2 = 'ReplaceAll';
|
|
1426
|
+
const ReplaceValue = 'replace-value';
|
|
1427
|
+
const SearchValue = 'search-value';
|
|
1428
|
+
const ToggleReplace = 'ToggleReplace';
|
|
1429
|
+
const UseRegularExpression$1 = 'UseRegularExpression';
|
|
1430
|
+
|
|
1431
|
+
const applyEdits = async (editorId, edits) => {
|
|
1432
|
+
// @ts-ignore
|
|
1433
|
+
await invoke('Editor.applyDocumentEdits', editorId, edits);
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
|
|
1437
|
+
if (value.length === 0 || matches.length === 0) {
|
|
1438
|
+
return [];
|
|
1439
|
+
}
|
|
1440
|
+
const edits = [];
|
|
1441
|
+
const totalMatches = Math.floor(matches.length / 2);
|
|
1442
|
+
const fromIndex = replaceAll ? 0 : Math.max(0, startIndex);
|
|
1443
|
+
const toIndex = replaceAll ? totalMatches : Math.min(totalMatches, fromIndex + 1);
|
|
1444
|
+
for (let i = fromIndex; i < toIndex; i++) {
|
|
1445
|
+
const rowIndex = matches[i * 2];
|
|
1446
|
+
const startColumnIndex = matches[i * 2 + 1];
|
|
1447
|
+
const endColumnIndex = startColumnIndex + value.length;
|
|
1448
|
+
edits.push({
|
|
1449
|
+
start: {
|
|
1450
|
+
rowIndex,
|
|
1451
|
+
columnIndex: startColumnIndex
|
|
1452
|
+
},
|
|
1453
|
+
end: {
|
|
1454
|
+
rowIndex,
|
|
1455
|
+
columnIndex: endColumnIndex
|
|
1456
|
+
},
|
|
1457
|
+
inserted: [replacement],
|
|
1458
|
+
deleted: [value],
|
|
1459
|
+
origin: 'find-widget.replace'
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
return edits;
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
const replace$1 = async state => {
|
|
1466
|
+
const {
|
|
1467
|
+
matches,
|
|
1468
|
+
value,
|
|
1469
|
+
replacement,
|
|
1470
|
+
matchIndex,
|
|
1471
|
+
editorUid
|
|
1472
|
+
} = state;
|
|
1473
|
+
const edits = getEdits(matches, value, replacement, matchIndex, false);
|
|
1474
|
+
await applyEdits(editorUid, edits);
|
|
1475
|
+
// TODO ask editor worker to apply edit
|
|
1476
|
+
// TODO ask editor worker for new lines?
|
|
1477
|
+
return {
|
|
1478
|
+
...state
|
|
1479
|
+
};
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
const replaceAll$1 = state => {
|
|
1483
|
+
const {
|
|
1484
|
+
matches,
|
|
1485
|
+
value,
|
|
1486
|
+
replacement,
|
|
1487
|
+
editorUid
|
|
1488
|
+
} = state;
|
|
1489
|
+
const edits = getEdits(matches, value, replacement, 0, true);
|
|
1490
|
+
void applyEdits(editorUid, edits);
|
|
1491
|
+
return {
|
|
1492
|
+
...state
|
|
1387
1493
|
};
|
|
1388
1494
|
};
|
|
1389
1495
|
|
|
1496
|
+
const getClickHandler = name => {
|
|
1497
|
+
switch (name) {
|
|
1498
|
+
case Replace$2:
|
|
1499
|
+
return replace$1;
|
|
1500
|
+
case ReplaceAll$2:
|
|
1501
|
+
return replaceAll$1;
|
|
1502
|
+
case MatchCase$1:
|
|
1503
|
+
return toggleMatchCase;
|
|
1504
|
+
case MatchWholeWord$1:
|
|
1505
|
+
return toggleMatchWholeWord;
|
|
1506
|
+
case UseRegularExpression$1:
|
|
1507
|
+
return toggleUseRegularExpression;
|
|
1508
|
+
case PreserveCase:
|
|
1509
|
+
return togglePreserveCase;
|
|
1510
|
+
default:
|
|
1511
|
+
throw new Error(`unexpected click`);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
const handleClickButton = async (state, name) => {
|
|
1516
|
+
const fn = getClickHandler(name);
|
|
1517
|
+
return fn(state);
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
const close$1 = async state => {
|
|
1521
|
+
const {
|
|
1522
|
+
editorUid
|
|
1523
|
+
} = state;
|
|
1524
|
+
// @ts-ignore
|
|
1525
|
+
await invoke('Editor.closeFind2', editorUid);
|
|
1526
|
+
return state;
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
const handleClickClose = state => {
|
|
1530
|
+
return close$1(state);
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
const handleInput = (state, value, inputSource = User) => {
|
|
1534
|
+
return refresh(state, value, inputSource);
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1390
1537
|
const getFindWidgetHeight = replaceExpanded => {
|
|
1391
1538
|
const collapsedHeight = 30;
|
|
1392
1539
|
const expandedHeight = 60;
|
|
@@ -1407,16 +1554,6 @@ const toggleReplace = state => {
|
|
|
1407
1554
|
};
|
|
1408
1555
|
};
|
|
1409
1556
|
|
|
1410
|
-
const toggleUseRegularExpression = state => {
|
|
1411
|
-
const {
|
|
1412
|
-
useRegularExpression
|
|
1413
|
-
} = state;
|
|
1414
|
-
return {
|
|
1415
|
-
...state,
|
|
1416
|
-
useRegularExpression: !useRegularExpression
|
|
1417
|
-
};
|
|
1418
|
-
};
|
|
1419
|
-
|
|
1420
1557
|
const handleReplaceInput = (state, value, inputSource = User) => {
|
|
1421
1558
|
return {
|
|
1422
1559
|
...state,
|
|
@@ -1425,6 +1562,20 @@ const handleReplaceInput = (state, value, inputSource = User) => {
|
|
|
1425
1562
|
};
|
|
1426
1563
|
};
|
|
1427
1564
|
|
|
1565
|
+
const regexFlags = 'gi';
|
|
1566
|
+
const getSearchRegex = searchString => {
|
|
1567
|
+
const escaped = escapeRegExpCharacters(searchString);
|
|
1568
|
+
return new RegExp(escaped, regexFlags);
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const findMatchesCaseInsensitive = (lines, searchString) => {
|
|
1572
|
+
if (searchString.length === 0) {
|
|
1573
|
+
return new Uint32Array([]);
|
|
1574
|
+
}
|
|
1575
|
+
const regex = getSearchRegex(searchString);
|
|
1576
|
+
return findRegexMatches(lines, regex);
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1428
1579
|
const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
|
|
1429
1580
|
const width = 300;
|
|
1430
1581
|
const height = 30;
|
|
@@ -1551,12 +1702,12 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1551
1702
|
|
|
1552
1703
|
const MatchOf = '{PH1} of {PH2}';
|
|
1553
1704
|
const NoResults = 'No Results';
|
|
1554
|
-
const Close$
|
|
1705
|
+
const Close$1 = 'Close';
|
|
1555
1706
|
const PreviousMatch = 'Previous Match';
|
|
1556
1707
|
const NextMatch = 'Next Match';
|
|
1557
1708
|
const Find$1 = 'Find';
|
|
1558
|
-
const Replace$
|
|
1559
|
-
const ReplaceAll$
|
|
1709
|
+
const Replace$1 = 'Replace';
|
|
1710
|
+
const ReplaceAll$1 = 'Replace All';
|
|
1560
1711
|
|
|
1561
1712
|
const noResults = () => {
|
|
1562
1713
|
return i18nString(NoResults);
|
|
@@ -1574,38 +1725,26 @@ const nextMatch = () => {
|
|
|
1574
1725
|
return i18nString(NextMatch);
|
|
1575
1726
|
};
|
|
1576
1727
|
const close = () => {
|
|
1577
|
-
return i18nString(Close$
|
|
1728
|
+
return i18nString(Close$1);
|
|
1578
1729
|
};
|
|
1579
1730
|
const find = () => {
|
|
1580
1731
|
return i18nString(Find$1);
|
|
1581
1732
|
};
|
|
1582
|
-
const replace
|
|
1583
|
-
return i18nString(Replace$
|
|
1733
|
+
const replace = () => {
|
|
1734
|
+
return i18nString(Replace$1);
|
|
1584
1735
|
};
|
|
1585
|
-
const replaceAll
|
|
1586
|
-
return i18nString(ReplaceAll$
|
|
1736
|
+
const replaceAll = () => {
|
|
1737
|
+
return i18nString(ReplaceAll$1);
|
|
1587
1738
|
};
|
|
1588
1739
|
|
|
1589
|
-
const MatchCase
|
|
1590
|
-
const UseRegularExpression
|
|
1591
|
-
const MatchWholeWord
|
|
1740
|
+
const MatchCase = 'CaseSensitive';
|
|
1741
|
+
const UseRegularExpression = 'Regex';
|
|
1742
|
+
const MatchWholeWord = 'WholeWord';
|
|
1592
1743
|
const ArrowDown = 'ArrowDown';
|
|
1593
1744
|
const ArrowUp = 'ArrowUp';
|
|
1594
|
-
const Close$1 = 'Close';
|
|
1595
|
-
const Replace$1 = 'Replace';
|
|
1596
|
-
const ReplaceAll$1 = 'ReplaceAll';
|
|
1597
|
-
|
|
1598
1745
|
const Close = 'Close';
|
|
1599
|
-
const FocusNext = 'FocusNext';
|
|
1600
|
-
const FocusPrevious = 'FocusPrevious';
|
|
1601
|
-
const MatchCase = 'MatchCase';
|
|
1602
|
-
const MatchWholeWord = 'MatchWholeWord';
|
|
1603
1746
|
const Replace = 'Replace';
|
|
1604
1747
|
const ReplaceAll = 'ReplaceAll';
|
|
1605
|
-
const ReplaceValue = 'replace-value';
|
|
1606
|
-
const SearchValue = 'search-value';
|
|
1607
|
-
const ToggleReplace = 'ToggleReplace';
|
|
1608
|
-
const UseRegularExpression = 'UseRegularExpression';
|
|
1609
1748
|
|
|
1610
1749
|
const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
|
|
1611
1750
|
const findButtons = [{
|
|
@@ -1622,23 +1761,23 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
|
|
|
1622
1761
|
name: FocusNext
|
|
1623
1762
|
}, {
|
|
1624
1763
|
label: close(),
|
|
1625
|
-
icon: Close
|
|
1764
|
+
icon: Close,
|
|
1626
1765
|
disabled: false,
|
|
1627
1766
|
onClick: HandleClickClose,
|
|
1628
|
-
name: Close
|
|
1767
|
+
name: Close$2
|
|
1629
1768
|
}];
|
|
1630
1769
|
const replaceButtons = [{
|
|
1631
|
-
label: replace
|
|
1632
|
-
icon: Replace
|
|
1770
|
+
label: replace(),
|
|
1771
|
+
icon: Replace,
|
|
1633
1772
|
disabled: !replaceButtonsEnabled,
|
|
1634
1773
|
onClick: HandleClickReplace,
|
|
1635
|
-
name: Replace
|
|
1774
|
+
name: Replace$2
|
|
1636
1775
|
}, {
|
|
1637
|
-
label: replaceAll
|
|
1638
|
-
icon: ReplaceAll
|
|
1776
|
+
label: replaceAll(),
|
|
1777
|
+
icon: ReplaceAll,
|
|
1639
1778
|
disabled: !replaceButtonsEnabled,
|
|
1640
1779
|
onClick: HandleClickReplaceAll,
|
|
1641
|
-
name: ReplaceAll
|
|
1780
|
+
name: ReplaceAll$2
|
|
1642
1781
|
}];
|
|
1643
1782
|
return {
|
|
1644
1783
|
findButtons,
|
|
@@ -1667,10 +1806,6 @@ const text = data => {
|
|
|
1667
1806
|
};
|
|
1668
1807
|
};
|
|
1669
1808
|
|
|
1670
|
-
const CheckBox = 'checkbox';
|
|
1671
|
-
const Group = 'group';
|
|
1672
|
-
const None = 'none';
|
|
1673
|
-
|
|
1674
1809
|
const FindWidgetFind = 'FindWidgetFind';
|
|
1675
1810
|
const FindWidgetMatchCount = 'FindWidgetMatchCount';
|
|
1676
1811
|
const FindWidgetMatchCountEmpty = 'FindWidgetMatchCountEmpty';
|
|
@@ -1692,19 +1827,19 @@ const ViewletFindWidget = 'ViewletFindWidget';
|
|
|
1692
1827
|
const getFindButtons = () => {
|
|
1693
1828
|
return [{
|
|
1694
1829
|
checked: false,
|
|
1695
|
-
icon: MatchCase
|
|
1830
|
+
icon: MatchCase,
|
|
1696
1831
|
title: 'Match Case',
|
|
1697
|
-
name: MatchCase
|
|
1832
|
+
name: MatchCase$1
|
|
1698
1833
|
}, {
|
|
1699
1834
|
checked: false,
|
|
1700
|
-
icon: MatchWholeWord
|
|
1835
|
+
icon: MatchWholeWord,
|
|
1701
1836
|
title: 'Match Whole Word',
|
|
1702
|
-
name: MatchWholeWord
|
|
1837
|
+
name: MatchWholeWord$1
|
|
1703
1838
|
}, {
|
|
1704
1839
|
checked: false,
|
|
1705
|
-
icon: UseRegularExpression
|
|
1840
|
+
icon: UseRegularExpression,
|
|
1706
1841
|
title: 'Use Regular Expression',
|
|
1707
|
-
name: UseRegularExpression
|
|
1842
|
+
name: UseRegularExpression$1
|
|
1708
1843
|
}];
|
|
1709
1844
|
};
|
|
1710
1845
|
|
|
@@ -1821,7 +1956,7 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
|
|
|
1821
1956
|
type: Div,
|
|
1822
1957
|
className: FindWidgetReplace,
|
|
1823
1958
|
childCount: 1 + replaceButtons.length
|
|
1824
|
-
}, ...getSearchFieldVirtualDom(ReplaceValue, replace
|
|
1959
|
+
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
|
|
1825
1960
|
}
|
|
1826
1961
|
return dom;
|
|
1827
1962
|
};
|
|
@@ -1964,7 +2099,7 @@ const renderReplaceValue = (oldState, newState) => {
|
|
|
1964
2099
|
uid,
|
|
1965
2100
|
replacement
|
|
1966
2101
|
} = newState;
|
|
1967
|
-
return [SetValueByName, uid, Replace, replacement];
|
|
2102
|
+
return [SetValueByName, uid, Replace$2, replacement];
|
|
1968
2103
|
};
|
|
1969
2104
|
|
|
1970
2105
|
const renderUid = (oldState, newState) => {
|
|
@@ -2025,63 +2160,6 @@ const render2 = (uid, diffResult) => {
|
|
|
2025
2160
|
return commands;
|
|
2026
2161
|
};
|
|
2027
2162
|
|
|
2028
|
-
const applyEdits = async (editorId, edits) => {
|
|
2029
|
-
await applyEdit(editorId, edits);
|
|
2030
|
-
};
|
|
2031
|
-
|
|
2032
|
-
const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
|
|
2033
|
-
if (value.length === 0 || matches.length === 0) {
|
|
2034
|
-
return [];
|
|
2035
|
-
}
|
|
2036
|
-
const edits = [];
|
|
2037
|
-
const totalMatches = Math.floor(matches.length / 2);
|
|
2038
|
-
const fromIndex = replaceAll ? 0 : Math.max(0, startIndex);
|
|
2039
|
-
const toIndex = replaceAll ? totalMatches : Math.min(totalMatches, fromIndex + 1);
|
|
2040
|
-
for (let i = fromIndex; i < toIndex; i++) {
|
|
2041
|
-
const rowIndex = matches[i * 2];
|
|
2042
|
-
const startColumnIndex = matches[i * 2 + 1];
|
|
2043
|
-
const endColumnIndex = startColumnIndex + value.length;
|
|
2044
|
-
edits.push({
|
|
2045
|
-
rowIndex,
|
|
2046
|
-
startColumnIndex,
|
|
2047
|
-
endColumnIndex,
|
|
2048
|
-
newText: replacement
|
|
2049
|
-
});
|
|
2050
|
-
}
|
|
2051
|
-
return edits;
|
|
2052
|
-
};
|
|
2053
|
-
|
|
2054
|
-
const replace = async state => {
|
|
2055
|
-
const {
|
|
2056
|
-
matches,
|
|
2057
|
-
value,
|
|
2058
|
-
replacement,
|
|
2059
|
-
matchIndex,
|
|
2060
|
-
editorUid
|
|
2061
|
-
} = state;
|
|
2062
|
-
const edits = getEdits(matches, value, replacement, matchIndex, false);
|
|
2063
|
-
await applyEdits(editorUid, edits);
|
|
2064
|
-
// TODO ask editor worker to apply edit
|
|
2065
|
-
// TODO ask editor worker for new lines?
|
|
2066
|
-
return {
|
|
2067
|
-
...state
|
|
2068
|
-
};
|
|
2069
|
-
};
|
|
2070
|
-
|
|
2071
|
-
const replaceAll = state => {
|
|
2072
|
-
const {
|
|
2073
|
-
matches,
|
|
2074
|
-
value,
|
|
2075
|
-
replacement,
|
|
2076
|
-
editorUid
|
|
2077
|
-
} = state;
|
|
2078
|
-
const edits = getEdits(matches, value, replacement, 0, true);
|
|
2079
|
-
void applyEdits(editorUid, edits);
|
|
2080
|
-
return {
|
|
2081
|
-
...state
|
|
2082
|
-
};
|
|
2083
|
-
};
|
|
2084
|
-
|
|
2085
2163
|
const commandMap = {
|
|
2086
2164
|
'FindWidget.create': create$1,
|
|
2087
2165
|
'FindWidget.diff2': diff2,
|
|
@@ -2105,8 +2183,8 @@ const commandMap = {
|
|
|
2105
2183
|
'FindWidget.render2': render2,
|
|
2106
2184
|
'FindWidget.terminate': terminate,
|
|
2107
2185
|
'FindWidget.toggleReplace': wrapCommand(toggleReplace),
|
|
2108
|
-
'FindWidget.replace': wrapCommand(replace),
|
|
2109
|
-
'FindWidget.replaceAll': wrapCommand(replaceAll),
|
|
2186
|
+
'FindWidget.replace': wrapCommand(replace$1),
|
|
2187
|
+
'FindWidget.replaceAll': wrapCommand(replaceAll$1),
|
|
2110
2188
|
'FindWidget.handleClickButton': wrapCommand(handleClickButton),
|
|
2111
2189
|
'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
|
|
2112
2190
|
};
|