@lvce-editor/editor-worker 19.76.4 → 19.77.1

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.
@@ -120,6 +120,7 @@ export interface EditorState {
120
120
  readonly fontSize: number;
121
121
  readonly fontWeight: number;
122
122
  readonly forceText?: boolean;
123
+ readonly formatActions?: "pre-save" | "post-save";
123
124
  readonly formatOnSave?: boolean;
124
125
  readonly gutterDecorations: readonly EditorGutterDecoration[];
125
126
  readonly gutterWidth: number;
@@ -175,6 +176,7 @@ export interface EditorState {
175
176
  readonly outerHeight?: number;
176
177
  readonly outerWidth: number;
177
178
  readonly platform: number;
179
+ readonly postSaveFormat?: boolean;
178
180
  readonly primarySelectionIndex: number;
179
181
  readonly problemNavigationDiagnostic?: any;
180
182
  readonly problemsHighlightedRow: number;
package/dist/diff-sdk.js CHANGED
@@ -6362,6 +6362,7 @@ const createEditor = async ({
6362
6362
  fontFamily,
6363
6363
  fontSize,
6364
6364
  fontWeight,
6365
+ formatActions,
6365
6366
  formatOnSave,
6366
6367
  height,
6367
6368
  highlightActiveLineNumber = true,
@@ -6426,6 +6427,7 @@ const createEditor = async ({
6426
6427
  fontFamily,
6427
6428
  fontSize,
6428
6429
  fontWeight,
6430
+ formatActions,
6429
6431
  formatOnSave,
6430
6432
  gutterDecorations: [],
6431
6433
  gutterWidth: 0,
@@ -7999,7 +8001,7 @@ const applyEdit = async (editor, changes, selectionChanges) => {
7999
8001
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
8000
8002
  };
8001
8003
 
8002
- const getFormattingEdits = async editor => {
8004
+ const getFormattingEdits$1 = async editor => {
8003
8005
  if (editor.largeFile) {
8004
8006
  return [];
8005
8007
  }
@@ -8275,26 +8277,32 @@ const showErrorMessage = async (editor, rowIndex, columnIndex, message) => {
8275
8277
  };
8276
8278
 
8277
8279
  const expectedErrorMessage = 'Failed to execute formatting provider: FormattingError:';
8278
-
8279
- // TODO also format with cursor
8280
- const format = async editor => {
8280
+ const getFormattingEdits = async editor => {
8281
8281
  try {
8282
- const edits = await getFormattingEdits(editor);
8283
- return applyDocumentEdits$1(editor, edits);
8282
+ return await getFormattingEdits$1(editor);
8284
8283
  } catch (error) {
8285
8284
  if (isFormattingError(error)) {
8286
8285
  console.error('Formatting Error:',
8287
8286
  // @ts-ignore
8288
8287
  error.message.slice(expectedErrorMessage.length));
8289
- return editor;
8288
+ return undefined;
8290
8289
  }
8291
8290
  console.error(error);
8292
8291
 
8293
8292
  // TODO configure editor message as widget
8294
8293
  const displayErrorMessage = String(error);
8295
8294
  await editorShowMessage(editor, 0, 0, displayErrorMessage);
8295
+ return undefined;
8296
+ }
8297
+ };
8298
+
8299
+ // TODO also format with cursor
8300
+ const format = async editor => {
8301
+ const edits = await getFormattingEdits(editor);
8302
+ if (!edits) {
8296
8303
  return editor;
8297
8304
  }
8305
+ return applyDocumentEdits$1(editor, edits);
8298
8306
  };
8299
8307
 
8300
8308
  const getNewEditor = async (editor, skipFormatting = false) => {
@@ -8373,29 +8381,41 @@ const save$1 = async (editor, skipFormatting = false) => {
8373
8381
  if (!isUntitledFile(uri) && (await isReadonlyFile(uri, applicationId))) {
8374
8382
  return editor;
8375
8383
  }
8376
- const newEditor = await getNewEditor(editor, skipFormatting);
8377
- const content = applyLineEndings(getText$1(newEditor), newEditor.endOfLine);
8384
+ const shouldFormat = editor.formatOnSave && !skipFormatting;
8385
+ const formatBeforeSave = shouldFormat && editor.formatActions === 'pre-save';
8386
+ const editorToSave = formatBeforeSave ? await getNewEditor(editor) : editor;
8387
+ const content = applyLineEndings(getText$1(editorToSave), editorToSave.endOfLine);
8378
8388
  if (isUntitledFile(uri)) {
8379
8389
  const pickedFilePath = await saveUntitledFile(uri, content, platform, applicationId);
8380
8390
  if (pickedFilePath) {
8381
- if (newEditor.modified) {
8391
+ const savedEditor = {
8392
+ ...editorToSave,
8393
+ uri: pickedFilePath
8394
+ };
8395
+ if (editor.modified || savedEditor.modified) {
8382
8396
  await notifyTabModifiedStatusChange(uri, false, applicationId);
8383
8397
  }
8384
8398
  return {
8385
- ...newEditor,
8399
+ ...savedEditor,
8386
8400
  modified: false,
8387
- uri: pickedFilePath
8401
+ uri: pickedFilePath,
8402
+ ...(shouldFormat && !formatBeforeSave && {
8403
+ postSaveFormat: true
8404
+ })
8388
8405
  };
8389
8406
  }
8390
- return newEditor;
8407
+ return editorToSave;
8391
8408
  }
8392
8409
  await saveNormalFile(uri, content, applicationId);
8393
- if (newEditor.modified) {
8410
+ if (editor.modified || editorToSave.modified) {
8394
8411
  await notifyTabModifiedStatusChange(uri, false, applicationId);
8395
8412
  }
8396
8413
  return {
8397
- ...newEditor,
8398
- modified: false
8414
+ ...editorToSave,
8415
+ modified: false,
8416
+ ...(shouldFormat && !formatBeforeSave && {
8417
+ postSaveFormat: true
8418
+ })
8399
8419
  };
8400
8420
  } catch (error) {
8401
8421
  // @ts-ignore
@@ -8490,6 +8510,25 @@ const registerStateCommand = command => {
8490
8510
  };
8491
8511
  const isStateCommand = command => stateCommands?.has(command) ?? false;
8492
8512
  const cursorUndoLimit = 100;
8513
+ const formatAfterSave = async (uid, snapshot) => {
8514
+ const originalText = getText$1(snapshot);
8515
+ const edits = await getFormattingEdits(snapshot);
8516
+ if (!edits?.length) {
8517
+ return;
8518
+ }
8519
+ const applyFormatting = wrapCommand$1(async editor => {
8520
+ const staleReason = snapshot.lifecycle ? editor.lifecycle === snapshot.lifecycle ? editor.uri === snapshot.uri ? editor.applicationId === snapshot.applicationId ? getText$1(editor) === originalText ? '' : `text:${originalText.length}:${getText$1(editor).length}` : 'application' : 'uri' : 'lifecycle' : 'missing-snapshot-lifecycle';
8521
+ if (staleReason) {
8522
+ return editor;
8523
+ }
8524
+ const formattedEditor = await applyDocumentEdits$1(editor, edits);
8525
+ if (formattedEditor === editor || getText$1(formattedEditor) === originalText) {
8526
+ return editor;
8527
+ }
8528
+ return save$1(formattedEditor, true);
8529
+ });
8530
+ await applyFormatting(uid);
8531
+ };
8493
8532
  const selectionsEqual = (left, right) => {
8494
8533
  if (left === right) {
8495
8534
  return true;
@@ -8555,10 +8594,18 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
8555
8594
  uri
8556
8595
  } = state;
8557
8596
  const commandResult = await fn(state, ...args);
8597
+ const shouldFormatAfterSave = commandResult?.postSaveFormat === true;
8558
8598
  let newEditor = !preservesTypingCoalescing && commandResult.canCoalesceTyping ? {
8559
8599
  ...commandResult,
8560
8600
  canCoalesceTyping: false
8561
8601
  } : commandResult;
8602
+ if (shouldFormatAfterSave) {
8603
+ const {
8604
+ postSaveFormat: _postSaveFormat,
8605
+ ...stateWithoutPostSaveFormat
8606
+ } = newEditor;
8607
+ newEditor = stateWithoutPostSaveFormat;
8608
+ }
8562
8609
  if (lines !== newEditor.lines && newEditor.cursorUndoStack?.length) {
8563
8610
  newEditor = {
8564
8611
  ...newEditor,
@@ -8627,6 +8674,9 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
8627
8674
  }
8628
8675
  }
8629
8676
  }
8677
+ if (shouldFormatAfterSave) {
8678
+ setTimeout(() => void formatAfterSave(uid, finalEditor), 0);
8679
+ }
8630
8680
  if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
8631
8681
  schedule$1(uid, token => saveAfterDelay(uid, token));
8632
8682
  } else if (modified && !finalEditor.modified) {
@@ -16947,6 +16997,9 @@ const DEFAULT_HORIZONTAL_VIRTUALIZATION_THRESHOLD = 500;
16947
16997
  const getSelectedTextOccurrenceMatching = value => {
16948
16998
  return value === 'caseInsensitive' ? value : DEFAULT_SELECTED_TEXT_OCCURRENCE_MATCHING;
16949
16999
  };
17000
+ const getFormatActions = value => {
17001
+ return value === 'pre-save' ? 'pre-save' : 'post-save';
17002
+ };
16950
17003
  const getHoverDelay = value => {
16951
17004
  const delay = typeof value === 'number' ? value : Number(value);
16952
17005
  if (!Number.isFinite(delay) || delay < 0) {
@@ -16969,7 +17022,7 @@ const getHorizontalVirtualizationThreshold = value => {
16969
17022
  return Math.floor(threshold);
16970
17023
  };
16971
17024
  const getEditorPreferences = async applicationId => {
16972
- const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching] = await Promise.all([get$3('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$3('editor.formatOnSave', applicationId), get$3('editor.hover', applicationId), get$3('editor.hoverDelay', applicationId), get$3('editor.horizontalVirtualizationThreshold', applicationId), get$3('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$3('breadcrumbs.enabled', applicationId), get$3('editor.insertSpaces', applicationId), get$3('editor.dragAndDrop', applicationId), get$3('editor.roundedSelection', applicationId), get$3('editor.combineWhitespaceTokens', applicationId), get$3('editor.selectedTextOccurrenceMatching', applicationId)]);
17025
+ const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, formatActions, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching] = await Promise.all([get$3('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$3('editor.formatOnSave', applicationId), get$3('editor.formatActions', applicationId), get$3('editor.hover', applicationId), get$3('editor.hoverDelay', applicationId), get$3('editor.horizontalVirtualizationThreshold', applicationId), get$3('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$3('breadcrumbs.enabled', applicationId), get$3('editor.insertSpaces', applicationId), get$3('editor.dragAndDrop', applicationId), get$3('editor.roundedSelection', applicationId), get$3('editor.combineWhitespaceTokens', applicationId), get$3('editor.selectedTextOccurrenceMatching', applicationId)]);
16973
17026
  return {
16974
17027
  breadcrumbsEnabled: breadcrumbsEnabled ?? false,
16975
17028
  combineWhitespaceTokens: combineWhitespaceTokens ?? true,
@@ -16979,6 +17032,7 @@ const getEditorPreferences = async applicationId => {
16979
17032
  fontFamily,
16980
17033
  fontSize,
16981
17034
  fontWeight,
17035
+ formatActions: getFormatActions(formatActions),
16982
17036
  formatOnSave: formatOnSave ?? false,
16983
17037
  highlightActiveLineNumber,
16984
17038
  horizontalVirtualizationThreshold: getHorizontalVirtualizationThreshold(horizontalVirtualizationThreshold),
@@ -17062,6 +17116,7 @@ const handleSettingsChanged = async state => {
17062
17116
  charWidth,
17063
17117
  completionsOnType: !state.largeFile && Boolean(completionsOnTypeRaw),
17064
17118
  diagnostics: diagnosticsEnabled ? state.diagnostics : [],
17119
+ formatActions: editorPreferences.formatActions === 'pre-save' ? 'pre-save' : 'post-save',
17065
17120
  isMonospaceFont,
17066
17121
  itemHeight: rowHeight,
17067
17122
  minimapRevision: (state.minimapRevision || 0) + (minimapEnabled ? 1 : 0),
@@ -17340,7 +17395,7 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
17340
17395
  };
17341
17396
 
17342
17397
  const largeFileContentLength = 10 * 1024 * 1024;
17343
- const editorFileCacheMaxBytes = 500_000;
17398
+ const editorFileCacheMaxBytes = 10 * 1024 * 1024;
17344
17399
  const pendingFileReads = new Map();
17345
17400
  const getFileStatFingerprint = stat => {
17346
17401
  if (!stat || typeof stat !== 'object' || !Number.isFinite(stat.size)) {
@@ -17523,6 +17578,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17523
17578
  fontFamily,
17524
17579
  fontSize,
17525
17580
  fontWeight,
17581
+ formatActions,
17526
17582
  formatOnSave,
17527
17583
  highlightActiveLineNumber,
17528
17584
  horizontalVirtualizationThreshold,
@@ -17562,6 +17618,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17562
17618
  fontFamily,
17563
17619
  fontSize,
17564
17620
  fontWeight,
17621
+ formatActions: formatActions === 'pre-save' ? 'pre-save' : 'post-save',
17565
17622
  formatOnSave,
17566
17623
  highlightActiveLineNumber,
17567
17624
  horizontalVirtualizationThreshold,
@@ -19425,15 +19482,24 @@ const revealProblem = (editor, rowIndex, columnIndex) => {
19425
19482
 
19426
19483
  const save = async (uid, skipFormatting = false) => {
19427
19484
  let savedFrom;
19485
+ let postSaveSnapshot;
19428
19486
  const saveContent = wrapCommand$1(async editor => {
19429
19487
  savedFrom = editor;
19430
- return save$1(editor, skipFormatting);
19488
+ const shouldFormatAfterSave = editor.formatOnSave && !skipFormatting && editor.formatActions !== 'pre-save';
19489
+ const savedEditor = await save$1(editor, skipFormatting || shouldFormatAfterSave);
19490
+ if (shouldFormatAfterSave && savedEditor !== editor) {
19491
+ postSaveSnapshot = savedEditor;
19492
+ }
19493
+ return savedEditor;
19431
19494
  });
19432
19495
  const saved = await saveContent(uid);
19433
19496
  if (savedFrom && saved && savedFrom.uri !== saved.uri) {
19434
19497
  // Retargeting calls Editor.handleUriChange, so release the editing queue first.
19435
19498
  await invoke$a(savedFrom.applicationId, 'Main.handleUriChange', savedFrom.uri, saved.uri);
19436
19499
  }
19500
+ if (saved && postSaveSnapshot) {
19501
+ setTimeout(() => void formatAfterSave(uid, saved), 0);
19502
+ }
19437
19503
  };
19438
19504
 
19439
19505
  const saveState = async (state, hotReload) => {
@@ -6775,6 +6775,7 @@ const createEditor = async ({
6775
6775
  fontFamily,
6776
6776
  fontSize,
6777
6777
  fontWeight,
6778
+ formatActions,
6778
6779
  formatOnSave,
6779
6780
  height,
6780
6781
  highlightActiveLineNumber = true,
@@ -6839,6 +6840,7 @@ const createEditor = async ({
6839
6840
  fontFamily,
6840
6841
  fontSize,
6841
6842
  fontWeight,
6843
+ formatActions,
6842
6844
  formatOnSave,
6843
6845
  gutterDecorations: [],
6844
6846
  gutterWidth: 0,
@@ -8412,7 +8414,7 @@ const applyEdit = async (editor, changes, selectionChanges) => {
8412
8414
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
8413
8415
  };
8414
8416
 
8415
- const getFormattingEdits = async editor => {
8417
+ const getFormattingEdits$1 = async editor => {
8416
8418
  if (editor.largeFile) {
8417
8419
  return [];
8418
8420
  }
@@ -8688,26 +8690,32 @@ const showErrorMessage = async (editor, rowIndex, columnIndex, message) => {
8688
8690
  };
8689
8691
 
8690
8692
  const expectedErrorMessage = 'Failed to execute formatting provider: FormattingError:';
8691
-
8692
- // TODO also format with cursor
8693
- const format = async editor => {
8693
+ const getFormattingEdits = async editor => {
8694
8694
  try {
8695
- const edits = await getFormattingEdits(editor);
8696
- return applyDocumentEdits$1(editor, edits);
8695
+ return await getFormattingEdits$1(editor);
8697
8696
  } catch (error) {
8698
8697
  if (isFormattingError(error)) {
8699
8698
  console.error('Formatting Error:',
8700
8699
  // @ts-ignore
8701
8700
  error.message.slice(expectedErrorMessage.length));
8702
- return editor;
8701
+ return undefined;
8703
8702
  }
8704
8703
  console.error(error);
8705
8704
 
8706
8705
  // TODO configure editor message as widget
8707
8706
  const displayErrorMessage = String(error);
8708
8707
  await editorShowMessage(editor, 0, 0, displayErrorMessage);
8708
+ return undefined;
8709
+ }
8710
+ };
8711
+
8712
+ // TODO also format with cursor
8713
+ const format = async editor => {
8714
+ const edits = await getFormattingEdits(editor);
8715
+ if (!edits) {
8709
8716
  return editor;
8710
8717
  }
8718
+ return applyDocumentEdits$1(editor, edits);
8711
8719
  };
8712
8720
 
8713
8721
  const getNewEditor = async (editor, skipFormatting = false) => {
@@ -8786,29 +8794,41 @@ const save$1 = async (editor, skipFormatting = false) => {
8786
8794
  if (!isUntitledFile(uri) && (await isReadonlyFile(uri, applicationId))) {
8787
8795
  return editor;
8788
8796
  }
8789
- const newEditor = await getNewEditor(editor, skipFormatting);
8790
- const content = applyLineEndings(getText$1(newEditor), newEditor.endOfLine);
8797
+ const shouldFormat = editor.formatOnSave && !skipFormatting;
8798
+ const formatBeforeSave = shouldFormat && editor.formatActions === 'pre-save';
8799
+ const editorToSave = formatBeforeSave ? await getNewEditor(editor) : editor;
8800
+ const content = applyLineEndings(getText$1(editorToSave), editorToSave.endOfLine);
8791
8801
  if (isUntitledFile(uri)) {
8792
8802
  const pickedFilePath = await saveUntitledFile(uri, content, platform, applicationId);
8793
8803
  if (pickedFilePath) {
8794
- if (newEditor.modified) {
8804
+ const savedEditor = {
8805
+ ...editorToSave,
8806
+ uri: pickedFilePath
8807
+ };
8808
+ if (editor.modified || savedEditor.modified) {
8795
8809
  await notifyTabModifiedStatusChange(uri, false, applicationId);
8796
8810
  }
8797
8811
  return {
8798
- ...newEditor,
8812
+ ...savedEditor,
8799
8813
  modified: false,
8800
- uri: pickedFilePath
8814
+ uri: pickedFilePath,
8815
+ ...(shouldFormat && !formatBeforeSave && {
8816
+ postSaveFormat: true
8817
+ })
8801
8818
  };
8802
8819
  }
8803
- return newEditor;
8820
+ return editorToSave;
8804
8821
  }
8805
8822
  await saveNormalFile(uri, content, applicationId);
8806
- if (newEditor.modified) {
8823
+ if (editor.modified || editorToSave.modified) {
8807
8824
  await notifyTabModifiedStatusChange(uri, false, applicationId);
8808
8825
  }
8809
8826
  return {
8810
- ...newEditor,
8811
- modified: false
8827
+ ...editorToSave,
8828
+ modified: false,
8829
+ ...(shouldFormat && !formatBeforeSave && {
8830
+ postSaveFormat: true
8831
+ })
8812
8832
  };
8813
8833
  } catch (error) {
8814
8834
  // @ts-ignore
@@ -8898,6 +8918,25 @@ const schedule = editor => {
8898
8918
  };
8899
8919
 
8900
8920
  const cursorUndoLimit = 100;
8921
+ const formatAfterSave = async (uid, snapshot) => {
8922
+ const originalText = getText$1(snapshot);
8923
+ const edits = await getFormattingEdits(snapshot);
8924
+ if (!edits?.length) {
8925
+ return;
8926
+ }
8927
+ const applyFormatting = wrapCommand$1(async editor => {
8928
+ const staleReason = snapshot.lifecycle ? editor.lifecycle === snapshot.lifecycle ? editor.uri === snapshot.uri ? editor.applicationId === snapshot.applicationId ? getText$1(editor) === originalText ? '' : `text:${originalText.length}:${getText$1(editor).length}` : 'application' : 'uri' : 'lifecycle' : 'missing-snapshot-lifecycle';
8929
+ if (staleReason) {
8930
+ return editor;
8931
+ }
8932
+ const formattedEditor = await applyDocumentEdits$1(editor, edits);
8933
+ if (formattedEditor === editor || getText$1(formattedEditor) === originalText) {
8934
+ return editor;
8935
+ }
8936
+ return save$1(formattedEditor, true);
8937
+ });
8938
+ await applyFormatting(uid);
8939
+ };
8901
8940
  const selectionsEqual = (left, right) => {
8902
8941
  if (left === right) {
8903
8942
  return true;
@@ -8963,10 +9002,18 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
8963
9002
  uri
8964
9003
  } = state;
8965
9004
  const commandResult = await fn(state, ...args);
9005
+ const shouldFormatAfterSave = commandResult?.postSaveFormat === true;
8966
9006
  let newEditor = !preservesTypingCoalescing && commandResult.canCoalesceTyping ? {
8967
9007
  ...commandResult,
8968
9008
  canCoalesceTyping: false
8969
9009
  } : commandResult;
9010
+ if (shouldFormatAfterSave) {
9011
+ const {
9012
+ postSaveFormat: _postSaveFormat,
9013
+ ...stateWithoutPostSaveFormat
9014
+ } = newEditor;
9015
+ newEditor = stateWithoutPostSaveFormat;
9016
+ }
8970
9017
  if (lines !== newEditor.lines && newEditor.cursorUndoStack?.length) {
8971
9018
  newEditor = {
8972
9019
  ...newEditor,
@@ -9035,6 +9082,9 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
9035
9082
  }
9036
9083
  }
9037
9084
  }
9085
+ if (shouldFormatAfterSave) {
9086
+ setTimeout(() => void formatAfterSave(uid, finalEditor), 0);
9087
+ }
9038
9088
  if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
9039
9089
  schedule$1(uid, token => saveAfterDelay(uid, token));
9040
9090
  } else if (modified && !finalEditor.modified) {
@@ -17351,6 +17401,9 @@ const DEFAULT_HORIZONTAL_VIRTUALIZATION_THRESHOLD = 500;
17351
17401
  const getSelectedTextOccurrenceMatching = value => {
17352
17402
  return value === 'caseInsensitive' ? value : DEFAULT_SELECTED_TEXT_OCCURRENCE_MATCHING;
17353
17403
  };
17404
+ const getFormatActions = value => {
17405
+ return value === 'pre-save' ? 'pre-save' : 'post-save';
17406
+ };
17354
17407
  const getHoverDelay = value => {
17355
17408
  const delay = typeof value === 'number' ? value : Number(value);
17356
17409
  if (!Number.isFinite(delay) || delay < 0) {
@@ -17373,7 +17426,7 @@ const getHorizontalVirtualizationThreshold = value => {
17373
17426
  return Math.floor(threshold);
17374
17427
  };
17375
17428
  const getEditorPreferences = async applicationId => {
17376
- const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching] = await Promise.all([get$3('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$3('editor.formatOnSave', applicationId), get$3('editor.hover', applicationId), get$3('editor.hoverDelay', applicationId), get$3('editor.horizontalVirtualizationThreshold', applicationId), get$3('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$3('breadcrumbs.enabled', applicationId), get$3('editor.insertSpaces', applicationId), get$3('editor.dragAndDrop', applicationId), get$3('editor.roundedSelection', applicationId), get$3('editor.combineWhitespaceTokens', applicationId), get$3('editor.selectedTextOccurrenceMatching', applicationId)]);
17429
+ const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, formatActions, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching] = await Promise.all([get$3('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$3('editor.formatOnSave', applicationId), get$3('editor.formatActions', applicationId), get$3('editor.hover', applicationId), get$3('editor.hoverDelay', applicationId), get$3('editor.horizontalVirtualizationThreshold', applicationId), get$3('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$3('breadcrumbs.enabled', applicationId), get$3('editor.insertSpaces', applicationId), get$3('editor.dragAndDrop', applicationId), get$3('editor.roundedSelection', applicationId), get$3('editor.combineWhitespaceTokens', applicationId), get$3('editor.selectedTextOccurrenceMatching', applicationId)]);
17377
17430
  return {
17378
17431
  breadcrumbsEnabled: breadcrumbsEnabled ?? false,
17379
17432
  combineWhitespaceTokens: combineWhitespaceTokens ?? true,
@@ -17383,6 +17436,7 @@ const getEditorPreferences = async applicationId => {
17383
17436
  fontFamily,
17384
17437
  fontSize,
17385
17438
  fontWeight,
17439
+ formatActions: getFormatActions(formatActions),
17386
17440
  formatOnSave: formatOnSave ?? false,
17387
17441
  highlightActiveLineNumber,
17388
17442
  horizontalVirtualizationThreshold: getHorizontalVirtualizationThreshold(horizontalVirtualizationThreshold),
@@ -17466,6 +17520,7 @@ const handleSettingsChanged = async state => {
17466
17520
  charWidth,
17467
17521
  completionsOnType: !state.largeFile && Boolean(completionsOnTypeRaw),
17468
17522
  diagnostics: diagnosticsEnabled ? state.diagnostics : [],
17523
+ formatActions: editorPreferences.formatActions === 'pre-save' ? 'pre-save' : 'post-save',
17469
17524
  isMonospaceFont,
17470
17525
  itemHeight: rowHeight,
17471
17526
  minimapRevision: (state.minimapRevision || 0) + (minimapEnabled ? 1 : 0),
@@ -17744,7 +17799,7 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
17744
17799
  };
17745
17800
 
17746
17801
  const largeFileContentLength = 10 * 1024 * 1024;
17747
- const editorFileCacheMaxBytes = 500_000;
17802
+ const editorFileCacheMaxBytes = 10 * 1024 * 1024;
17748
17803
  const pendingFileReads = new Map();
17749
17804
  const getFileStatFingerprint = stat => {
17750
17805
  if (!stat || typeof stat !== 'object' || !Number.isFinite(stat.size)) {
@@ -17927,6 +17982,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17927
17982
  fontFamily,
17928
17983
  fontSize,
17929
17984
  fontWeight,
17985
+ formatActions,
17930
17986
  formatOnSave,
17931
17987
  highlightActiveLineNumber,
17932
17988
  horizontalVirtualizationThreshold,
@@ -17966,6 +18022,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17966
18022
  fontFamily,
17967
18023
  fontSize,
17968
18024
  fontWeight,
18025
+ formatActions: formatActions === 'pre-save' ? 'pre-save' : 'post-save',
17969
18026
  formatOnSave,
17970
18027
  highlightActiveLineNumber,
17971
18028
  horizontalVirtualizationThreshold,
@@ -19829,15 +19886,24 @@ const revealProblem = (editor, rowIndex, columnIndex) => {
19829
19886
 
19830
19887
  const save = async (uid, skipFormatting = false) => {
19831
19888
  let savedFrom;
19889
+ let postSaveSnapshot;
19832
19890
  const saveContent = wrapCommand$1(async editor => {
19833
19891
  savedFrom = editor;
19834
- return save$1(editor, skipFormatting);
19892
+ const shouldFormatAfterSave = editor.formatOnSave && !skipFormatting && editor.formatActions !== 'pre-save';
19893
+ const savedEditor = await save$1(editor, skipFormatting || shouldFormatAfterSave);
19894
+ if (shouldFormatAfterSave && savedEditor !== editor) {
19895
+ postSaveSnapshot = savedEditor;
19896
+ }
19897
+ return savedEditor;
19835
19898
  });
19836
19899
  const saved = await saveContent(uid);
19837
19900
  if (savedFrom && saved && savedFrom.uri !== saved.uri) {
19838
19901
  // Retargeting calls Editor.handleUriChange, so release the editing queue first.
19839
19902
  await invoke$a(savedFrom.applicationId, 'Main.handleUriChange', savedFrom.uri, saved.uri);
19840
19903
  }
19904
+ if (saved && postSaveSnapshot) {
19905
+ setTimeout(() => void formatAfterSave(uid, saved), 0);
19906
+ }
19841
19907
  };
19842
19908
 
19843
19909
  const saveState = async (state, hotReload) => {
@@ -43,6 +43,24 @@
43
43
  "type": "boolean",
44
44
  "value": false
45
45
  },
46
+ {
47
+ "category": "text-editor",
48
+ "description": "Controls when formatting actions run during save",
49
+ "heading": "Format Actions",
50
+ "id": "editor.formatActions",
51
+ "options": [
52
+ {
53
+ "id": "pre-save",
54
+ "label": "Before saving"
55
+ },
56
+ {
57
+ "id": "post-save",
58
+ "label": "After saving"
59
+ }
60
+ ],
61
+ "type": "enum",
62
+ "value": "post-save"
63
+ },
46
64
  {
47
65
  "category": "text-editor",
48
66
  "description": "Show completions automatically while typing",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.76.4",
3
+ "version": "19.77.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"