@lvce-editor/find-widget-worker 1.23.0 → 2.1.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.
@@ -988,8 +988,10 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
988
988
  minWidth: 400,
989
989
  history: [],
990
990
  inputErrorMessage: '',
991
- inputHeight: 24,
992
- inputLineHeight: 24
991
+ inputHeight: 15,
992
+ inputLineHeight: 15,
993
+ inputPaddingTop: 2,
994
+ inputPaddingBottom: 2
993
995
  };
994
996
  set$3(uid, state, state);
995
997
  return state;
@@ -1046,9 +1048,18 @@ const ClientX = 'event.clientX';
1046
1048
  const ClientY = 'event.clientY';
1047
1049
  const TargetName = 'event.target.name';
1048
1050
 
1051
+ const Tab = 2;
1052
+ const Enter = 3;
1053
+ const KeyF = 34;
1054
+ const F4 = 60;
1055
+
1049
1056
  const User = 1;
1050
1057
  const Script = 2;
1051
1058
 
1059
+ const CtrlCmd = 1 << 11 >>> 0;
1060
+ const Shift = 1 << 10 >>> 0;
1061
+ const Alt = 1 << 9 >>> 0;
1062
+
1052
1063
  const EditorWorker$1 = 99;
1053
1064
 
1054
1065
  const FocusSelector = 'Viewlet.focusSelector';
@@ -1056,7 +1067,13 @@ const SetCss = 'Viewlet.setCss';
1056
1067
  const SetFocusContext = 'Viewlet.setFocusContext';
1057
1068
  const SetValueByName = 'Viewlet.setValueByName';
1058
1069
 
1070
+ const FocusFindWidget$1 = 16;
1059
1071
  const FocusFindWidgetCloseButton$1 = 48;
1072
+ const FocusFindWidgetNextMatchButton = 49;
1073
+ const FocusFindWidgetPreviousMatchButton = 50;
1074
+ const FocusFindWidgetReplace$1 = 43;
1075
+ const FocusFindWidgetReplaceAllButton$1 = 47;
1076
+ const FocusFindWidgetReplaceButton = 46;
1060
1077
  const FocusIgnoreFiles = 1012;
1061
1078
  const FocusSearchExcludeInput = 1008;
1062
1079
  const FocusSearchIncludeInput = 1007;
@@ -1419,7 +1436,9 @@ const refresh$1 = (state, value, inputSource) => {
1419
1436
  matchCase,
1420
1437
  useRegularExpression,
1421
1438
  matchWholeWord,
1422
- inputLineHeight
1439
+ inputLineHeight,
1440
+ inputPaddingTop,
1441
+ inputPaddingBottom
1423
1442
  } = state;
1424
1443
  const options = {
1425
1444
  matchCase,
@@ -1430,12 +1449,15 @@ const refresh$1 = (state, value, inputSource) => {
1430
1449
  matches,
1431
1450
  error
1432
1451
  } = findMatches(lines, value, options);
1433
- const inputHeight = measureTextHeight(value, inputLineHeight);
1452
+ const textHeight = measureTextHeight(value, inputLineHeight);
1453
+ const inputHeight = textHeight + inputPaddingBottom + inputPaddingTop;
1454
+ const height = inputHeight + 5;
1434
1455
  if (error) {
1435
1456
  return {
1436
1457
  ...state,
1437
1458
  inputErrorMessage: error,
1438
- inputHeight
1459
+ inputHeight,
1460
+ height
1439
1461
  };
1440
1462
  }
1441
1463
  const matchCount = getMatchCount(matches);
@@ -1447,7 +1469,8 @@ const refresh$1 = (state, value, inputSource) => {
1447
1469
  matchCount,
1448
1470
  matches,
1449
1471
  matchIndex: 0,
1450
- value
1472
+ value,
1473
+ height
1451
1474
  };
1452
1475
  };
1453
1476
 
@@ -1517,7 +1540,7 @@ const applyEdits = async (editorId, edits) => {
1517
1540
  await invoke('Editor.applyDocumentEdits', editorId, edits);
1518
1541
  };
