@lvce-editor/find-widget-worker 2.0.0 → 2.2.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.
@@ -997,44 +997,34 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
997
997
  return state;
998
998
  };
999
999
 
1000
- const isEqual$7 = (oldState, newState) => {
1000
+ const isEqual$8 = (oldState, newState) => {
1001
1001
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
1002
1002
  };
1003
1003
 
1004
- const isEqual$6 = (oldState, newState) => {
1004
+ const isEqual$7 = (oldState, newState) => {
1005
1005
  return newState.width === newState.width && oldState.height === newState.height && oldState.x === newState.x && oldState.inputHeight === newState.inputHeight;
1006
1006
  };
1007
1007
 
1008
- const isEqual$5 = (oldState, newState) => {
1008
+ const isEqual$6 = (oldState, newState) => {
1009
1009
  return oldState.version === newState.version;
1010
1010
  };
1011
1011
 
1012
- const isEqual$4 = (oldState, newState) => {
1012
+ const isEqual$5 = (oldState, newState) => {
1013
1013
  return oldState.focused === newState.focused && oldState.focus === newState.focus;
1014
1014
  };
1015
1015
 
1016
- const isEqual$3 = (oldState, newState) => {
1016
+ const isEqual$4 = (oldState, newState) => {
1017
1017
  return oldState.focused === newState.focused;
1018
1018
  };
1019
1019
 
1020
- const isEqual$2 = (oldState, newState) => {
1020
+ const isEqual$3 = (oldState, newState) => {
1021
1021
  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;
1022
1022
  };
1023
1023
 
1024
- const isEqual$1 = (oldState, newState) => {
1024
+ const isEqual$2 = (oldState, newState) => {
1025
1025
  return oldState.version === newState.version;
1026
1026
  };
1027
1027
 
1028
- const RenderBounds = 8;
1029
- const RenderCss = 10;
1030
- const RenderEventListeners = 11;
1031
- const RenderUid = 12;
1032
- const RenderContent = 13;
1033
- const RenderFocusContext = 14;
1034
- const RenderFocus = 15;
1035
- const RenderValue = 16;
1036
- const RenderReplaceValue = 17;
1037
-
1038
1028
  const CheckBox = 'checkbox';
1039
1029
  const Group = 'group';
1040
1030
  const None = 'none';
@@ -1088,12 +1078,26 @@ const FocusSearchWholeWord = 34;
1088
1078
  const FocusToggleDetails = 1010;
1089
1079
  const FocusToggleReplace = 1020;
1090
1080
 
1081
+ const isEqual$1 = (oldState, newState) => {
1082
+ return newState.inputSource === User || oldState.replacement === newState.replacement;
1083
+ };
1084
+
1085
+ const RenderBounds = 8;
1086
+ const RenderCss = 10;
1087
+ const RenderEventListeners = 11;
1088
+ const RenderUid = 12;
1089
+ const RenderContent = 13;
1090
+ const RenderFocusContext = 14;
1091
+ const RenderFocus = 15;
1092
+ const RenderValue = 16;
1093
+ const RenderReplaceValue = 17;
1094
+
1091
1095
  const isEqual = (oldState, newState) => {
1092
1096
  return newState.inputSource === User || oldState.value === newState.value;
1093
1097
  };
1094
1098
 
1095
- const modules = [isEqual$5, isEqual$2, isEqual$7, isEqual$1, isEqual$3, isEqual$4, isEqual, isEqual$6];
1096
- const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue, RenderCss];
1099
+ const modules = [isEqual$6, isEqual$3, isEqual$8, isEqual$2, isEqual$4, isEqual$5, isEqual, isEqual$1, isEqual$7];
1100
+ const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue, RenderReplaceValue, RenderCss];
1097
1101
 
1098
1102
  const diff = (oldState, newState) => {
1099
1103
  const diffResult = [];
@@ -1540,7 +1544,7 @@ const applyEdits = async (editorId, edits) => {
1540
1544
  await invoke('Editor.applyDocumentEdits', editorId, edits);
1541
1545
  };
1542
1546
 
1543
- const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
1547
+ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) => {
1544
1548
  if (value.length === 0 || matches.length === 0) {
1545
1549
  return [];
1546
1550
  }
@@ -1552,17 +1556,22 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
1552
1556
  const rowIndex = matches[i * 2];
1553
1557
  const startColumnIndex = matches[i * 2 + 1];
1554
1558
  const endColumnIndex = startColumnIndex + value.length;
1559
+
1560
+ // Convert row/column positions to character offsets
1561
+ let startOffset = 0;
1562
+ for (let row = 0; row < rowIndex; row++) {
1563
+ startOffset += lines[row].length + 1; // +1 for newline character
1564
+ }
1565
+ startOffset += startColumnIndex;
1566
+ let endOffset = 0;
1567
+ for (let row = 0; row < rowIndex; row++) {
1568
+ endOffset += lines[row].length + 1; // +1 for newline character
1569
+ }
1570
+ endOffset += endColumnIndex;
1555
1571
  edits.push({
1556
- start: {
1557
- rowIndex,
1558
- columnIndex: startColumnIndex
1559
- },
1560
- end: {
1561
- rowIndex,
1562
- columnIndex: endColumnIndex
1563
- },
1564
- inserted: [replacement],
1565
- deleted: [value],
1572
+ startOffset,
1573
+ endOffset,
1574
+ inserted: replacement,
1566
1575
  origin: 'find-widget.replace'
1567
1576
  });
1568
1577
  }
@@ -1575,9 +1584,10 @@ const replace$1 = async state => {
1575
1584
  value,
1576
1585
  replacement,
1577
1586
  matchIndex,
1578
- editorUid
1587
+ editorUid,
1588
+ lines
1579
1589
  } = state;
1580
- const edits = getEdits(matches, value, replacement, matchIndex, false);
1590
+ const edits = getEdits(matches, value, replacement, matchIndex, false, lines);
1581
1591
  await applyEdits(editorUid, edits);
1582
1592
  // TODO ask editor worker to apply edit
1583
1593
  // TODO ask editor worker for new lines?
@@ -1591,9 +1601,10 @@ const replaceAll$1 = state => {
1591
1601
  matches,
1592
1602
  value,
1593
1603
  replacement,
1594
- editorUid
1604
+ editorUid,
1605
+ lines
1595
1606
  } = state;
1596
- const edits = getEdits(matches, value, replacement, 0, true);
1607
+ const edits = getEdits(matches, value, replacement, 0, true, lines);
1597
1608
  void applyEdits(editorUid, edits);
1598
1609
  return {
1599
1610
  ...state
@@ -2720,7 +2731,8 @@ const commandMap = {
2720
2731
  'FindWidget.terminate': terminate,
2721
2732
  'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
2722
2733
  'FindWidget.toggleReplace': wrapCommand(toggleReplace$1),
2723
- 'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
2734
+ 'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
2735
+ 'FindWidget.togglePreserveCase': wrapCommand(togglePreserveCase)
2724
2736
  };
2725
2737
 
2726
2738
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",