@lvce-editor/editor-worker 3.28.0 → 3.30.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
@@ -5253,6 +5254,35 @@ const handleBlur = async state => {
5253
5254
  return state;
5254
5255
  };
5255
5256
 
5257
+ const refresh$1 = (editor, state, value) => {
5258
+ const {
5259
+ lines
5260
+ } = editor;
5261
+ const matches = findMatchesCaseInsensitive(lines, value);
5262
+ const matchCount = getMatchCount(matches);
5263
+ return {
5264
+ ...state,
5265
+ matches,
5266
+ matchIndex: 0,
5267
+ matchCount,
5268
+ value
5269
+ };
5270
+ };
5271
+
5272
+ const refresh = (state, value = state.value) => {
5273
+ // TODO get focused editor
5274
+ const {
5275
+ editorUid
5276
+ } = state;
5277
+ // highlight locations that match value
5278
+ const editor = getEditor(editorUid);
5279
+ return refresh$1(editor, state, value);
5280
+ };
5281
+
5282
+ const handleInput = (state, value) => {
5283
+ return refresh(state, value);
5284
+ };
5285
+
5256
5286
  const handleFindWidgetFocus = (state, focusKey) => {
5257
5287
  if (state.focus === focusKey) {
5258
5288
  return state;
@@ -5310,29 +5340,6 @@ const loadContent$1 = editorId => {
5310
5340
  editorUid: editor.uid
5311
5341
  };
5312
5342
  };
5313
- const refresh = (state, value = state.value) => {
5314
- // TODO get focused editor
5315
- const {
5316
- editorUid
5317
- } = state;
5318
- // highlight locations that match value
5319
- const editor = getEditor(editorUid);
5320
- const {
5321
- lines
5322
- } = editor;
5323
- const matches = findMatchesCaseInsensitive(lines, value);
5324
- const matchCount = getMatchCount(matches);
5325
- return {
5326
- ...state,
5327
- matches,
5328
- matchIndex: 0,
5329
- matchCount,
5330
- value
5331
- };
5332
- };
5333
- const handleInput = (state, value) => {
5334
- return refresh(state, value);
5335
- };
5336
5343
  const close$1 = async state => {
5337
5344
  // TODO
5338
5345
  // await Viewlet.closeWidget(uid)
@@ -5351,9 +5358,11 @@ const handleToggleReplaceFocus = async state => {
5351
5358
  focus: FocusFindWidgetToggleReplace
5352
5359
  };
5353
5360
  };
5354
- const handleReplaceInput = state => {
5355
- // TODO
5356
- return state;
5361
+ const handleReplaceInput = (state, value) => {
5362
+ return {
5363
+ ...state,
5364
+ replacement: value
5365
+ };
5357
5366
  };
5358
5367
 
5359
5368
  const getFindWidgetPosition = editor => {
@@ -7871,6 +7880,56 @@ const renderHover = (oldState, newState) => {
7871
7880
  return commands;
7872
7881
  };
7873
7882
 
7883
+ const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
7884
+ const ranges = [];
7885
+ const oldValueLength = oldValue.length;
7886
+ for (let i = 0; i < matches.length; i += 2) {
7887
+ const startRowIndex = matches[i];
7888
+ const startColumnIndex = matches[i + 1];
7889
+ const endRowIndex = matches[i];
7890
+ const endColumnIndex = matches[i] + oldValueLength;
7891
+ ranges.push(startRowIndex, startColumnIndex, endRowIndex, endColumnIndex);
7892
+ }
7893
+ return replaceRange(editor, ranges, [newValue], ReplaceAll$2);
7894
+ };
7895
+
7896
+ const updateWidget = (editor, widgetId, newState) => {
7897
+ // TODO avoid closure
7898
+ const isWidget = widget => {
7899
+ return widget.id === widgetId;
7900
+ };
7901
+ const childIndex = editor.widgets.findIndex(isWidget);
7902
+ // TODO scroll up/down if necessary
7903
+ const childWidget = editor.widgets[childIndex];
7904
+ const newWidget = {
7905
+ ...childWidget,
7906
+ oldState: childWidget.newState,
7907
+ newState
7908
+ };
7909
+ const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
7910
+ return {
7911
+ ...editor,
7912
+ widgets: newWidgets
7913
+ };
7914
+ };
7915
+
7916
+ const replaceAll$1 = async editor => {
7917
+ const state = getFindState(editor);
7918
+ if (!state) {
7919
+ return editor;
7920
+ }
7921
+ const {
7922
+ matches,
7923
+ value,
7924
+ replacement
7925
+ } = state;
7926
+ const edits = replaceTextOccurrences(editor, matches, value, replacement);
7927
+ const newEditor = await applyEdit(editor, edits);
7928
+ const newState = refresh$1(newEditor, state, value);
7929
+ const newestEditor = updateWidget(newEditor, Find, newState);
7930
+ return newestEditor;
7931
+ };
7932
+
7874
7933
  const pending = Object.create(null);
7875
7934
  const loaded = Object.create(null);
7876
7935
  const setPending = (id, promise) => {
@@ -8856,16 +8915,8 @@ const wrapWidgetCommand = (widgetId, fn) => {
8856
8915
  // TODO scroll up/down if necessary
8857
8916
  const childWidget = editor.widgets[childIndex];
8858
8917
  const newState = await fn(childWidget.newState, ...args);
8859
- const newWidget = {
8860
- ...childWidget,
8861
- oldState: childWidget.newState,
8862
- newState
8863
- };
8864
- const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
8865
- return {
8866
- ...editor,
8867
- widgets: newWidgets
8868
- };
8918
+ const newEditor = updateWidget(editor, widgetId, newState);
8919
+ return newEditor;
8869
8920
  };
8870
8921
  return wrapped;
8871
8922
  };
@@ -9095,6 +9146,7 @@ const commandMap = {
9095
9146
  'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
9096
9147
  'FindWidget.loadContent': loadContent$1,
9097
9148
  'FindWidget.toggleReplace': toggleReplace,
9149
+ 'FindWidget.replaceAll': replaceAll$1,
9098
9150
  'Font.ensure': ensure,
9099
9151
  'Hover.getHoverInfo': getEditorHoverInfo,
9100
9152
  '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.30.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",