1519
1542
 
1520
- const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
1543
+ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines) => {
1521
1544
  if (value.length === 0 || matches.length === 0) {
1522
1545
  return [];
1523
1546
  }
@@ -1529,17 +1552,22 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
1529
1552
  const rowIndex = matches[i * 2];
1530
1553
  const startColumnIndex = matches[i * 2 + 1];
1531
1554
  const endColumnIndex = startColumnIndex + value.length;
1555
+
1556
+ // Convert row/column positions to character offsets
1557
+ let startOffset = 0;
1558
+ for (let row = 0; row < rowIndex; row++) {
1559
+ startOffset += lines[row].length + 1; // +1 for newline character
1560
+ }
1561
+ startOffset += startColumnIndex;
1562
+ let endOffset = 0;
1563
+ for (let row = 0; row < rowIndex; row++) {
1564
+ endOffset += lines[row].length + 1; // +1 for newline character
1565
+ }
1566
+ endOffset += endColumnIndex;
1532
1567
  edits.push({
1533
- start: {
1534
- rowIndex,
1535
- columnIndex: startColumnIndex
1536
- },
1537
- end: {
1538
- rowIndex,
1539
- columnIndex: endColumnIndex
1540
- },
1541
- inserted: [replacement],
1542
- deleted: [value],
1568
+ startOffset,
1569
+ endOffset,
1570
+ inserted: replacement,
1543
1571
  origin: 'find-widget.replace'
1544
1572
  });
1545
1573
  }
@@ -1552,9 +1580,10 @@ const replace$1 = async state => {
1552
1580
  value,
1553
1581
  replacement,
1554
1582
  matchIndex,
1555
- editorUid
1583
+ editorUid,
1584
+ lines
1556
1585
  } = state;
1557
- const edits = getEdits(matches, value, replacement, matchIndex, false);
1586
+ const edits = getEdits(matches, value, replacement, matchIndex, false, lines);
1558
1587
  await applyEdits(editorUid, edits);
1559
1588
  // TODO ask editor worker to apply edit
1560
1589
  // TODO ask editor worker for new lines?
@@ -1568,9 +1597,10 @@ const replaceAll$1 = state => {
1568
1597
  matches,
1569
1598
  value,
1570
1599
  replacement,
1571
- editorUid
1600
+ editorUid,
1601
+ lines
1572
1602
  } = state;
1573
- const edits = getEdits(matches, value, replacement, 0, true);
1603
+ const edits = getEdits(matches, value, replacement, 0, true, lines);
1574
1604
  void applyEdits(editorUid, edits);
