@lvce-editor/editor-worker 3.28.0 → 3.29.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.
@@ -131,8 +131,8 @@ const handleSliderPointerMove = (state, x, y) => {
131
131
  // TODO use numeric enum
132
132
  const CompositionUpdate = 'compositionUpdate';
133
133
  const ContentEditableInput = 'contentEditableInput';
134
- const DeleteLeft = 'deleteLeft';
135
134
  const DeleteHorizontalRight = 'deleteHorizontalRight';
135
+ const DeleteLeft = 'deleteLeft';
136
136
  const EditorCut = 'editorCut';
137
137
  const EditorPasteText = 'editorPasteText';
138
138
  const EditorSnippet = 'editorSnippet';
@@ -142,6 +142,7 @@ const Format = 'format';
142
142
  const IndentLess = 'indentLess';
143
143
  const IndentMore = 'indentMore';
144
144
  const InsertLineBreak = 'insertLineBreak';
145
+ const ReplaceAll$2 = 'replaceAll';
145
146
  const ToggleBlockComment = 'toggleBlockComment';
146
147
 
147
148
  const map$1 = Object.create(null);
@@ -866,7 +867,7 @@ const scheduleSelections = (editor, selectionEdits) => {
866
867
  };
867
868
 
868
869
  /**
869
- *
870
+ * TODO make this synchronous maybe?
870
871
  * @param {any} editor
871
872
  * @param {any[]} changes
872
873
  * @param {Uint32Array|undefined} selectionChanges
@@ -5351,9 +5352,11 @@ const handleToggleReplaceFocus = async state => {
5351
5352
  focus: FocusFindWidgetToggleReplace
5352
5353
  };
5353
5354
  };
5354
- const handleReplaceInput = state => {
5355
- // TODO
5356
- return state;
5355
+ const handleReplaceInput = (state, value) => {
5356
+ return {
5357
+ ...state,
5358
+ replacement: value
5359
+ };
5357
5360
  };
5358
5361
 
5359
5362
  const getFindWidgetPosition = editor => {
@@ -7871,6 +7874,34 @@ const renderHover = (oldState, newState) => {
7871
7874
  return commands;
7872
7875
  };
7873
7876
 
7877
+ const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
7878
+ const ranges = [];
7879
+ const oldValueLength = oldValue.length;
7880
+ for (let i = 0; i < matches.length; i += 2) {
7881
+ const startRowIndex = matches[i];
7882
+ const startColumnIndex = matches[i + 1];
7883
+ const endRowIndex = matches[i];
7884
+ const endColumnIndex = matches[i] + oldValueLength;
7885
+ ranges.push(startRowIndex, startColumnIndex, endRowIndex, endColumnIndex);
7886
+ }
7887
+ return replaceRange(editor, ranges, [newValue], ReplaceAll$2);
7888
+ };
7889
+
7890
+ const replaceAll$1 = async editor => {
7891
+ const state = getFindState(editor);
7892
+ if (!state) {
7893
+ return editor;
7894
+ }
7895
+ const {
7896
+ matches,
7897
+ value,
7898
+ replacement
7899
+ } = state;
7900
+ const edits = replaceTextOccurrences(editor, matches, value, replacement);
7901
+ const newEditor = await applyEdit(editor, edits);
7902
+ return newEditor;
7903
+ };
7904
+
7874
7905
  const pending = Object.create(null);
7875
7906
  const loaded = Object.create(null);
7876
7907
  const setPending = (id, promise) => {
@@ -9095,6 +9126,7 @@ const commandMap = {
9095
9126
  'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
9096
9127
  'FindWidget.loadContent': loadContent$1,
9097
9128
  'FindWidget.toggleReplace': toggleReplace,
9129
+ 'FindWidget.replaceAll': replaceAll$1,
9098
9130
  'Font.ensure': ensure,
9099
9131
  'Hover.getHoverInfo': getEditorHoverInfo,
9100
9132
  'Hover.handleSashPointerDown': handleSashPointerDown,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.28.0",
3
+ "version": "3.29.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",