@lvce-editor/find-widget-worker 2.4.0 → 2.5.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 +75 -20
- package/package.json +1 -1
|
@@ -1222,7 +1222,7 @@ const isEqual$4 = (oldState, newState) => {
|
|
|
1222
1222
|
};
|
|
1223
1223
|
|
|
1224
1224
|
const isEqual$3 = (oldState, newState) => {
|
|
1225
|
-
return oldState.
|
|
1225
|
+
return oldState.inputErrorMessage === newState.inputErrorMessage && oldState.matchCase === newState.matchCase && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex && oldState.matchWholeWord === newState.matchWholeWord && oldState.preserveCase === newState.preserveCase && oldState.replaceExpanded === newState.replaceExpanded && oldState.useRegularExpression === newState.useRegularExpression && oldState.version === newState.version;
|
|
1226
1226
|
};
|
|
1227
1227
|
|
|
1228
1228
|
const isEqual$2 = (oldState, newState) => {
|
|
@@ -1422,8 +1422,15 @@ const findMatches = (lines, searchString, options) => {
|
|
|
1422
1422
|
};
|
|
1423
1423
|
}
|
|
1424
1424
|
const {
|
|
1425
|
-
regex
|
|
1425
|
+
regex,
|
|
1426
|
+
error
|
|
1426
1427
|
} = buildRegex(searchString, options);
|
|
1428
|
+
if (error) {
|
|
1429
|
+
return {
|
|
1430
|
+
matches: new Uint32Array([]),
|
|
1431
|
+
error
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1427
1434
|
const matches = findRegexMatches(lines, regex);
|
|
1428
1435
|
return {
|
|
1429
1436
|
matches,
|
|
@@ -1573,7 +1580,46 @@ const applyEdits = async (editorId, edits) => {
|
|
|
1573
1580
|
await invoke('Editor.applyDocumentEdits', editorId, edits);
|
|
1574
1581
|
};
|
|
1575
1582
|
|
|
1576
|
-
|
|
1583
|
+
/**
|
|
1584
|
+
* Preserves the case pattern of the original text when replacing.
|
|
1585
|
+
* Supports uppercase, lowercase, PascalCase, and camelCase patterns.
|
|
1586
|
+
*/
|
|
1587
|
+
const preserveCase$1 = (originalText, replacementText) => {
|
|
1588
|
+
if (originalText.length === 0 || replacementText.length === 0) {
|
|
1589
|
+
return replacementText;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// Check if original text is all uppercase
|
|
1593
|
+
if (originalText === originalText.toUpperCase()) {
|
|
1594
|
+
return replacementText.toUpperCase();
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// Check if original text is all lowercase
|
|
1598
|
+
if (originalText === originalText.toLowerCase()) {
|
|
1599
|
+
return replacementText.toLowerCase();
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// Check if original text is PascalCase (first letter uppercase, rest lowercase or mixed)
|
|
1603
|
+
if (originalText[0] === originalText[0].toUpperCase()) {
|
|
1604
|
+
// Check if it's pure PascalCase (first uppercase, rest lowercase)
|
|
1605
|
+
const restOfText = originalText.slice(1);
|
|
1606
|
+
if (restOfText === restOfText.toLowerCase()) {
|
|
1607
|
+
return replacementText[0].toUpperCase() + replacementText.slice(1).toLowerCase();
|
|
1608
|
+
}
|
|
1609
|
+
// Mixed case - preserve the pattern as much as possible
|
|
1610
|
+
return replacementText[0].toUpperCase() + replacementText.slice(1).toLowerCase();
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// Check if original text is camelCase (first letter lowercase, rest mixed)
|
|
1614
|
+
if (originalText[0] === originalText[0].toLowerCase()) {
|
|
1615
|
+
return replacementText[0].toLowerCase() + replacementText.slice(1).toLowerCase();
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// Default fallback - return replacement as-is
|
|
1619
|
+
return replacementText;
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, preserveCaseOption = false) => {
|
|
1577
1623
|
if (value.length === 0 || matches.length === 0) {
|
|
1578
1624
|
return [];
|
|
1579
1625
|
}
|
|
@@ -1586,6 +1632,12 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) =>
|
|
|
1586
1632
|
const startColumnIndex = matches[i * 2 + 1];
|
|
1587
1633
|
const endColumnIndex = startColumnIndex + value.length;
|
|
1588
1634
|
|
|
1635
|
+
// Get the original text that was matched
|
|
1636
|
+
const originalText = lines[rowIndex].slice(startColumnIndex, endColumnIndex);
|
|
1637
|
+
|
|
1638
|
+
// Apply case preservation if enabled
|
|
1639
|
+
const finalReplacement = preserveCaseOption ? preserveCase$1(originalText, replacement) : replacement;
|
|
1640
|
+
|
|
1589
1641
|
// Convert row/column positions to character offsets
|
|
1590
1642
|
let startOffset = 0;
|
|
1591
1643
|
for (let row = 0; row < rowIndex; row++) {
|
|
@@ -1600,7 +1652,7 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) =>
|
|
|
1600
1652
|
edits.push({
|
|
1601
1653
|
startOffset,
|
|
1602
1654
|
endOffset,
|
|
1603
|
-
inserted:
|
|
1655
|
+
inserted: finalReplacement,
|
|
1604
1656
|
origin: 'find-widget.replace'
|
|
1605
1657
|
});
|
|
1606
1658
|
}
|
|
@@ -1614,9 +1666,10 @@ const replace$1 = async state => {
|
|
|
1614
1666
|
replacement,
|
|
1615
1667
|
matchIndex,
|
|
1616
1668
|
editorUid,
|
|
1617
|
-
lines
|
|
1669
|
+
lines,
|
|
1670
|
+
preserveCase
|
|
1618
1671
|
} = state;
|
|
1619
|
-
const edits = getEdits(matches, value, replacement, matchIndex, false, lines);
|
|
1672
|
+
const edits = getEdits(matches, value, replacement, matchIndex, false, lines, preserveCase);
|
|
1620
1673
|
await applyEdits(editorUid, edits);
|
|
1621
1674
|
// TODO ask editor worker to apply edit
|
|
1622
1675
|
// TODO ask editor worker for new lines?
|
|
@@ -1631,9 +1684,10 @@ const replaceAll$1 = state => {
|
|
|
1631
1684
|
value,
|
|
1632
1685
|
replacement,
|
|
1633
1686
|
editorUid,
|
|
1634
|
-
lines
|
|
1687
|
+
lines,
|
|
1688
|
+
preserveCase
|
|
1635
1689
|
} = state;
|
|
1636
|
-
const edits = getEdits(matches, value, replacement, 0, true, lines);
|
|
1690
|
+
const edits = getEdits(matches, value, replacement, 0, true, lines, preserveCase);
|
|
1637
1691
|
void applyEdits(editorUid, edits);
|
|
1638
1692
|
return {
|
|
1639
1693
|
...state
|
|
@@ -2270,6 +2324,7 @@ const text = data => {
|
|
|
2270
2324
|
};
|
|
2271
2325
|
};
|
|
2272
2326
|
|
|
2327
|
+
const FindWidget = 'FindWidget';
|
|
2273
2328
|
const FindWidgetFind = 'FindWidgetFind';
|
|
2274
2329
|
const FindWidgetMatchCount = 'FindWidgetMatchCount';
|
|
2275
2330
|
const FindWidgetMatchCountEmpty = 'FindWidgetMatchCountEmpty';
|
|
@@ -2278,21 +2333,21 @@ const FindWidgetRight = 'FindWidgetRight';
|
|
|
2278
2333
|
const IconButton = 'IconButton';
|
|
2279
2334
|
const IconButtonDisabled = 'IconButtonDisabled';
|
|
2280
2335
|
const MaskIcon = 'MaskIcon';
|
|
2336
|
+
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
2337
|
+
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
2281
2338
|
const MultilineInputBox = 'MultilineInputBox';
|
|
2339
|
+
const Resizer = 'Resizer';
|
|
2340
|
+
const ResizerHighlight = 'ResizerHighlight';
|
|
2282
2341
|
const SearchField = 'SearchField';
|
|
2283
2342
|
const SearchFieldButton = 'SearchFieldButton';
|
|
2284
2343
|
const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
|
|
2285
2344
|
const SearchFieldButtons = 'SearchFieldButtons';
|
|
2345
|
+
const SearchFieldError = 'SearchFieldError';
|
|
2346
|
+
const SearchToggleButton = 'SearchToggleButton';
|
|
2347
|
+
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
2286
2348
|
const Viewlet = 'Viewlet';
|
|
2287
2349
|
const ViewletFind = 'ViewletFind';
|
|
2288
|
-
const FindWidget = 'FindWidget';
|
|
2289
2350
|
const ViewletFindWidget = 'ViewletFindWidget';
|
|
2290
|
-
const Resizer = 'Resizer';
|
|
2291
|
-
const ResizerHighlight = 'ResizerHighlight';
|
|
2292
|
-
const SearchToggleButton = 'SearchToggleButton';
|
|
2293
|
-
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
2294
|
-
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
2295
|
-
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
2296
2351
|
|
|
2297
2352
|
const getIconVirtualDom = (icon, type = Div) => {
|
|
2298
2353
|
return {
|
|
@@ -2370,15 +2425,15 @@ const getSearchFieldButtonVirtualDom = button => {
|
|
|
2370
2425
|
}];
|
|
2371
2426
|
};
|
|
2372
2427
|
|
|
2373
|
-
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus
|
|
2428
|
+
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus, extraClassName) => {
|
|
2374
2429
|
const dom = [{
|
|
2375
2430
|
type: Div,
|
|
2376
|
-
className: SearchField,
|
|
2431
|
+
className: mergeClassNames(SearchField, extraClassName),
|
|
2377
2432
|
role: None,
|
|
2378
2433
|
childCount: 2
|
|
2379
2434
|
}, {
|
|
2380
2435
|
type: TextArea,
|
|
2381
|
-
className:
|
|
2436
|
+
className: MultilineInputBox,
|
|
2382
2437
|
spellcheck: false,
|
|
2383
2438
|
autocapitalize: 'off',
|
|
2384
2439
|
autocorrect: 'off',
|
|
@@ -2399,7 +2454,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
2399
2454
|
};
|
|
2400
2455
|
|
|
2401
2456
|
const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, hasValue, hasError) => {
|
|
2402
|
-
const extraClassName = hasError ?
|
|
2457
|
+
const extraClassName = hasError ? SearchFieldError : '';
|
|
2403
2458
|
return [{
|
|
2404
2459
|
type: Div,
|
|
2405
2460
|
className: FindWidgetFind,
|
|
@@ -2419,7 +2474,7 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replace
|
|
|
2419
2474
|
type: Div,
|
|
2420
2475
|
className: FindWidgetReplace,
|
|
2421
2476
|
childCount: 1 + replaceButtons.length
|
|
2422
|
-
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
|
|
2477
|
+
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus, ''), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
|
|
2423
2478
|
};
|
|
2424
2479
|
|
|
2425
2480
|
const getResizerVirtualDom = () => {
|