1575
1605
  return {
1576
1606
  ...state
@@ -1794,6 +1824,82 @@ const focusPreviousElement = state => {
1794
1824
  return focusElement(state, previousFocus);
1795
1825
  };
1796
1826
 
1827
+ const getKeyBindings = () => {
1828
+ return [{
1829
+ key: Enter,
1830
+ command: 'FindWidget.focusNext',
1831
+ when: FocusFindWidget$1
1832
+ }, {
1833
+ key: CtrlCmd | KeyF,
1834
+ command: 'FindWidget.preventDefaultBrowserFind',
1835
+ when: FocusFindWidget$1
1836
+ }, {
1837
+ key: Shift | F4,
1838
+ command: 'FindWidget.focusPrevious',
1839
+ when: FocusFindWidget$1
1840
+ }, {
1841
+ key: F4,
1842
+ command: 'FindWidget.focusNext',
1843
+ when: FocusFindWidget$1
1844
+ }, {
1845
+ key: Shift | Tab,
1846
+ command: 'FindWidget.focusToggleReplace',
1847
+ when: FocusFindWidget$1
1848
+ }, {
1849
+ key: Tab,
1850
+ command: 'FindWidget.focusReplace',
1851
+ when: FocusFindWidget$1
1852
+ }, {
1853
+ key: Tab,
1854
+ command: 'FindWidget.focusPreviousMatchButton',
1855
+ when: FocusFindWidgetReplace$1
1856
+ }, {
1857
+ key: Alt | CtrlCmd | Enter,
1858
+ command: 'FindWidget.replaceAll',
1859
+ when: FocusFindWidgetReplace$1
1860
+ }, {
1861
+ key: Tab,
1862
+ command: 'FindWidget.focusNextMatchButton',
1863
+ when: FocusFindWidgetPreviousMatchButton
1864
+ }, {
1865
+ key: Shift | Tab,
1866
+ command: 'FindWidget.focusReplace',
1867
+ when: FocusFindWidgetPreviousMatchButton
1868
+ }, {
1869
+ key: Shift | Tab,
1870
+ command: 'FindWidget.focusPreviousMatchButton',
1871
+ when: FocusFindWidgetNextMatchButton
1872
+ }, {
1873
+ key: Tab,
1874
+ command: 'FindWidget.focusCloseButton',
1875
+ when: FocusFindWidgetNextMatchButton
1876
+ }, {
1877
+ key: Shift | Tab,
1878
+ command: 'FindWidget.focusNextMatchButton',
1879
+ when: FocusFindWidgetCloseButton$1
1880
+ }, {
1881
+ key: Tab,
1882
+ command: 'FindWidget.focusReplaceButton',
1883
+ when: FocusFindWidgetCloseButton$1
1884
+ }, {
1885
+ key: Shift | Tab,
1886
+ command: 'FindWidget.focusFind',
1887
+ when: FocusFindWidgetReplace$1
1888
+ }, {
1889
+ key: Tab,
1890
+ command: 'FindWidget.focusReplaceAllButton',
1891
+ when: FocusFindWidgetReplaceButton
1892
+ }, {
1893
+ key: Shift | Tab,
1894
+ command: 'FindWidget.focusCloseButton',
1895
+ when: FocusFindWidgetReplaceButton
1896
+ }, {
1897
+ key: Shift | Tab,
1898
+ command: 'FindWidget.focusReplaceButton',
1899
+ when: FocusFindWidgetReplaceAllButton$1
1900
+ }];
1901
+ };
1902
+
1797
1903
  const handleInput = (state, value, inputSource = User) => {
1798
1904
  return refresh(state, value, inputSource);
1799
1905
  };
@@ -1884,7 +1990,8 @@ const loadContent = async (state, savedState) => {
1884
1990
  editorUid,
1885
1991
  editorWidth,
1886
1992
  editorX,
1887
- editorY
1993
+ editorY,
1994
+ inputLineHeight
1888
1995
  } = state;
1889
1996
  const {
1890
1997
  replacement,
@@ -1904,11 +2011,13 @@ const loadContent = async (state, savedState) => {
1904
2011
  const actualValue = value || getSelectedText(lines, selections);
1905
2012
  const matches = findMatchesCaseInsensitive(lines, actualValue);
1906
2013
  const matchCount = getMatchCount(matches);
2014
+ const inputHeight = measureTextHeight(value, inputLineHeight);
1907
2015
  return {
1908
2016
  ...state,
1909
2017
  focus: FocusSearchInput,
1910
2018
  focused: true,
1911
2019
  height,
2020
+ inputHeight,
1912
2021
  inputSource: Script,
1913
2022
  lines,
1914
2023
  matchCount,
@@ -2153,13 +2262,6 @@ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
2153
2262
  const MaskIconChevronDown = 'MaskIconChevronDown';
2154
2263
  const MaskIconChevronRight = 'MaskIconChevronRight';
2155
2264
 
2156
- const getFindMatchCountClassName = (matchCount, hasValue) => {
2157
- if (hasValue && matchCount === 0) {
2158
- return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
2159
- }
2160
- return FindWidgetMatchCount;
2161
- };
2162
-
2163
2265
  const getIconVirtualDom = (icon, type = Div) => {
2164
2266
  return {
2165
2267
  type,
@@ -2193,6 +2295,22 @@ const getIconButtonVirtualDom = iconButton => {
2193
2295
  }, getIconVirtualDom(icon)];
2194
2296
  };
2195
2297
 
2298
+ const emptyMatches = mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
2299
+ const getFindMatchCountClassName = (matchCount, hasValue) => {
2300
+ if (hasValue && matchCount === 0) {
2301
+ return emptyMatches;
2302
+ }
2303
+ return FindWidgetMatchCount;
2304
+ };
2305
+
2306
+ const getMatchCountVirtualDom = (matchCountText, matchCount, hasValue) => {
2307
+ return [{
2308
+ type: Div,
2309
+ className: getFindMatchCountClassName(matchCount, hasValue),
2310
+ childCount: 1
2311
+ }, text(matchCountText)];
2312
+ };
2313
+
2196
2314
  const checkedClassName = mergeClassNames(SearchFieldButton, SearchFieldButtonChecked);
2197
2315
  const unCheckedClassName = SearchFieldButton;
2198
2316
  const getSearchFieldButtonVirtualDom = button => {
@@ -2253,12 +2371,12 @@ const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matc
2253
2371
  return [{
2254
2372
  type: Div,
2255
2373
  className: FindWidgetFind,
2256
- childCount: 5
2374
+ childCount: 2
2257
2375
  }, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus, extraClassName), {
2258
2376
  type: Div,
2259
- className: getFindMatchCountClassName(matchCount, hasValue),
2260
- childCount: 1
2261
- }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom)];
2377
+ className: 'FindWidgetActions',
2378
+ childCount: 1 + buttons.length
2379
+ }, ...getMatchCountVirtualDom(matchCountText, matchCount, hasValue), ...buttons.flatMap(getIconButtonVirtualDom)];
2262
2380
  };
