@lvce-editor/editor-worker 4.8.0 → 4.10.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.
@@ -144,6 +144,7 @@ const IndentMore = 'indentMore';
144
144
  const InsertLineBreak = 'insertLineBreak';
145
145
  const ReplaceAll$2 = 'replaceAll';
146
146
  const ToggleBlockComment = 'toggleBlockComment';
147
+ const Rename$1 = 'rename';
147
148
 
148
149
  const map$1 = Object.create(null);
149
150
  const set$7 = (id, widget) => {
@@ -398,23 +399,27 @@ const offsetAt = (textDocument, positionRowIndex, positionColumnIndex) => {
398
399
  return offset;
399
400
  };
400
401
  const positionAt = (textDocument, offset) => {
402
+ const {
403
+ lines
404
+ } = textDocument;
401
405
  let rowIndex = 0;
402
406
  let columnIndex = 0;
403
407
  let currentOffset = 0;
404
- while (rowIndex < textDocument.lines.length && currentOffset < offset) {
405
- currentOffset += textDocument.lines[rowIndex].length + 1;
408
+ while (rowIndex < lines.length && currentOffset < offset) {
409
+ currentOffset += lines[rowIndex].length + 1;
406
410
  rowIndex++;
407
411
  }
408
412
  if (currentOffset > offset) {
409
413
  rowIndex--;
410
- currentOffset -= textDocument.lines[rowIndex].length + 1;
414
+ currentOffset -= lines[rowIndex].length + 1;
411
415
  columnIndex = offset - currentOffset;
412
416
  } else {
413
417
  columnIndex = currentOffset - offset;
414
418
  }
415
- // for (let i = 0; i < textDocument.lines.length; i++) {
416
- // if(currentOffset)
417
- // }
419
+ console.log({
420
+ rowIndex,
421
+ columnIndex
422
+ });
418
423
  // TODO
419
424
  return {
420
425
  rowIndex,
@@ -3012,7 +3017,6 @@ const cutLine = async editor => {
3012
3017
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
3013
3018
  };
3014
3019
 
3015
- // @ts-ignore
3016
3020
  const cutSelectedText = async editor => {
3017
3021
  const {
3018
3022
  selections
@@ -7952,6 +7956,13 @@ const HandleFocusIn = 'handleFocusIn';
7952
7956
  const HandleClick = 'handleClick';
7953
7957
  const HandleInput = 'handleInput';
7954
7958
  const HandleFocus = 'handleFocus';
7959
+ const HandleClickPreviousMatch = 'handleClickPreviousMatch';
7960
+ const HandleClickNextMatch = 'handleClickNextMatch';
7961
+ const HandleClickClose = 'handleClickClose';
7962
+ const HandleClickReplace = 'handleClickReplace';
7963
+ const HandleClickReplaceAll = 'handleClickReplaceAll';
7964
+ const HandleReplaceInput = 'handleReplaceInput';
7965
+ const HandleReplaceFocus = 'handleReplaceFocus';
7955
7966
 
7956
7967
  const hoverProblemMessage = {
7957
7968
  type: Span,
@@ -8068,6 +8079,35 @@ const getRenameState = editor => {
8068
8079
  return getWidgetState(editor, Rename);
8069
8080
  };
8070
8081
 
8082
+ const getRenameChanges = (editor, result) => {
8083
+ if (!result || !result.edits) {
8084
+ return [];
8085
+ }
8086
+ const changes = [];
8087
+ console.log({
8088
+ result
8089
+ });
8090
+ for (const edit of result.edits) {
8091
+ const position = positionAt(editor, edit.offset);
8092
+ const start = position;
8093
+ const end = {
8094
+ ...position,
8095
+ columnIndex: start.columnIndex + edit.deleted
8096
+ };
8097
+ const selection = {
8098
+ start,
8099
+ end
8100
+ };
8101
+ changes.push({
8102
+ start,
8103
+ end,
8104
+ inserted: [result.inserted],
8105
+ deleted: getSelectionText(editor, selection),
8106
+ origin: Rename$1
8107
+ });
8108
+ }
8109
+ return changes;
8110
+ };
8071
8111
  const accept = async editor => {
8072
8112
  const child = getRenameState(editor);
8073
8113
  if (!child) {
@@ -8080,8 +8120,9 @@ const accept = async editor => {
8080
8120
  // TODO
8081
8121
  const offset = getOffsetAtCursor(editor);
8082
8122
  const result = await executeRenameProvider(editor, offset, child.newValue);
8123
+ const changes = getRenameChanges(editor, result);
8083
8124
  console.log({
8084
- result
8125
+ changes
8085
8126
  });
8086
8127
  // 1. ask extension host for rename edits
8087
8128
  // 2. apply rename edit across editor (and whole workspace)
@@ -10560,37 +10601,37 @@ const FocusNext = 'FocusNext';
10560
10601
  const FocusPrevious = 'FocusPrevious';
10561
10602
  const Replace = 'Replace';
10562
10603
 
10563
- const getFindWidgetButtons = buttonsEnabled => {
10604
+ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
10564
10605
  const findButtons = [{
10565
10606
  label: previousMatch(),
10566
10607
  icon: ArrowUp,
10567
- disabled: !buttonsEnabled,
10568
- onClick: 'handleClickPreviousMatch',
10608
+ disabled: !findButtonsEnabled,
10609
+ onClick: HandleClickPreviousMatch,
10569
10610
  name: FocusPrevious
10570
10611
  }, {
10571
10612
  label: nextMatch(),
10572
10613
  icon: ArrowDown,
10573
- disabled: !buttonsEnabled,
10574
- onClick: 'handleClickNextMatch',
10614
+ disabled: !findButtonsEnabled,
10615
+ onClick: HandleClickNextMatch,
10575
10616
  name: FocusNext
10576
10617
  }, {
10577
10618
  label: close(),
10578
10619
  icon: Close$1,
10579
10620
  disabled: false,
10580
- onClick: 'handleClickClose',
10621
+ onClick: HandleClickClose,
10581
10622
  name: Close
10582
10623
  }];
10583
10624
  const replaceButtons = [{
10584
10625
  label: replace(),
10585
10626
  icon: Replace$1,
10586
- disabled: !buttonsEnabled,
10587
- onClick: 'handleClickReplace',
10627
+ disabled: !replaceButtonsEnabled,
10628
+ onClick: HandleClickReplace,
10588
10629
  name: Replace
10589
10630
  }, {
10590
10631
  label: replaceAll(),
10591
10632
  icon: ReplaceAll$1,
10592
- disabled: !buttonsEnabled,
10593
- onClick: 'handleClickReplaceAll',
10633
+ disabled: !replaceButtonsEnabled,
10634
+ onClick: HandleClickReplaceAll,
10594
10635
  name: ReplaceAll
10595
10636
  }];
10596
10637
  return {
@@ -10599,6 +10640,15 @@ const getFindWidgetButtons = buttonsEnabled => {
10599
10640
  };
10600
10641
  };
10601
10642
 
10643
+ const getFindWidgetButtonsEnabled = (matchCount, value) => {
10644
+ const findButtonsEnabled = matchCount > 0;
10645
+ const replaceButtonsEnabled = value.length > 0;
10646
+ return {
10647
+ findButtonsEnabled,
10648
+ replaceButtonsEnabled
10649
+ };
10650
+ };
10651
+
10602
10652
  // TODO always focus element by name
10603
10653
  const getFindWidgetFocusSelector = focus => {
10604
10654
  switch (focus) {
@@ -10623,8 +10673,8 @@ const getFindWidgetFocusSelector = focus => {
10623
10673
  }
10624
10674
  };
10625
10675
 
10626
- const getFindMatchCountClassName = matchCount => {
10627
- if (matchCount === 0) {
10676
+ const getFindMatchCountClassName = (matchCount, value) => {
10677
+ if (value && matchCount === 0) {
10628
10678
  return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
10629
10679
  }
10630
10680
  return FindWidgetMatchCount;
@@ -10712,7 +10762,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
10712
10762
  return dom;
10713
10763
  };
10714
10764
 
10715
- const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount) => {
10765
+ const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount, value) => {
10716
10766
  const dom = [];
10717
10767
  dom.push({
10718
10768
  type: Div,
@@ -10720,7 +10770,7 @@ const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount) => {
10720
10770
  childCount: 5
10721
10771
  });
10722
10772
  dom.push(...getSearchFieldVirtualDom('search-value', find(), HandleInput, [], [], HandleFocus));
10723
- const findClassName = getFindMatchCountClassName(matchCount);
10773
+ const findClassName = getFindMatchCountClassName(matchCount, value);
10724
10774
  dom.push({
10725
10775
  type: Div,
10726
10776
  className: findClassName,
@@ -10736,7 +10786,7 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
10736
10786
  type: Div,
10737
10787
  className: FindWidgetReplace,
10738
10788
  childCount: 1 + replaceButtons.length
10739
- }, ...getSearchFieldVirtualDom('replace-value', replace(), 'handleReplaceInput', [], [], 'handleReplaceFocus'), ...replaceButtons.flatMap(getIconButtonVirtualDom));
10789
+ }, ...getSearchFieldVirtualDom('replace-value', replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
10740
10790
  }
10741
10791
  return dom;
10742
10792
  };
@@ -10760,7 +10810,7 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
10760
10810
  }];
10761
10811
  };
10762
10812
 
10763
- const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, replaceButtons, matchCase, matchWholeWord, useRegularExpression, matchCount) => {
10813
+ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, replaceButtons, matchCase, matchWholeWord, useRegularExpression, matchCount, value) => {
10764
10814
  const dom = [];
10765
10815
  dom.push({
10766
10816
  type: Div,
@@ -10774,7 +10824,7 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, r
10774
10824
  className: FindWidgetRight,
10775
10825
  childCount: replaceExpanded ? 2 : 1
10776
10826
  });
10777
- dom.push(...getFindWidgetFindVirtualDom(matchCountText, findButtons, matchCount));
10827
+ dom.push(...getFindWidgetFindVirtualDom(matchCountText, findButtons, matchCount, value));
10778
10828
  if (replaceExpanded) {
10779
10829
  dom.push(...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons));
10780
10830
  }
@@ -10798,16 +10848,19 @@ const renderValue = {
10798
10848
  };
10799
10849
  const renderDetails = {
10800
10850
  isEqual(oldState, newState) {
10801
- return oldState.matchIndex === newState.matchIndex && oldState.matchCount === newState.matchCount && oldState.replaceExpanded === newState.replaceExpanded;
10851
+ return oldState.matchIndex === newState.matchIndex && oldState.matchCount === newState.matchCount && oldState.replaceExpanded === newState.replaceExpanded && oldState.value === newState.value;
10802
10852
  },
10803
10853
  apply(oldState, newState) {
10804
10854
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
10805
- const buttonsEnabled = newState.matchCount > 0;
10855
+ const {
10856
+ findButtonsEnabled,
10857
+ replaceButtonsEnabled
10858
+ } = getFindWidgetButtonsEnabled(newState.matchCount, newState.value);
10806
10859
  const {
10807
10860
  findButtons,
10808
10861
  replaceButtons
10809
- } = getFindWidgetButtons(buttonsEnabled);
10810
- const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.matchCount);
10862
+ } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled);
10863
+ const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.matchCount, newState.value);
10811
10864
  return ['Viewlet.setDom2', dom];
10812
10865
  }
10813
10866
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "4.8.0",
3
+ "version": "4.10.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",