@lvce-editor/find-widget-worker 2.4.0 → 2.6.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.
@@ -1222,7 +1222,7 @@ const isEqual$4 = (oldState, newState) => {
1222
1222
  };
1223
1223
 
1224
1224
  const isEqual$3 = (oldState, newState) => {
1225
- return oldState.version === newState.version && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex && oldState.matchCase === newState.matchCase && oldState.matchWholeWord === newState.matchWholeWord && oldState.useRegularExpression === newState.useRegularExpression && oldState.preserveCase === newState.preserveCase;
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
- const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) => {
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: replacement,
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,22 @@ 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 SearchFieldFocused = 'SearchFieldFocused';
2347
+ const SearchToggleButton = 'SearchToggleButton';
2348
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
2286
2349
  const Viewlet = 'Viewlet';
2287
2350
  const ViewletFind = 'ViewletFind';
2288
- const FindWidget = 'FindWidget';
2289
2351
  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
2352
 
2297
2353
  const getIconVirtualDom = (icon, type = Div) => {
2298
2354
  return {
@@ -2370,15 +2426,15 @@ const getSearchFieldButtonVirtualDom = button => {
2370
2426
  }];
2371
2427
  };
2372
2428
 
2373
- const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '', extraClassName = '') => {
2429
+ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus, extraClassName) => {
2374
2430
  const dom = [{
2375
2431
  type: Div,
2376
- className: SearchField,
2432
+ className: mergeClassNames(SearchField, extraClassName),
2377
2433
  role: None,
2378
2434
  childCount: 2
2379
2435
  }, {
2380
2436
  type: TextArea,
2381
- className: mergeClassNames(MultilineInputBox, extraClassName),
2437
+ className: MultilineInputBox,
2382
2438
  spellcheck: false,
2383
2439
  autocapitalize: 'off',
2384
2440
  autocorrect: 'off',
@@ -2398,8 +2454,17 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2398
2454
  return dom;
2399
2455
  };
2400
2456
 
2401
- const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, hasValue, hasError) => {
2402
- const extraClassName = hasError ? `InputValidationError` : '';
2457
+ const getExtraClassName = (hasError, inputFocused) => {
2458
+ if (hasError) {
2459
+ return SearchFieldError;
2460
+ }
2461
+ if (inputFocused) {
2462
+ return SearchFieldFocused;
2463
+ }
2464
+ return '';
2465
+ };
2466
+ const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, hasValue, hasError, inputFocused) => {
2467
+ const extraClassName = getExtraClassName(hasError, inputFocused);
2403
2468
  return [{
2404
2469
  type: Div,
2405
2470
  className: FindWidgetFind,
@@ -2411,15 +2476,16 @@ const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matc
2411
2476
  }, ...getMatchCountVirtualDom(matchCountText, matchCount, hasValue), ...buttons.flatMap(getIconButtonVirtualDom)];
2412
2477
  };
2413
2478
 
2414
- const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replaceFieldButtons) => {
2479
+ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replaceFieldButtons, replaceInputFocused) => {
2415
2480
  if (!replaceExpanded) {
2416
2481
  return [];
2417
2482
  }
2483
+ const extraClassName = replaceInputFocused ? SearchFieldFocused : '';
2418
2484
  return [{
2419
2485
  type: Div,
2420
2486
  className: FindWidgetReplace,
2421
2487
  childCount: 1 + replaceButtons.length
2422
- }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
2488
+ }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus, extraClassName), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
2423
2489
  };
2424
2490
 
2425
2491
  const getResizerVirtualDom = () => {
@@ -2461,12 +2527,12 @@ const parentNode = {
2461
2527
  childCount: 3,
2462
2528
  role: Group
2463
2529
  };
2464
- const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError) => {
2530
+ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError, inputFocused, replaceInputFocused) => {
2465
2531
  return [parentNode, ...getResizerVirtualDom(), ...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'), {
2466
2532
  type: Div,
2467
2533
  className: FindWidgetRight,
2468
2534
  childCount: replaceExpanded ? 2 : 1
2469
- }, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, Boolean(value), hasError), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons)];
2535
+ }, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, Boolean(value), hasError, inputFocused), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons, replaceFieldButtons, replaceInputFocused)];
2470
2536
  };
2471
2537
 
2472
2538
  const getMatchCountText = (matchIndex, matchCount) => {
@@ -2478,6 +2544,7 @@ const getMatchCountText = (matchIndex, matchCount) => {
2478
2544
 
2479
2545
  const renderContent = (oldState, newState) => {
2480
2546
  const {
2547
+ focus,
2481
2548
  uid,
2482
2549
  matchCount,
2483
2550
  value,
@@ -2500,7 +2567,9 @@ const renderContent = (oldState, newState) => {
2500
2567
  replaceFieldButtons
2501
2568
  } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled, matchCase, matchWholeWord, useRegularExpression, preserveCase);
2502
2569
  const hasError = Boolean(inputErrorMessage);
2503
- const dom = getFindWidgetVirtualDom(matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError);
2570
+ const inputFocused = focus === FocusSearchInput;
2571
+ const replaceInputFocused = focus === FocusSearchReplaceInput;
2572
+ const dom = getFindWidgetVirtualDom(matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError, inputFocused, replaceInputFocused);
2504
2573
  return [SetDom2, uid, dom];
2505
2574
  };
2506
2575
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",