@lvce-editor/editor-worker 19.18.1 → 19.20.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.
@@ -8599,47 +8599,17 @@ const setDecorations = (editor, decorations, diagnostics) => {
8599
8599
  };
8600
8600
  };
8601
8601
 
8602
- // TODO add command to set language id
8603
- // without needing to specify tokenizePath
8604
8602
  const setLanguageId = async (editor, languageId, tokenizePath) => {
8605
8603
  const {
8606
8604
  tokenizerId
8607
8605
  } = editor;
8608
- setTokenizePath(languageId, tokenizePath);
8609
- // TODO move tokenizer to syntax highlighting worker
8610
- // TODO only load tokenizer if not already loaded
8611
- // if already loaded just set tokenizer and rerender text
8612
- // TODO race condition
8613
8606
  await loadTokenizer(languageId, tokenizePath);
8614
8607
  const tokenizer = getTokenizer(languageId);
8615
8608
  const newTokenizerId = tokenizerId + 1;
8616
8609
  set$4(newTokenizerId, tokenizer);
8617
- const latest = getEditor$1(editor.uid);
8618
- if (!latest) {
8619
- return editor;
8620
- }
8621
- const syncIncremental = getEnabled();
8622
- const {
8623
- differences,
8624
- textInfos
8625
- } = await getVisible$1(editor, syncIncremental);
8626
- const latest2 = getEditor$1(editor.uid);
8627
- if (!latest2) {
8628
- return editor;
8629
- }
8630
- const newEditor4 = {
8631
- ...latest2,
8632
- differences,
8633
- focused: true,
8634
- textInfos
8635
- };
8636
-
8637
- // TODO don't update editor if tokenizer was already loaded
8638
- // TODO update syntax highlighting
8639
- // TODO get edits
8640
-
8641
8610
  return {
8642
- ...newEditor4,
8611
+ ...editor,
8612
+ focused: true,
8643
8613
  invalidStartIndex: 0,
8644
8614
  languageId,
8645
8615
  tokenizerId: newTokenizerId
@@ -11245,6 +11215,104 @@ const handleMessagePort = async (port, rpcId) => {
11245
11215
  }
11246
11216
  };
11247
11217
 
11218
+ const kLineHeight = 'editor.lineHeight';
11219
+ const kFontSize = 'editor.fontSize';
11220
+ const kFontFamily = 'editor.fontFamily';
11221
+ const kLetterSpacing = 'editor.letterSpacing';
11222
+ const kTabSize = 'editor.tabSize';
11223
+ const kLineNumbers = 'editor.lineNumbers';
11224
+ const kDiagnostics = 'editor.diagnostics';
11225
+ const kQuickSuggestions = 'editor.quickSuggestions';
11226
+ const kAutoClosingQuotes = 'editor.autoClosingQuotes';
11227
+ const kAutoClosingBrackets = 'editor.autoclosingBrackets';
11228
+ const kFontWeight = 'editor.fontWeight';
11229
+ const isAutoClosingBracketsEnabled = async () => {
11230
+ return Boolean(await get$2(kAutoClosingBrackets));
11231
+ };
11232
+ const isAutoClosingQuotesEnabled = async () => {
11233
+ return Boolean(await get$2(kAutoClosingQuotes));
11234
+ };
11235
+ const isQuickSuggestionsEnabled = async () => {
11236
+ return Boolean(await get$2(kQuickSuggestions));
11237
+ };
11238
+ const isAutoClosingTagsEnabled = async () => {
11239
+ return true;
11240
+ };
11241
+ const getRowHeight = async () => {
11242
+ return (await get$2(kLineHeight)) || 20;
11243
+ };
11244
+ const getFontSize = async () => {
11245
+ 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
11246
+ };
11247
+ const getFontFamily = async () => {
11248
+ return (await get$2(kFontFamily)) || 'Fira Code';
11249
+ };
11250
+ const getLetterSpacing = async () => {
11251
+ // if (!false) {
11252
+ // return 0
11253
+ // }
11254
+ return (await get$2(kLetterSpacing)) ?? 0.5;
11255
+ };
11256
+ const getTabSize = async () => {
11257
+ return (await get$2(kTabSize)) || 2;
11258
+ };
11259
+ const getLineNumbers = async () => {
11260
+ return (await get$2(kLineNumbers)) ?? false;
11261
+ };
11262
+ const getCompletionTriggerCharacters = async () => {
11263
+ return ['.', '/'];
11264
+ };
11265
+ const diagnosticsEnabled = async () => {
11266
+ return (await get$2(kDiagnostics)) ?? false;
11267
+ };
11268
+ const getFontWeight = async () => {
11269
+ return (await get$2(kFontWeight)) ?? 400;
11270
+ };
11271
+
11272
+ const getEditorPreferences = async () => {
11273
+ 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()]);
11274
+ return {
11275
+ completionTriggerCharacters,
11276
+ diagnosticsEnabled: diagnosticsEnabled$1,
11277
+ fontFamily,
11278
+ fontSize,
11279
+ fontWeight,
11280
+ isAutoClosingBracketsEnabled: isAutoClosingBracketsEnabled$1,
11281
+ isAutoClosingQuotesEnabled: isAutoClosingQuotesEnabled$1,
11282
+ isAutoClosingTagsEnabled: isAutoClosingTagsEnabled$1,
11283
+ isQuickSuggestionsEnabled: isQuickSuggestionsEnabled$1,
11284
+ letterSpacing,
11285
+ lineNumbers,
11286
+ rowHeight,
11287
+ tabSize
11288
+ };
11289
+ };
11290
+
11291
+ const handleSettingsChanged = async state => {
11292
+ const editorPreferences = await getEditorPreferences();
11293
+ const {
11294
+ diagnosticsEnabled,
11295
+ fontFamily,
11296
+ fontSize,
11297
+ fontWeight,
11298
+ letterSpacing,
11299
+ rowHeight
11300
+ } = editorPreferences;
11301
+ const [charWidth, completionsOnTypeRaw] = await Promise.all([measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing), get$2('editor.completionsOnType')]);
11302
+ const isMonospaceFont = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
11303
+ const editorWithUpdatedSettings = {
11304
+ ...state,
11305
+ ...editorPreferences,
11306
+ charWidth,
11307
+ completionsOnType: Boolean(completionsOnTypeRaw),
11308
+ diagnostics: diagnosticsEnabled ? state.diagnostics : [],
11309
+ isMonospaceFont,
11310
+ itemHeight: rowHeight,
11311
+ visualDecorations: diagnosticsEnabled ? state.visualDecorations : []
11312
+ };
11313
+ return resize(editorWithUpdatedSettings, {}, charWidth);
11314
+ };
11315
+
11248
11316
  const applyTabCompletion = (editor, result) => {
11249
11317
  return editorSnippet(editor, result);
11250
11318
  };
