@lvce-editor/editor-worker 19.67.4 → 19.67.6

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.
@@ -10379,8 +10379,15 @@ const handleTouchMove = (editor, touchEvent) => {
10379
10379
  };
10380
10380
 
10381
10381
  const handleUriChange = async (editor, newUri) => {
10382
+ const {
10383
+ explicitLanguageId,
10384
+ ...state
10385
+ } = editor;
10382
10386
  return {
10383
- ...editor,
10387
+ ...state,
10388
+ ...(editor.uri === newUri && explicitLanguageId && {
10389
+ explicitLanguageId
10390
+ }),
10384
10391
  uri: newUri
10385
10392
  };
10386
10393
  };
@@ -11927,10 +11934,11 @@ const setIndentation = (editor, insertSpaces) => {
11927
11934
  };
11928
11935
  };
11929
11936
 
11930
- const setLanguageId = async (editor, languageId, tokenizePath) => {
11937
+ const setLanguageId = async (editor, languageId, tokenizePath, isExplicit = false) => {
11931
11938
  if (editor.largeFile) {
11932
11939
  return {
11933
11940
  ...editor,
11941
+ explicitLanguageId: isExplicit ? languageId : editor.explicitLanguageId,
11934
11942
  languageId
11935
11943
  };
11936
11944
  }
@@ -11943,6 +11951,7 @@ const setLanguageId = async (editor, languageId, tokenizePath) => {
11943
11951
  set$3(newTokenizerId, tokenizer);
11944
11952
  return {
11945
11953
  ...editor,
11954
+ explicitLanguageId: isExplicit ? languageId : editor.explicitLanguageId,
11946
11955
  focused: true,
11947
11956
  invalidStartIndex: 0,
11948
11957
  languageId,
@@ -15087,6 +15096,21 @@ const getSavedHistory = (savedState, content) => {
15087
15096
  undoStack
15088
15097
  };
15089
15098
  };
15099
+ const getSavedLanguageId = (savedState, languages) => {
15100
+ if (!savedState || typeof savedState !== 'object') {
15101
+ return undefined;
15102
+ }
15103
+ const {
15104
+ explicitLanguageId
15105
+ } = savedState;
15106
+ if (typeof explicitLanguageId !== 'string' || !explicitLanguageId) {
15107
+ return undefined;
15108
+ }
15109
+ if (languages.every(language => language?.id !== explicitLanguageId)) {
15110
+ return undefined;
15111
+ }
15112
+ return explicitLanguageId;
15113
+ };
15090
15114
  const loadContent = async (state, savedState, largeFile = false) => {
15091
15115
  const {
15092
15116
  assetDir,
@@ -15128,7 +15152,8 @@ const loadContent = async (state, savedState, largeFile = false) => {
15128
15152
  const charWidth = await measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing);
15129
15153
  const languages = await getLanguages(platform, assetDir);
15130
15154
  setTokenizePaths(languages);
15131
- const computedLanguageId = getLanguageId$1(uri, languages);
15155
+ const explicitLanguageId = getSavedLanguageId(savedState, languages);
15156
+ const computedLanguageId = explicitLanguageId || getLanguageId$1(uri, languages);
15132
15157
  const newEditor0 = {
15133
15158
  ...state,
15134
15159
  breadcrumbsEnabled,
@@ -15137,6 +15162,9 @@ const loadContent = async (state, savedState, largeFile = false) => {
15137
15162
  completionTriggerCharacters,
15138
15163
  diagnosticsEnabled,
15139
15164
  dragAndDropEnabled,
15165
+ ...(explicitLanguageId && {
15166
+ explicitLanguageId
15167
+ }),
15140
15168
  fontFamily,
15141
15169
  fontSize,
15142
15170
  fontWeight,
@@ -16629,12 +16657,16 @@ const revealProblem = (editor, rowIndex, columnIndex) => {
16629
16657
 
16630
16658
  const saveState = (state, savedState) => {
16631
16659
  const {
16660
+ explicitLanguageId,
16632
16661
  largeFile,
16633
16662
  lines,
16634
16663
  redoStack,
16635
16664
  undoStack
16636
16665
  } = state;
16637
16666
  return {
16667
+ ...(explicitLanguageId && {
16668
+ explicitLanguageId
16669
+ }),
16638
16670
  ...(largeFile && {
16639
16671
  largeFile: true
16640
16672
  }),
@@ -16830,7 +16862,7 @@ const diagnosticsEqual = (left, right) => {
16830
16862
  });
16831
16863
  };
16832
16864
  const diagnosticLayoutEqual = (left, right) => left.charWidth === right.charWidth && left.deltaY === right.deltaY && left.fontFamily === right.fontFamily && left.fontSize === right.fontSize && left.fontWeight === right.fontWeight && left.isMonospaceFont === right.isMonospaceFont && left.itemHeight === right.itemHeight && left.letterSpacing === right.letterSpacing && left.lines === right.lines && left.minLineY === right.minLineY && left.rowHeight === right.rowHeight && left.tabSize === right.tabSize && left.viewLineIndices === right.viewLineIndices && left.width === right.width;
16833
- const isApplicable = (latest, editor) => latest && latest.newState.diagnosticsEnabled && latest.newState.diagnostics === editor.diagnostics && latest.newState.languageId === editor.languageId && latest.newState.lines === editor.lines && latest.newState.uri === editor.uri;
16865
+ const isApplicable = (latest, editor) => latest && latest.newState.diagnosticsEnabled && !latest.newState.loadError && latest.newState.diagnostics === editor.diagnostics && latest.newState.languageId === editor.languageId && latest.newState.lines === editor.lines && latest.newState.uri === editor.uri;
16834
16866
  const mergeDiagnostics = (editor, editorWithDiagnostics) => ({
16835
16867
  ...editor,
16836
16868
  decorations: editorWithDiagnostics.decorations,
@@ -16839,7 +16871,7 @@ const mergeDiagnostics = (editor, editorWithDiagnostics) => ({
16839
16871
  visualDecorations: editorWithDiagnostics.visualDecorations
16840
16872
  });
16841
16873
  const updateDiagnostics = async editor => {
16842
- if (!editor.diagnosticsEnabled) {
16874
+ if (!editor.diagnosticsEnabled || editor.loadError) {
16843
16875
  return editor;
16844
16876
  }
16845
16877
  try {
@@ -16894,7 +16926,7 @@ const editorDiagnosticEffect = {
16894
16926
  apply(editor) {
16895
16927
  return updateDiagnostics(editor);
16896
16928
  },
16897
- isActive: (oldEditor, newEditor) => !oldEditor.initial && newEditor.diagnosticsEnabled && (oldEditor.lines !== newEditor.lines || oldEditor.languageId !== newEditor.languageId)
16929
+ isActive: (oldEditor, newEditor) => !oldEditor.initial && !newEditor.loadError && newEditor.diagnosticsEnabled && (oldEditor.lines !== newEditor.lines || oldEditor.languageId !== newEditor.languageId)
16898
16930
  };
16899
16931
 
16900
16932
  const cursorUndoLimit = 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.67.4",
3
+ "version": "19.67.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"