2263
2381
 
2264
2382
  const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replaceFieldButtons) => {
@@ -2578,17 +2696,18 @@ const commandMap = {
2578
2696
  'FindWidget.diff2': diff2,
2579
2697
  'FindWidget.dispose': dispose$1,
2580
2698
  'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
2581
- 'FindWidget.focusFirst': wrapCommand(focusFirst),
2582
2699
  'FindWidget.focusElement': wrapCommand(focusElement),
2700
+ 'FindWidget.focusFirst': wrapCommand(focusFirst),
2583
2701
  'FindWidget.focusIndex': wrapCommand(focusIndex),
2584
2702
  'FindWidget.focusLast': wrapCommand(focusLast),
2585
2703
  'FindWidget.focusNext': wrapCommand(focusNext),
2586
- 'FindWidget.focusPrevious': wrapCommand(focusPrevious),
2587
2704
  'FindWidget.focusNextElement': wrapCommand(focusNextElement),
2705
+ 'FindWidget.focusPrevious': wrapCommand(focusPrevious),
2588
2706
  'FindWidget.focusPreviousElement': wrapCommand(focusPreviousElement),
2589
2707
  'FindWidget.focusReplace': wrapCommand(focusReplace),
2590
2708
  'FindWidget.focusReplaceAllButton': wrapCommand(focusReplaceAllButton),
2591
2709
  'FindWidget.getCommandIds': getCommandIds,
2710
+ 'FindWidget.getKeyBindings': getKeyBindings,
2592
2711
  'FindWidget.handleBlur': wrapCommand(handleBlur),
2593
2712
  'FindWidget.handleClickButton': wrapCommand(handleClickButton),
2594
2713
  'FindWidget.handleClickClose': wrapCommand(handleClickClose),
@@ -2604,8 +2723,8 @@ const commandMap = {
2604
2723
  'FindWidget.replace': wrapCommand(replace$1),
2605
2724
  'FindWidget.replaceAll': wrapCommand(replaceAll$1),
2606
2725
  'FindWidget.resize': wrapCommand(resize),
2607
- 'FindWidget.terminate': terminate,
2608
2726
  'FindWidget.saveState': wrapGetter(saveState),
2727
+ 'FindWidget.terminate': terminate,
2609
2728
  'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
2610
2729
  'FindWidget.toggleReplace': wrapCommand(toggleReplace$1),
2611
2730
  'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.23.0",
3
+ "version": "2.1.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",