@@ -11450,79 +11518,6 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
11450
11518
  await initializeSyntaxHighlighting(syntaxHighlightingEnabled, syncIncremental);
11451
11519
  };
11452
11520
 
11453
- const kLineHeight = 'editor.lineHeight';
11454
- const kFontSize = 'editor.fontSize';
11455
- const kFontFamily = 'editor.fontFamily';
11456
- const kLetterSpacing = 'editor.letterSpacing';
11457
- const kTabSize = 'editor.tabSize';
11458
- const kLineNumbers = 'editor.lineNumbers';
11459
- const kDiagnostics = 'editor.diagnostics';
11460
- const kQuickSuggestions = 'editor.quickSuggestions';
11461
- const kAutoClosingQuotes = 'editor.autoClosingQuotes';
11462
- const kAutoClosingBrackets = 'editor.autoclosingBrackets';
11463
- const kFontWeight = 'editor.fontWeight';
11464
- const isAutoClosingBracketsEnabled = async () => {
11465
- return Boolean(await get$2(kAutoClosingBrackets));
11466
- };
11467
- const isAutoClosingQuotesEnabled = async () => {
11468
- return Boolean(await get$2(kAutoClosingQuotes));
11469
- };
11470
- const isQuickSuggestionsEnabled = async () => {
11471
- return Boolean(await get$2(kQuickSuggestions));
11472
- };
11473
- const isAutoClosingTagsEnabled = async () => {
11474
- return true;
11475
- };
11476
- const getRowHeight = async () => {
11477
- return (await get$2(kLineHeight)) || 20;
11478
- };
11479
- const getFontSize = async () => {
11480
- 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
11481
- };
11482
- const getFontFamily = async () => {
11483
- return (await get$2(kFontFamily)) || 'Fira Code';
11484
- };
11485
- const getLetterSpacing = async () => {
11486
- // if (!false) {
11487
- // return 0
11488
- // }
11489
- return (await get$2(kLetterSpacing)) ?? 0.5;
11490
- };
11491
- const getTabSize = async () => {
11492
- return (await get$2(kTabSize)) || 2;
11493
- };
11494
- const getLineNumbers = async () => {
11495
- return (await get$2(kLineNumbers)) ?? false;
11496
- };
11497
- const getCompletionTriggerCharacters = async () => {
11498
- return ['.', '/'];
11499
- };
11500
- const diagnosticsEnabled = async () => {
11501
- return (await get$2(kDiagnostics)) ?? false;
11502
- };
11503
- const getFontWeight = async () => {
11504
- return (await get$2(kFontWeight)) ?? 400;
11505
- };
11506
-
11507
- const getEditorPreferences = async () => {
11508
- 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()]);
11509
- return {
11510
- completionTriggerCharacters,
11511
- diagnosticsEnabled: diagnosticsEnabled$1,
11512
- fontFamily,
11513
- fontSize,
11514
- fontWeight,
11515
- isAutoClosingBracketsEnabled: isAutoClosingBracketsEnabled$1,
11516
- isAutoClosingQuotesEnabled: isAutoClosingQuotesEnabled$1,
11517
- isAutoClosingTagsEnabled: isAutoClosingTagsEnabled$1,
11518
- isQuickSuggestionsEnabled: isQuickSuggestionsEnabled$1,
11519
- letterSpacing,
11520
- lineNumbers,
11521
- rowHeight,
11522
- tabSize
11523
- };
11524
- };
11525
-
11526
11521
  const getTokenizePath = (languages, languageId) => {
11527
11522
  for (const language of languages) {
11528
11523
  if (language?.id === languageId && language.tokenize) {
@@ -12668,24 +12663,37 @@ const updateDebugInfo = async debugId => {
12668
12663
  await invoke$b('Editor.rerender', key);
12669
12664
  };
12670
12665
 
12666
+ const queues = [];
12667
+
12671
12668
  // TODO wrap commands globally, not per editor
12672
12669
  // TODO only store editor state in editor worker, not in renderer worker also
12673
12670
 
12674
- const wrapCommand = fn => async (editorUid, ...args) => {
12675
- const oldInstance = get$7(editorUid);
12676
- const state = oldInstance.newState;
12677
- const newEditor = await fn(state, ...args);
12678
- if (state === newEditor) {
12679
- return newEditor;
12671
+ const wrapCommand = fn => async (uid, ...args) => {
12672
+ const previous = queues[uid];
12673
+ const {
12674
+ promise: next,
12675
+ resolve
12676
+ } = Promise.withResolvers();
12677
+ queues[uid] = next;
12678
+ if (previous) {
12679
+ await previous;
12680
+ }
12681
+ try {
12682
+ const oldInstance = get$7(uid);
12683
+ const state = oldInstance.newState;
12684
+ const newEditor = await fn(state, ...args);
12685
+ if (state === newEditor) {
12686
+ return newEditor;
12687
+ }
12688
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12689
+ set$9(uid, state, newEditorWithDerivedState);
12690
+ return newEditorWithDerivedState;
12691
+ } finally {
12692
+ resolve();
12693
+ if (queues[uid] === next) {
12694
+ queues[uid] = undefined;
12695
+ }
12680
12696
  }
12681
- const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12682
-
12683
- // TODO if editor did not change, no need to update furthur
12684
-
12685
- // TODO combine neweditor with latest editor?
12686
-
12687
- set$9(editorUid, state, newEditorWithDerivedState);
12688
- return newEditorWithDerivedState;
12689
12697
  };
12690
12698
 
12691
12699
  const commandMap = {
@@ -12796,6 +12804,7 @@ const commandMap = {
12796
12804
  'Editor.handleScrollBarVerticalMove': wrapCommand(handleScrollBarVerticalPointerMove),
12797
12805
  'Editor.handleScrollBarVerticalPointerDown': wrapCommand(handleScrollBarPointerDown),
12798
12806
  'Editor.handleScrollBarVerticalPointerMove': wrapCommand(handleScrollBarVerticalPointerMove),
12807
+ 'Editor.handleSettingsChanged': wrapCommand(handleSettingsChanged),
12799
12808
  'Editor.handleSingleClick': wrapCommand(handleSingleClick),
12800
12809
  'Editor.handleTab': wrapCommand(handleTab),
12801
12810
  'Editor.handleTouchEnd': wrapCommand(handleTouchEnd),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.18.1",
3
+ "version": "19.20.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"