@lvce-editor/find-widget-worker 1.14.0 → 1.16.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 +370 -167
- package/package.json +1 -1
|
@@ -946,6 +946,7 @@ const {
|
|
|
946
946
|
registerCommands
|
|
947
947
|
} = create$2();
|
|
948
948
|
|
|
949
|
+
const User$1 = 1;
|
|
949
950
|
const Script$1 = 2;
|
|
950
951
|
const Unknown = 0;
|
|
951
952
|
|
|
@@ -978,16 +979,21 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
|
978
979
|
editorWidth: width,
|
|
979
980
|
editorHeight: height,
|
|
980
981
|
inputSource: 0,
|
|
981
|
-
preserveCase: false
|
|
982
|
+
preserveCase: false,
|
|
983
|
+
resizerPointerDown: false
|
|
982
984
|
};
|
|
983
985
|
set$3(uid, state, state);
|
|
984
986
|
return state;
|
|
985
987
|
};
|
|
986
988
|
|
|
987
|
-
const isEqual$
|
|
989
|
+
const isEqual$6 = (oldState, newState) => {
|
|
988
990
|
return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
|
|
989
991
|
};
|
|
990
992
|
|
|
993
|
+
const isEqual$5 = (oldState, newState) => {
|
|
994
|
+
return newState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x;
|
|
995
|
+
};
|
|
996
|
+
|
|
991
997
|
const isEqual$4 = (oldState, newState) => {
|
|
992
998
|
return oldState.version === newState.version;
|
|
993
999
|
};
|
|
@@ -1005,6 +1011,7 @@ const isEqual$1 = (oldState, newState) => {
|
|
|
1005
1011
|
};
|
|
1006
1012
|
|
|
1007
1013
|
const RenderBounds = 8;
|
|
1014
|
+
const RenderCss = 10;
|
|
1008
1015
|
const RenderEventListeners = 11;
|
|
1009
1016
|
const RenderUid = 12;
|
|
1010
1017
|
const RenderContent = 13;
|
|
@@ -1013,17 +1020,25 @@ const RenderFocus = 15;
|
|
|
1013
1020
|
const RenderValue = 16;
|
|
1014
1021
|
const RenderReplaceValue = 17;
|
|
1015
1022
|
|
|
1023
|
+
const CheckBox = 'checkbox';
|
|
1024
|
+
const Group = 'group';
|
|
1025
|
+
const None = 'none';
|
|
1026
|
+
|
|
1016
1027
|
const Button = 1;
|
|
1017
1028
|
const Div = 4;
|
|
1018
1029
|
const Text = 12;
|
|
1019
1030
|
const TextArea = 62;
|
|
1020
1031
|
|
|
1032
|
+
const ClientX = 'event.clientX';
|
|
1033
|
+
const ClientY = 'event.clientY';
|
|
1034
|
+
|
|
1021
1035
|
const User = 1;
|
|
1022
1036
|
const Script = 1;
|
|
1023
1037
|
|
|
1024
1038
|
const EditorWorker$1 = 99;
|
|
1025
1039
|
|
|
1026
1040
|
const FocusSelector = 'Viewlet.focusSelector';
|
|
1041
|
+
const SetCss = 'Viewlet.setCss';
|
|
1027
1042
|
const SetFocusContext = 'Viewlet.setFocusContext';
|
|
1028
1043
|
const SetValueByName = 'Viewlet.setValueByName';
|
|
1029
1044
|
|
|
@@ -1031,8 +1046,8 @@ const isEqual = (oldState, newState) => {
|
|
|
1031
1046
|
return newState.inputSource === User || oldState.value === newState.value;
|
|
1032
1047
|
};
|
|
1033
1048
|
|
|
1034
|
-
const modules = [isEqual$4, isEqual$2, isEqual$
|
|
1035
|
-
const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue];
|
|
1049
|
+
const modules = [isEqual$4, isEqual$2, isEqual$6, isEqual$1, isEqual$3, isEqual$3, isEqual, isEqual$5];
|
|
1050
|
+
const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue, RenderCss];
|
|
1036
1051
|
|
|
1037
1052
|
const diff = (oldState, newState) => {
|
|
1038
1053
|
const diffResult = [];
|
|
@@ -1126,7 +1141,7 @@ const activateByEvent = async event => {
|
|
|
1126
1141
|
// @ts-ignore
|
|
1127
1142
|
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1128
1143
|
};
|
|
1129
|
-
const applyEdit
|
|
1144
|
+
const applyEdit = async (editorUid, changes) => {
|
|
1130
1145
|
// @ts-ignore
|
|
1131
1146
|
await invoke$1('Editor.applyEdit2', editorUid, changes);
|
|
1132
1147
|
};
|
|
@@ -1191,7 +1206,7 @@ const registerMockRpc = commandMap => {
|
|
|
1191
1206
|
const EditorWorker = {
|
|
1192
1207
|
__proto__: null,
|
|
1193
1208
|
activateByEvent,
|
|
1194
|
-
applyEdit
|
|
1209
|
+
applyEdit,
|
|
1195
1210
|
applyWorkspaceEdit,
|
|
1196
1211
|
closeWidget,
|
|
1197
1212
|
dispose,
|
|
@@ -1215,9 +1230,7 @@ const EditorWorker = {
|
|
|
1215
1230
|
|
|
1216
1231
|
const {
|
|
1217
1232
|
invoke,
|
|
1218
|
-
set
|
|
1219
|
-
applyEdit
|
|
1220
|
-
} = EditorWorker;
|
|
1233
|
+
set} = EditorWorker;
|
|
1221
1234
|
|
|
1222
1235
|
const setSelections = async (editorUid, selections) => {
|
|
1223
1236
|
// @ts-ignore
|
|
@@ -1290,21 +1303,21 @@ const handleBlur = async state => {
|
|
|
1290
1303
|
};
|
|
1291
1304
|
};
|
|
1292
1305
|
|
|
1293
|
-
const
|
|
1294
|
-
return state;
|
|
1295
|
-
};
|
|
1296
|
-
|
|
1297
|
-
const close$1 = async state => {
|
|
1298
|
-
const {
|
|
1299
|
-
editorUid
|
|
1300
|
-
} = state;
|
|
1306
|
+
const escapeRegExpCharacters = value => {
|
|
1301
1307
|
// @ts-ignore
|
|
1302
|
-
|
|
1303
|
-
return state;
|
|
1308
|
+
return RegExp.escape(value);
|
|
1304
1309
|
};
|
|
1305
1310
|
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1311
|
+
const buildRegex = (searchString, options) => {
|
|
1312
|
+
const {
|
|
1313
|
+
matchCase,
|
|
1314
|
+
useRegularExpression,
|
|
1315
|
+
matchWholeWord
|
|
1316
|
+
} = options;
|
|
1317
|
+
const flags = matchCase ? 'g' : 'gi';
|
|
1318
|
+
const pattern = useRegularExpression ? searchString : escapeRegExpCharacters(searchString);
|
|
1319
|
+
const wrapped = matchWholeWord ? `\\b(?:${pattern})\\b` : pattern;
|
|
1320
|
+
return new RegExp(wrapped, flags);
|
|
1308
1321
|
};
|
|
1309
1322
|
|
|
1310
1323
|
const findRegexMatches = (lines, regex) => {
|
|
@@ -1329,22 +1342,11 @@ const findRegexMatches = (lines, regex) => {
|
|
|
1329
1342
|
return new Uint32Array(matches);
|
|
1330
1343
|
};
|
|
1331
1344
|
|
|
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) => {
|
|
1345
|
+
const findMatches = (lines, searchString, options) => {
|
|
1344
1346
|
if (searchString.length === 0) {
|
|
1345
1347
|
return new Uint32Array([]);
|
|
1346
1348
|
}
|
|
1347
|
-
const regex =
|
|
1349
|
+
const regex = buildRegex(searchString, options);
|
|
1348
1350
|
return findRegexMatches(lines, regex);
|
|
1349
1351
|
};
|
|
1350
1352
|
|
|
@@ -1354,9 +1356,17 @@ const getMatchCount = matches => {
|
|
|
1354
1356
|
|
|
1355
1357
|
const refresh$1 = (state, value, inputSource) => {
|
|
1356
1358
|
const {
|
|
1357
|
-
lines
|
|
1359
|
+
lines,
|
|
1360
|
+
matchCase,
|
|
1361
|
+
useRegularExpression,
|
|
1362
|
+
matchWholeWord
|
|
1358
1363
|
} = state;
|
|
1359
|
-
const
|
|
1364
|
+
const options = {
|
|
1365
|
+
matchCase,
|
|
1366
|
+
useRegularExpression,
|
|
1367
|
+
matchWholeWord
|
|
1368
|
+
};
|
|
1369
|
+
const matches = findMatches(lines, value, options);
|
|
1360
1370
|
const matchCount = getMatchCount(matches);
|
|
1361
1371
|
return {
|
|
1362
1372
|
...state,
|
|
@@ -1372,18 +1382,209 @@ const refresh = (state, value = state.value, inputSource = User) => {
|
|
|
1372
1382
|
return refresh$1(state, value, inputSource);
|
|
1373
1383
|
};
|
|
1374
1384
|
|
|
1385
|
+
const toggleMatchCase = state => {
|
|
1386
|
+
const {
|
|
1387
|
+
matchCase
|
|
1388
|
+
} = state;
|
|
1389
|
+
const newState = {
|
|
1390
|
+
...state,
|
|
1391
|
+
matchCase: !matchCase
|
|
1392
|
+
};
|
|
1393
|
+
return refresh(newState, newState.value, User);
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
const toggleMatchWholeWord = state => {
|
|
1397
|
+
const {
|
|
1398
|
+
matchWholeWord
|
|
1399
|
+
} = state;
|
|
1400
|
+
const newState = {
|
|
1401
|
+
...state,
|
|
1402
|
+
matchWholeWord: !matchWholeWord
|
|
1403
|
+
};
|
|
1404
|
+
return refresh(newState, newState.value, User);
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
const togglePreserveCase = state => {
|
|
1408
|
+
const {
|
|
1409
|
+
preserveCase
|
|
1410
|
+
} = state;
|
|
1411
|
+
// TODO update search results
|
|
1412
|
+
return {
|
|
1413
|
+
...state,
|
|
1414
|
+
preserveCase: !preserveCase
|
|
1415
|
+
};
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
const toggleUseRegularExpression = state => {
|
|
1419
|
+
const {
|
|
1420
|
+
useRegularExpression
|
|
1421
|
+
} = state;
|
|
1422
|
+
const newState = {
|
|
1423
|
+
...state,
|
|
1424
|
+
useRegularExpression: !useRegularExpression
|
|
1425
|
+
};
|
|
1426
|
+
return refresh(newState, newState.value, User);
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
const Close$2 = 'Close';
|
|
1430
|
+
const FocusNext = 'FocusNext';
|
|
1431
|
+
const FocusPrevious = 'FocusPrevious';
|
|
1432
|
+
const MatchCase$1 = 'MatchCase';
|
|
1433
|
+
const MatchWholeWord$1 = 'MatchWholeWord';
|
|
1434
|
+
const PreserveCase = 'PreserveCase';
|
|
1435
|
+
const Replace$2 = 'Replace';
|
|
1436
|
+
const ReplaceAll$2 = 'ReplaceAll';
|
|
1437
|
+
const ReplaceValue = 'replace-value';
|
|
1438
|
+
const SearchValue = 'search-value';
|
|
1439
|
+
const ToggleReplace$1 = 'ToggleReplace';
|
|
1440
|
+
const UseRegularExpression$1 = 'UseRegularExpression';
|
|
1441
|
+
|
|
1442
|
+
const applyEdits = async (editorId, edits) => {
|
|
1443
|
+
// @ts-ignore
|
|
1444
|
+
await invoke('Editor.applyDocumentEdits', editorId, edits);
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
|
|
1448
|
+
if (value.length === 0 || matches.length === 0) {
|
|
1449
|
+
return [];
|
|
1450
|
+
}
|
|
1451
|
+
const edits = [];
|
|
1452
|
+
const totalMatches = Math.floor(matches.length / 2);
|
|
1453
|
+
const fromIndex = replaceAll ? 0 : Math.max(0, startIndex);
|
|
1454
|
+
const toIndex = replaceAll ? totalMatches : Math.min(totalMatches, fromIndex + 1);
|
|
1455
|
+
for (let i = fromIndex; i < toIndex; i++) {
|
|
1456
|
+
const rowIndex = matches[i * 2];
|
|
1457
|
+
const startColumnIndex = matches[i * 2 + 1];
|
|
1458
|
+
const endColumnIndex = startColumnIndex + value.length;
|
|
1459
|
+
edits.push({
|
|
1460
|
+
start: {
|
|
1461
|
+
rowIndex,
|
|
1462
|
+
columnIndex: startColumnIndex
|
|
1463
|
+
},
|
|
1464
|
+
end: {
|
|
1465
|
+
rowIndex,
|
|
1466
|
+
columnIndex: endColumnIndex
|
|
1467
|
+
},
|
|
1468
|
+
inserted: [replacement],
|
|
1469
|
+
deleted: [value],
|
|
1470
|
+
origin: 'find-widget.replace'
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
return edits;
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
const replace$1 = async state => {
|
|
1477
|
+
const {
|
|
1478
|
+
matches,
|
|
1479
|
+
value,
|
|
1480
|
+
replacement,
|
|
1481
|
+
matchIndex,
|
|
1482
|
+
editorUid
|
|
1483
|
+
} = state;
|
|
1484
|
+
const edits = getEdits(matches, value, replacement, matchIndex, false);
|
|
1485
|
+
await applyEdits(editorUid, edits);
|
|
1486
|
+
// TODO ask editor worker to apply edit
|
|
1487
|
+
// TODO ask editor worker for new lines?
|
|
1488
|
+
return {
|
|
1489
|
+
...state
|
|
1490
|
+
};
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1493
|
+
const replaceAll$1 = state => {
|
|
1494
|
+
const {
|
|
1495
|
+
matches,
|
|
1496
|
+
value,
|
|
1497
|
+
replacement,
|
|
1498
|
+
editorUid
|
|
1499
|
+
} = state;
|
|
1500
|
+
const edits = getEdits(matches, value, replacement, 0, true);
|
|
1501
|
+
void applyEdits(editorUid, edits);
|
|
1502
|
+
return {
|
|
1503
|
+
...state
|
|
1504
|
+
};
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
const getClickHandler = name => {
|
|
1508
|
+
switch (name) {
|
|
1509
|
+
case Replace$2:
|
|
1510
|
+
return replace$1;
|
|
1511
|
+
case ReplaceAll$2:
|
|
1512
|
+
return replaceAll$1;
|
|
1513
|
+
case MatchCase$1:
|
|
1514
|
+
return toggleMatchCase;
|
|
1515
|
+
case MatchWholeWord$1:
|
|
1516
|
+
return toggleMatchWholeWord;
|
|
1517
|
+
case UseRegularExpression$1:
|
|
1518
|
+
return toggleUseRegularExpression;
|
|
1519
|
+
case PreserveCase:
|
|
1520
|
+
return togglePreserveCase;
|
|
1521
|
+
default:
|
|
1522
|
+
throw new Error(`unexpected click`);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
const handleClickButton = async (state, name) => {
|
|
1527
|
+
const fn = getClickHandler(name);
|
|
1528
|
+
return fn(state);
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
const close$1 = async state => {
|
|
1532
|
+
const {
|
|
1533
|
+
editorUid
|
|
1534
|
+
} = state;
|
|
1535
|
+
// @ts-ignore
|
|
1536
|
+
await invoke('Editor.closeFind2', editorUid);
|
|
1537
|
+
return state;
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
const handleClickClose = state => {
|
|
1541
|
+
return close$1(state);
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1375
1544
|
const handleInput = (state, value, inputSource = User) => {
|
|
1376
1545
|
return refresh(state, value, inputSource);
|
|
1377
1546
|
};
|
|
1378
1547
|
|
|
1379
|
-
const
|
|
1548
|
+
const handleFindWidgetFocus = (state, focusKey) => {
|
|
1549
|
+
if (state.focus === focusKey) {
|
|
1550
|
+
return state;
|
|
1551
|
+
}
|
|
1552
|
+
return {
|
|
1553
|
+
...state,
|
|
1554
|
+
focus: focusKey,
|
|
1555
|
+
focusSource: User$1
|
|
1556
|
+
};
|
|
1557
|
+
};
|
|
1558
|
+
|
|
1559
|
+
const handleReplaceFocus = state => {
|
|
1560
|
+
return handleFindWidgetFocus(state, FocusFindWidgetReplace);
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
const handleResizerPointerDown = async (state, eventX, eventY) => {
|
|
1564
|
+
return {
|
|
1565
|
+
...state,
|
|
1566
|
+
resizerPointerDown: true
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
const handleResizerPointerMove = async (state, eventX, eventY) => {
|
|
1380
1571
|
const {
|
|
1381
|
-
|
|
1572
|
+
width,
|
|
1573
|
+
x
|
|
1382
1574
|
} = state;
|
|
1383
|
-
|
|
1575
|
+
const oldXEnd = x + width;
|
|
1576
|
+
const newWidth = oldXEnd - eventX;
|
|
1384
1577
|
return {
|
|
1385
1578
|
...state,
|
|
1386
|
-
|
|
1579
|
+
x: eventX,
|
|
1580
|
+
width: newWidth
|
|
1581
|
+
};
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
const handleResizerPointerUp = async (state, eventX, eventY) => {
|
|
1585
|
+
return {
|
|
1586
|
+
...state,
|
|
1587
|
+
resizerPointerDown: false
|
|
1387
1588
|
};
|
|
1388
1589
|
};
|
|
1389
1590
|
|
|
@@ -1394,7 +1595,7 @@ const getFindWidgetHeight = replaceExpanded => {
|
|
|
1394
1595
|
return newHeight;
|
|
1395
1596
|
};
|
|
1396
1597
|
|
|
1397
|
-
const toggleReplace = state => {
|
|
1598
|
+
const toggleReplace$1 = state => {
|
|
1398
1599
|
const {
|
|
1399
1600
|
replaceExpanded
|
|
1400
1601
|
} = state;
|
|
@@ -1407,16 +1608,6 @@ const toggleReplace = state => {
|
|
|
1407
1608
|
};
|
|
1408
1609
|
};
|
|
1409
1610
|
|
|
1410
|
-
const toggleUseRegularExpression = state => {
|
|
1411
|
-
const {
|
|
1412
|
-
useRegularExpression
|
|
1413
|
-
} = state;
|
|
1414
|
-
return {
|
|
1415
|
-
...state,
|
|
1416
|
-
useRegularExpression: !useRegularExpression
|
|
1417
|
-
};
|
|
1418
|
-
};
|
|
1419
|
-
|
|
1420
1611
|
const handleReplaceInput = (state, value, inputSource = User) => {
|
|
1421
1612
|
return {
|
|
1422
1613
|
...state,
|
|
@@ -1425,6 +1616,20 @@ const handleReplaceInput = (state, value, inputSource = User) => {
|
|
|
1425
1616
|
};
|
|
1426
1617
|
};
|
|
1427
1618
|
|
|
1619
|
+
const regexFlags = 'gi';
|
|
1620
|
+
const getSearchRegex = searchString => {
|
|
1621
|
+
const escaped = escapeRegExpCharacters(searchString);
|
|
1622
|
+
return new RegExp(escaped, regexFlags);
|
|
1623
|
+
};
|
|
1624
|
+
|
|
1625
|
+
const findMatchesCaseInsensitive = (lines, searchString) => {
|
|
1626
|
+
if (searchString.length === 0) {
|
|
1627
|
+
return new Uint32Array([]);
|
|
1628
|
+
}
|
|
1629
|
+
const regex = getSearchRegex(searchString);
|
|
1630
|
+
return findRegexMatches(lines, regex);
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1428
1633
|
const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
|
|
1429
1634
|
const width = 300;
|
|
1430
1635
|
const height = 30;
|
|
@@ -1523,19 +1728,24 @@ const renderBounds = (oldState, newState) => {
|
|
|
1523
1728
|
};
|
|
1524
1729
|
|
|
1525
1730
|
const HandleBlur = 'handleBlur';
|
|
1731
|
+
const HandleClickButton = 'handleClickButton';
|
|
1526
1732
|
const HandleClickClose = 'handleClickClose';
|
|
1527
1733
|
const HandleClickNextMatch = 'handleClickNextMatch';
|
|
1528
1734
|
const HandleClickPreviousMatch = 'handleClickPreviousMatch';
|
|
1529
1735
|
const HandleClickReplace = 'handleClickReplace';
|
|
1530
|
-
const HandleClickToggleReplace = 'handleClickToggleReplace';
|
|
1531
1736
|
const HandleClickReplaceAll = 'handleClickReplaceAll';
|
|
1532
|
-
const
|
|
1737
|
+
const HandleClickToggleReplace = 'handleClickToggleReplace';
|
|
1533
1738
|
const HandleFocus = 'handleFocus';
|
|
1739
|
+
const HandleFocusNext = 'handleFocusNext';
|
|
1740
|
+
const HandleFocusPrevious = 'handleFocusPrevious';
|
|
1534
1741
|
const HandleInput = 'handleInput';
|
|
1535
1742
|
const HandleReplaceFocus = 'handleReplaceFocus';
|
|
1536
|
-
const HandleFocusPrevious = 'handleFocusPrevious';
|
|
1537
|
-
const HandleFocusNext = 'handleFocusNext';
|
|
1538
1743
|
const HandleReplaceInput = 'handleReplaceInput';
|
|
1744
|
+
const HandleResizerPointerDown = 'handleResizerPointerDown';
|
|
1745
|
+
const HandleResizerPointerMove = 'handleResizerPointerMove';
|
|
1746
|
+
const HandleResizerPointerUp = 'handleResizerPointerUp';
|
|
1747
|
+
const HandleSliderPointerMove = 'handleSliderPointerMove';
|
|
1748
|
+
const HandleToggleReplaceFocus = 'handleToggleReplaceFocus';
|
|
1539
1749
|
|
|
1540
1750
|
const emptyObject = {};
|
|
1541
1751
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
@@ -1551,12 +1761,13 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1551
1761
|
|
|
1552
1762
|
const MatchOf = '{PH1} of {PH2}';
|
|
1553
1763
|
const NoResults = 'No Results';
|
|
1554
|
-
const Close$
|
|
1764
|
+
const Close$1 = 'Close';
|
|
1555
1765
|
const PreviousMatch = 'Previous Match';
|
|
1556
1766
|
const NextMatch = 'Next Match';
|
|
1557
1767
|
const Find$1 = 'Find';
|
|
1558
|
-
const Replace$
|
|
1559
|
-
const ReplaceAll$
|
|
1768
|
+
const Replace$1 = 'Replace';
|
|
1769
|
+
const ReplaceAll$1 = 'Replace All';
|
|
1770
|
+
const ToggleReplace = 'Toggle Replace';
|
|
1560
1771
|
|
|
1561
1772
|
const noResults = () => {
|
|
1562
1773
|
return i18nString(NoResults);
|
|
@@ -1574,38 +1785,29 @@ const nextMatch = () => {
|
|
|
1574
1785
|
return i18nString(NextMatch);
|
|
1575
1786
|
};
|
|
1576
1787
|
const close = () => {
|
|
1577
|
-
return i18nString(Close$
|
|
1788
|
+
return i18nString(Close$1);
|
|
1578
1789
|
};
|
|
1579
1790
|
const find = () => {
|
|
1580
1791
|
return i18nString(Find$1);
|
|
1581
1792
|
};
|
|
1582
|
-
const replace
|
|
1583
|
-
return i18nString(Replace$
|
|
1793
|
+
const replace = () => {
|
|
1794
|
+
return i18nString(Replace$1);
|
|
1795
|
+
};
|
|
1796
|
+
const replaceAll = () => {
|
|
1797
|
+
return i18nString(ReplaceAll$1);
|
|
1584
1798
|
};
|
|
1585
|
-
const
|
|
1586
|
-
return i18nString(
|
|
1799
|
+
const toggleReplace = () => {
|
|
1800
|
+
return i18nString(ToggleReplace);
|
|
1587
1801
|
};
|
|
1588
1802
|
|
|
1589
|
-
const MatchCase
|
|
1590
|
-
const UseRegularExpression
|
|
1591
|
-
const MatchWholeWord
|
|
1803
|
+
const MatchCase = 'CaseSensitive';
|
|
1804
|
+
const UseRegularExpression = 'Regex';
|
|
1805
|
+
const MatchWholeWord = 'WholeWord';
|
|
1592
1806
|
const ArrowDown = 'ArrowDown';
|
|
1593
1807
|
const ArrowUp = 'ArrowUp';
|
|
1594
|
-
const Close$1 = 'Close';
|
|
1595
|
-
const Replace$1 = 'Replace';
|
|
1596
|
-
const ReplaceAll$1 = 'ReplaceAll';
|
|
1597
|
-
|
|
1598
1808
|
const Close = 'Close';
|
|
1599
|
-
const FocusNext = 'FocusNext';
|
|
1600
|
-
const FocusPrevious = 'FocusPrevious';
|
|
1601
|
-
const MatchCase = 'MatchCase';
|
|
1602
|
-
const MatchWholeWord = 'MatchWholeWord';
|
|
1603
1809
|
const Replace = 'Replace';
|
|
1604
1810
|
const ReplaceAll = 'ReplaceAll';
|
|
1605
|
-
const ReplaceValue = 'replace-value';
|
|
1606
|
-
const SearchValue = 'search-value';
|
|
1607
|
-
const ToggleReplace = 'ToggleReplace';
|
|
1608
|
-
const UseRegularExpression = 'UseRegularExpression';
|
|
1609
1811
|
|
|
1610
1812
|
const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
|
|
1611
1813
|
const findButtons = [{
|
|
@@ -1622,23 +1824,23 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
|
|
|
1622
1824
|
name: FocusNext
|
|
1623
1825
|
}, {
|
|
1624
1826
|
label: close(),
|
|
1625
|
-
icon: Close
|
|
1827
|
+
icon: Close,
|
|
1626
1828
|
disabled: false,
|
|
1627
1829
|
onClick: HandleClickClose,
|
|
1628
|
-
name: Close
|
|
1830
|
+
name: Close$2
|
|
1629
1831
|
}];
|
|
1630
1832
|
const replaceButtons = [{
|
|
1631
|
-
label: replace
|
|
1632
|
-
icon: Replace
|
|
1833
|
+
label: replace(),
|
|
1834
|
+
icon: Replace,
|
|
1633
1835
|
disabled: !replaceButtonsEnabled,
|
|
1634
1836
|
onClick: HandleClickReplace,
|
|
1635
|
-
name: Replace
|
|
1837
|
+
name: Replace$2
|
|
1636
1838
|
}, {
|
|
1637
|
-
label: replaceAll
|
|
1638
|
-
icon: ReplaceAll
|
|
1839
|
+
label: replaceAll(),
|
|
1840
|
+
icon: ReplaceAll,
|
|
1639
1841
|
disabled: !replaceButtonsEnabled,
|
|
1640
1842
|
onClick: HandleClickReplaceAll,
|
|
1641
|
-
name: ReplaceAll
|
|
1843
|
+
name: ReplaceAll$2
|
|
1642
1844
|
}];
|
|
1643
1845
|
return {
|
|
1644
1846
|
findButtons,
|
|
@@ -1667,10 +1869,6 @@ const text = data => {
|
|
|
1667
1869
|
};
|
|
1668
1870
|
};
|
|
1669
1871
|
|
|
1670
|
-
const CheckBox = 'checkbox';
|
|
1671
|
-
const Group = 'group';
|
|
1672
|
-
const None = 'none';
|
|
1673
|
-
|
|
1674
1872
|
const FindWidgetFind = 'FindWidgetFind';
|
|
1675
1873
|
const FindWidgetMatchCount = 'FindWidgetMatchCount';
|
|
1676
1874
|
const FindWidgetMatchCountEmpty = 'FindWidgetMatchCountEmpty';
|
|
@@ -1692,19 +1890,22 @@ const ViewletFindWidget = 'ViewletFindWidget';
|
|
|
1692
1890
|
const getFindButtons = () => {
|
|
1693
1891
|
return [{
|
|
1694
1892
|
checked: false,
|
|
1695
|
-
icon: MatchCase
|
|
1893
|
+
icon: MatchCase,
|
|
1696
1894
|
title: 'Match Case',
|
|
1697
|
-
name: MatchCase
|
|
1895
|
+
name: MatchCase$1,
|
|
1896
|
+
onClick: HandleClickButton
|
|
1698
1897
|
}, {
|
|
1699
1898
|
checked: false,
|
|
1700
|
-
icon: MatchWholeWord
|
|
1899
|
+
icon: MatchWholeWord,
|
|
1701
1900
|
title: 'Match Whole Word',
|
|
1702
|
-
name: MatchWholeWord
|
|
1901
|
+
name: MatchWholeWord$1,
|
|
1902
|
+
onClick: HandleClickButton
|
|
1703
1903
|
}, {
|
|
1704
1904
|
checked: false,
|
|
1705
|
-
icon: UseRegularExpression
|
|
1905
|
+
icon: UseRegularExpression,
|
|
1706
1906
|
title: 'Use Regular Expression',
|
|
1707
|
-
name: UseRegularExpression
|
|
1907
|
+
name: UseRegularExpression$1,
|
|
1908
|
+
onClick: HandleClickButton
|
|
1708
1909
|
}];
|
|
1709
1910
|
};
|
|
1710
1911
|
|
|
@@ -1752,16 +1953,20 @@ const getSearchFieldButtonVirtualDom = button => {
|
|
|
1752
1953
|
const {
|
|
1753
1954
|
icon,
|
|
1754
1955
|
checked,
|
|
1755
|
-
title
|
|
1956
|
+
title,
|
|
1957
|
+
name,
|
|
1958
|
+
onClick
|
|
1756
1959
|
} = button;
|
|
1757
1960
|
return [{
|
|
1758
1961
|
type: Div,
|
|
1962
|
+
ariaChecked: checked,
|
|
1759
1963
|
className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
|
|
1760
|
-
|
|
1964
|
+
name,
|
|
1761
1965
|
role: CheckBox,
|
|
1762
|
-
ariaChecked: checked,
|
|
1763
1966
|
tabIndex: 0,
|
|
1764
|
-
|
|
1967
|
+
title,
|
|
1968
|
+
childCount: 1,
|
|
1969
|
+
onClick
|
|
1765
1970
|
}, {
|
|
1766
1971
|
type: Div,
|
|
1767
1972
|
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
@@ -1821,23 +2026,39 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
|
|
|
1821
2026
|
type: Div,
|
|
1822
2027
|
className: FindWidgetReplace,
|
|
1823
2028
|
childCount: 1 + replaceButtons.length
|
|
1824
|
-
}, ...getSearchFieldVirtualDom(ReplaceValue, replace
|
|
2029
|
+
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
|
|
1825
2030
|
}
|
|
1826
2031
|
return dom;
|
|
1827
2032
|
};
|
|
1828
2033
|
|
|
2034
|
+
const getResizerVirtualDom = () => {
|
|
2035
|
+
return [{
|
|
2036
|
+
type: Div,
|
|
2037
|
+
className: 'Resizer',
|
|
2038
|
+
childCount: 1,
|
|
2039
|
+
onPointerDown: HandleResizerPointerDown,
|
|
2040
|
+
onPointerMove: HandleResizerPointerUp,
|
|
2041
|
+
onPointerUp: HandleResizerPointerMove
|
|
2042
|
+
}, {
|
|
2043
|
+
type: Div,
|
|
2044
|
+
className: 'ResizerHighlight',
|
|
2045
|
+
childCount: 0
|
|
2046
|
+
}];
|
|
2047
|
+
};
|
|
2048
|
+
|
|
1829
2049
|
const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
|
|
2050
|
+
const title = toggleReplace();
|
|
1830
2051
|
return [{
|
|
1831
2052
|
type: Button,
|
|
1832
2053
|
className: `IconButton SearchToggleButton ${replaceExpanded ? 'SearchToggleButtonExpanded' : ''}`,
|
|
1833
|
-
title
|
|
1834
|
-
ariaLabel:
|
|
2054
|
+
title,
|
|
2055
|
+
ariaLabel: title,
|
|
1835
2056
|
ariaExpanded: replaceExpanded,
|
|
1836
|
-
name: ToggleReplace,
|
|
2057
|
+
name: ToggleReplace$1,
|
|
1837
2058
|
childCount: 1,
|
|
1838
2059
|
'data-command': 'toggleReplace',
|
|
1839
2060
|
onClick,
|
|
1840
|
-
onFocus:
|
|
2061
|
+
onFocus: HandleToggleReplaceFocus
|
|
1841
2062
|
}, {
|
|
1842
2063
|
type: Div,
|
|
1843
2064
|
className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
|
|
@@ -1850,9 +2071,10 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, r
|
|
|
1850
2071
|
dom.push({
|
|
1851
2072
|
type: Div,
|
|
1852
2073
|
className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
|
|
1853
|
-
childCount:
|
|
2074
|
+
childCount: 3,
|
|
1854
2075
|
role: Group
|
|
1855
2076
|
});
|
|
2077
|
+
dom.push(...getResizerVirtualDom());
|
|
1856
2078
|
dom.push(...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'));
|
|
1857
2079
|
dom.push({
|
|
1858
2080
|
type: Div,
|
|
@@ -1890,6 +2112,23 @@ const renderContent = (oldState, newState) => {
|
|
|
1890
2112
|
return [SetDom2, uid, dom];
|
|
1891
2113
|
};
|
|
1892
2114
|
|
|
2115
|
+
const renderCss = (oldState, newState) => {
|
|
2116
|
+
const {
|
|
2117
|
+
uid,
|
|
2118
|
+
width,
|
|
2119
|
+
height,
|
|
2120
|
+
x,
|
|
2121
|
+
y
|
|
2122
|
+
} = newState;
|
|
2123
|
+
const css = `:root {
|
|
2124
|
+
--FindWidgetWidth: ${width}px;
|
|
2125
|
+
--FindWidgetHeight: ${height}px;
|
|
2126
|
+
--FindWidgetX: ${x}px;
|
|
2127
|
+
--FindWidgetY: ${y}px;
|
|
2128
|
+
}`;
|
|
2129
|
+
return [SetCss, uid, css];
|
|
2130
|
+
};
|
|
2131
|
+
|
|
1893
2132
|
const getEventListeners = (uid, widgetId) => {
|
|
1894
2133
|
return [{
|
|
1895
2134
|
name: HandleInput,
|
|
@@ -1933,6 +2172,16 @@ const getEventListeners = (uid, widgetId) => {
|
|
|
1933
2172
|
}, {
|
|
1934
2173
|
name: HandleClickButton,
|
|
1935
2174
|
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, `event.target.name`]
|
|
2175
|
+
}, {
|
|
2176
|
+
name: HandleResizerPointerDown,
|
|
2177
|
+
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleResizerPointerDown', 0, widgetId, ClientX, ClientY],
|
|
2178
|
+
trackPointerEvents: [HandleResizerPointerMove, HandleResizerPointerUp]
|
|
2179
|
+
}, {
|
|
2180
|
+
name: HandleSliderPointerMove,
|
|
2181
|
+
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleResizerPointerMove', 0, widgetId, ClientX, ClientY]
|
|
2182
|
+
}, {
|
|
2183
|
+
name: HandleResizerPointerUp,
|
|
2184
|
+
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleResizerPointerUp', 0, widgetId, ClientX, ClientY]
|
|
1936
2185
|
}];
|
|
1937
2186
|
};
|
|
1938
2187
|
|
|
@@ -1964,7 +2213,7 @@ const renderReplaceValue = (oldState, newState) => {
|
|
|
1964
2213
|
uid,
|
|
1965
2214
|
replacement
|
|
1966
2215
|
} = newState;
|
|
1967
|
-
return [SetValueByName, uid, Replace, replacement];
|
|
2216
|
+
return [SetValueByName, uid, Replace$2, replacement];
|
|
1968
2217
|
};
|
|
1969
2218
|
|
|
1970
2219
|
const renderUid = (oldState, newState) => {
|
|
@@ -2001,6 +2250,8 @@ const getRenderer = diffType => {
|
|
|
2001
2250
|
return renderValue;
|
|
2002
2251
|
case RenderReplaceValue:
|
|
2003
2252
|
return renderReplaceValue;
|
|
2253
|
+
case RenderCss:
|
|
2254
|
+
return renderCss;
|
|
2004
2255
|
default:
|
|
2005
2256
|
throw new Error('unknown renderer');
|
|
2006
2257
|
}
|
|
@@ -2025,61 +2276,8 @@ const render2 = (uid, diffResult) => {
|
|
|
2025
2276
|
return commands;
|
|
2026
2277
|
};
|
|
2027
2278
|
|
|
2028
|
-
const
|
|
2029
|
-
|
|
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
|
-
};
|
|
2279
|
+
const resize = async (state, dimensions) => {
|
|
2280
|
+
return state;
|
|
2083
2281
|
};
|
|
2084
2282
|
|
|
2085
2283
|
const commandMap = {
|
|
@@ -2090,24 +2288,29 @@ const commandMap = {
|
|
|
2090
2288
|
'FindWidget.focusFirst': wrapCommand(focusFirst),
|
|
2091
2289
|
'FindWidget.focusIndex': wrapCommand(focusIndex),
|
|
2092
2290
|
'FindWidget.focusLast': wrapCommand(focusLast),
|
|
2093
|
-
'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
|
|
2094
2291
|
'FindWidget.focusNext': wrapCommand(focusNext),
|
|
2095
2292
|
'FindWidget.focusPrevious': wrapCommand(focusPrevious),
|
|
2096
2293
|
'FindWidget.focusReplace': wrapCommand(focusReplace),
|
|
2097
2294
|
'FindWidget.focusReplaceAllButton': wrapCommand(focusReplaceAllButton),
|
|
2098
2295
|
'FindWidget.getCommandIds': getCommandIds,
|
|
2099
2296
|
'FindWidget.handleBlur': wrapCommand(handleBlur),
|
|
2297
|
+
'FindWidget.handleClickButton': wrapCommand(handleClickButton),
|
|
2100
2298
|
'FindWidget.handleClickClose': wrapCommand(handleClickClose),
|
|
2101
2299
|
'FindWidget.handleInput': wrapCommand(handleInput),
|
|
2300
|
+
'FindWidget.handleReplaceFocus': wrapCommand(handleReplaceFocus),
|
|
2102
2301
|
'FindWidget.handleReplaceInput': wrapCommand(handleReplaceInput),
|
|
2302
|
+
'FindWidget.handleResizerPointerDown': wrapCommand(handleResizerPointerDown),
|
|
2303
|
+
'FindWidget.handleResizerPointerMove': wrapCommand(handleResizerPointerMove),
|
|
2304
|
+
'FindWidget.handleResizerPointerUp': wrapCommand(handleResizerPointerUp),
|
|
2103
2305
|
'FindWidget.loadContent': wrapCommand(loadContent),
|
|
2104
2306
|
'FindWidget.preventDefaultBrowserFind': wrapCommand(preventDefaultBrowserFind),
|
|
2105
2307
|
'FindWidget.render2': render2,
|
|
2308
|
+
'FindWidget.replace': wrapCommand(replace$1),
|
|
2309
|
+
'FindWidget.replaceAll': wrapCommand(replaceAll$1),
|
|
2310
|
+
'FindWidget.resize': wrapCommand(resize),
|
|
2106
2311
|
'FindWidget.terminate': terminate,
|
|
2107
|
-
'FindWidget.
|
|
2108
|
-
'FindWidget.
|
|
2109
|
-
'FindWidget.replaceAll': wrapCommand(replaceAll),
|
|
2110
|
-
'FindWidget.handleClickButton': wrapCommand(handleClickButton),
|
|
2312
|
+
'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
|
|
2313
|
+
'FindWidget.toggleReplace': wrapCommand(toggleReplace$1),
|
|
2111
2314
|
'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
|
|
2112
2315
|
};
|
|
2113
2316
|
|