@lvce-editor/editor-worker 19.19.0 → 19.20.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.
@@ -4158,6 +4158,10 @@ const getLanguageByFileName = (languages, fileNameLower) => {
4158
4158
  }
4159
4159
  return '';
4160
4160
  };
4161
+ const getFileName = uri => {
4162
+ const slashIndex = Math.max(uri.lastIndexOf('/'), uri.lastIndexOf('\\'));
4163
+ return uri.slice(slashIndex + 1);
4164
+ };
4161
4165
  const getLanguageId$1 = (uri, languages) => {
4162
4166
  string(uri);
4163
4167
  // TODO this is inefficient for icon theme, as file extension is computed twice
@@ -4170,7 +4174,7 @@ const getLanguageId$1 = (uri, languages) => {
4170
4174
  if (candidate1) {
4171
4175
  return candidate1;
4172
4176
  }
4173
- const fileNameLower = uri.toLowerCase();
4177
+ const fileNameLower = getFileName(uri).toLowerCase();
4174
4178
  const secondExtensionIndex = getNthFileExtension(uri, extensionIndex - 1);
4175
4179
  const secondExtension = uri.slice(secondExtensionIndex);
4176
4180
  const candidate2 = getLanguageByExtension(languages, secondExtension);
@@ -7573,6 +7577,15 @@ const handleTouchMove = (editor, touchEvent) => {
7573
7577
  setDeltaYFixedValue(editor, offsetY);
7574
7578
  };
7575
7579
 
7580
+ const handleUriChange = async (editor, newUri) => {
7581
+ const content = getText$1(editor);
7582
+ await invoke$6(TextDocumentSyncFull, newUri, editor.id, editor.languageId, content);
7583
+ return {
7584
+ ...editor,
7585
+ uri: newUri
7586
+ };
7587
+ };
7588
+
7576
7589
  // Keep wheel handling as a dedicated command entry point and delegate
7577
7590
  // the actual scroll state update to the shared setDelta logic.
7578
7591
  // @ts-ignore
@@ -11215,6 +11228,104 @@ const handleMessagePort = async (port, rpcId) => {
11215
11228
  }
11216
11229
  };
11217
11230
 
11231
+ const kLineHeight = 'editor.lineHeight';
11232
+ const kFontSize = 'editor.fontSize';
11233
+ const kFontFamily = 'editor.fontFamily';
11234
+ const kLetterSpacing = 'editor.letterSpacing';
11235
+ const kTabSize = 'editor.tabSize';
11236
+ const kLineNumbers = 'editor.lineNumbers';
11237
+ const kDiagnostics = 'editor.diagnostics';
11238
+ const kQuickSuggestions = 'editor.quickSuggestions';
11239
+ const kAutoClosingQuotes = 'editor.autoClosingQuotes';
11240
+ const kAutoClosingBrackets = 'editor.autoclosingBrackets';
11241
+ const kFontWeight = 'editor.fontWeight';
11242
+ const isAutoClosingBracketsEnabled = async () => {
11243
+ return Boolean(await get$2(kAutoClosingBrackets));
11244
+ };
11245
+ const isAutoClosingQuotesEnabled = async () => {
11246
+ return Boolean(await get$2(kAutoClosingQuotes));
11247
+ };
11248
+ const isQuickSuggestionsEnabled = async () => {
11249
+ return Boolean(await get$2(kQuickSuggestions));
11250
+ };
11251
+ const isAutoClosingTagsEnabled = async () => {
11252
+ return true;
11253
+ };
11254
+ const getRowHeight = async () => {
11255
+ return (await get$2(kLineHeight)) || 20;
11256
+ };
11257
+ const getFontSize = async () => {
11258
+ return (await get$2(kFontSize)) || 15; // TODO find out if it is possible to use all numeric values for settings for efficiency, maybe settings could be an array
11259
+ };
11260
+ const getFontFamily = async () => {
11261
+ return (await get$2(kFontFamily)) || 'Fira Code';
11262
+ };
11263
+ const getLetterSpacing = async () => {
11264
+ // if (!false) {
11265
+ // return 0
11266
+ // }
11267
+ return (await get$2(kLetterSpacing)) ?? 0.5;
11268
+ };
11269
+ const getTabSize = async () => {
11270
+ return (await get$2(kTabSize)) || 2;
11271
+ };
11272
+ const getLineNumbers = async () => {
11273
+ return (await get$2(kLineNumbers)) ?? false;
11274
+ };
11275
+ const getCompletionTriggerCharacters = async () => {
11276
+ return ['.', '/'];
11277
+ };
11278
+ const diagnosticsEnabled = async () => {
11279
+ return (await get$2(kDiagnostics)) ?? false;
11280
+ };
11281
+ const getFontWeight = async () => {
11282
+ return (await get$2(kFontWeight)) ?? 400;
11283
+ };
11284
+
11285
+ const getEditorPreferences = async () => {
11286
+ const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters()]);
11287
+ return {
11288
+ completionTriggerCharacters,
11289
+ diagnosticsEnabled: diagnosticsEnabled$1,
11290
+ fontFamily,
11291
+ fontSize,
11292
+ fontWeight,
11293
+ isAutoClosingBracketsEnabled: isAutoClosingBracketsEnabled$1,
11294
+ isAutoClosingQuotesEnabled: isAutoClosingQuotesEnabled$1,
11295
+ isAutoClosingTagsEnabled: isAutoClosingTagsEnabled$1,
11296
+ isQuickSuggestionsEnabled: isQuickSuggestionsEnabled$1,
11297
+ letterSpacing,
11298
+ lineNumbers,
11299
+ rowHeight,
11300
+ tabSize
11301
+ };
11302
+ };
11303
+
11304
+ const handleSettingsChanged = async state => {
11305
+ const editorPreferences = await getEditorPreferences();
11306
+ const {
11307
+ diagnosticsEnabled,
11308
+ fontFamily,
11309
+ fontSize,
11310
+ fontWeight,
11311
+ letterSpacing,
11312
+ rowHeight
11313
+ } = editorPreferences;
11314
+ const [charWidth, completionsOnTypeRaw] = await Promise.all([measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing), get$2('editor.completionsOnType')]);
11315
+ const isMonospaceFont = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
11316
+ const editorWithUpdatedSettings = {
11317
+ ...state,
11318
+ ...editorPreferences,
11319
+ charWidth,
11320
+ completionsOnType: Boolean(completionsOnTypeRaw),
11321
+ diagnostics: diagnosticsEnabled ? state.diagnostics : [],
11322
+ isMonospaceFont,
11323
+ itemHeight: rowHeight,
11324
+ visualDecorations: diagnosticsEnabled ? state.visualDecorations : []
11325
+ };
11326
+ return resize(editorWithUpdatedSettings, {}, charWidth);
11327
+ };
11328
+
11218
11329
  const applyTabCompletion = (editor, result) => {
11219
11330
  return editorSnippet(editor, result);
11220
11331
  };
@@ -11420,79 +11531,6 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
11420
11531
  await initializeSyntaxHighlighting(syntaxHighlightingEnabled, syncIncremental);
11421
11532
  };
11422
11533
 
11423
- const kLineHeight = 'editor.lineHeight';
11424
- const kFontSize = 'editor.fontSize';
11425
- const kFontFamily = 'editor.fontFamily';
11426
- const kLetterSpacing = 'editor.letterSpacing';
11427
- const kTabSize = 'editor.tabSize';
11428
- const kLineNumbers = 'editor.lineNumbers';
11429
- const kDiagnostics = 'editor.diagnostics';
11430
- const kQuickSuggestions = 'editor.quickSuggestions';
11431
- const kAutoClosingQuotes = 'editor.autoClosingQuotes';
11432
- const kAutoClosingBrackets = 'editor.autoclosingBrackets';
11433
- const kFontWeight = 'editor.fontWeight';
11434
- const isAutoClosingBracketsEnabled = async () => {
11435
- return Boolean(await get$2(kAutoClosingBrackets));
11436
- };
11437
- const isAutoClosingQuotesEnabled = async () => {
11438
- return Boolean(await get$2(kAutoClosingQuotes));
11439
- };
11440
- const isQuickSuggestionsEnabled = async () => {
11441
- return Boolean(await get$2(kQuickSuggestions));
11442
- };
11443
- const isAutoClosingTagsEnabled = async () => {
11444
- return true;
11445
- };
11446
- const getRowHeight = async () => {
11447
- return (await get$2(kLineHeight)) || 20;
11448
- };
11449
- const getFontSize = async () => {
11450
- return (await get$2(kFontSize)) || 15; // TODO find out if it is possible to use all numeric values for settings for efficiency, maybe settings could be an array
11451
- };
11452
- const getFontFamily = async () => {
11453
- return (await get$2(kFontFamily)) || 'Fira Code';
11454
- };
11455
- const getLetterSpacing = async () => {
11456
- // if (!false) {
11457
- // return 0
11458
- // }
11459
- return (await get$2(kLetterSpacing)) ?? 0.5;
11460
- };
11461
- const getTabSize = async () => {
11462
- return (await get$2(kTabSize)) || 2;
11463
- };
11464
- const getLineNumbers = async () => {
11465
- return (await get$2(kLineNumbers)) ?? false;
11466
- };
11467
- const getCompletionTriggerCharacters = async () => {
11468
- return ['.', '/'];
11469
- };
11470
- const diagnosticsEnabled = async () => {
11471
- return (await get$2(kDiagnostics)) ?? false;
11472
- };
11473
- const getFontWeight = async () => {
11474
- return (await get$2(kFontWeight)) ?? 400;
11475
- };
11476
-
11477
- const getEditorPreferences = async () => {
11478
- const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters()]);
11479
- return {
11480
- completionTriggerCharacters,
11481
- diagnosticsEnabled: diagnosticsEnabled$1,
11482
- fontFamily,
11483
- fontSize,
11484
- fontWeight,
11485
- isAutoClosingBracketsEnabled: isAutoClosingBracketsEnabled$1,
11486
- isAutoClosingQuotesEnabled: isAutoClosingQuotesEnabled$1,
11487
- isAutoClosingTagsEnabled: isAutoClosingTagsEnabled$1,
11488
- isQuickSuggestionsEnabled: isQuickSuggestionsEnabled$1,
11489
- letterSpacing,
11490
- lineNumbers,
11491
- rowHeight,
11492
- tabSize
11493
- };
11494
- };
11495
-
11496
11534
  const getTokenizePath = (languages, languageId) => {
11497
11535
  for (const language of languages) {
11498
11536
  if (language?.id === languageId && language.tokenize) {
@@ -12638,24 +12676,37 @@ const updateDebugInfo = async debugId => {
12638
12676
  await invoke$b('Editor.rerender', key);
12639
12677
  };
12640
12678
 
12679
+ const queues = [];
12680
+
12641
12681
  // TODO wrap commands globally, not per editor
12642
12682
  // TODO only store editor state in editor worker, not in renderer worker also
12643
12683
 
12644
- const wrapCommand = fn => async (editorUid, ...args) => {
12645
- const oldInstance = get$7(editorUid);
12646
- const state = oldInstance.newState;
12647
- const newEditor = await fn(state, ...args);
12648
- if (state === newEditor) {
12649
- return newEditor;
12684
+ const wrapCommand = fn => async (uid, ...args) => {
12685
+ const previous = queues[uid];
12686
+ const {
12687
+ promise: next,
12688
+ resolve
12689
+ } = Promise.withResolvers();
12690
+ queues[uid] = next;
12691
+ if (previous) {
12692
+ await previous;
12693
+ }
12694
+ try {
12695
+ const oldInstance = get$7(uid);
12696
+ const state = oldInstance.newState;
12697
+ const newEditor = await fn(state, ...args);
12698
+ if (state === newEditor) {
12699
+ return newEditor;
12700
+ }
12701
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12702
+ set$9(uid, state, newEditorWithDerivedState);
12703
+ return newEditorWithDerivedState;
12704
+ } finally {
12705
+ resolve();
12706
+ if (queues[uid] === next) {
12707
+ queues[uid] = undefined;
12708
+ }
12650
12709
  }
12651
- const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12652
-
12653
- // TODO if editor did not change, no need to update furthur
12654
-
12655
- // TODO combine neweditor with latest editor?
12656
-
12657
- set$9(editorUid, state, newEditorWithDerivedState);
12658
- return newEditorWithDerivedState;
12659
12710
  };
12660
12711
 
12661
12712
  const commandMap = {
@@ -12766,12 +12817,14 @@ const commandMap = {
12766
12817
  'Editor.handleScrollBarVerticalMove': wrapCommand(handleScrollBarVerticalPointerMove),
12767
12818
  'Editor.handleScrollBarVerticalPointerDown': wrapCommand(handleScrollBarPointerDown),
12768
12819
  'Editor.handleScrollBarVerticalPointerMove': wrapCommand(handleScrollBarVerticalPointerMove),
12820
+ 'Editor.handleSettingsChanged': wrapCommand(handleSettingsChanged),
12769
12821
  'Editor.handleSingleClick': wrapCommand(handleSingleClick),
12770
12822
  'Editor.handleTab': wrapCommand(handleTab),
12771
12823
  'Editor.handleTouchEnd': wrapCommand(handleTouchEnd),
12772
12824
  'Editor.handleTouchMove': wrapCommand(handleTouchMove),
12773
12825
  'Editor.handleTouchStart': wrapCommand(handleTouchStart),
12774
12826
  'Editor.handleTripleClick': wrapCommand(handleTripleClick),
12827
+ 'Editor.handleUriChange': wrapCommand(handleUriChange),
12775
12828
  'Editor.handleWheel': wrapCommand(handleWheel$2),
12776
12829
  'Editor.hotReload': hotReload,
12777
12830
  'Editor.indendLess': wrapCommand(indentLess),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.19.0",
3
+ "version": "19.20.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"