@lvce-editor/editor-worker 5.3.0 → 5.4.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.
@@ -483,6 +483,10 @@ const getTabCount = string => {
483
483
  return count;
484
484
  };
485
485
 
486
+ const measureTextWidthFast = (text, charWidth) => {
487
+ return text.length * charWidth;
488
+ };
489
+
486
490
  const getFontString = (fontWeight, fontSize, fontFamily) => {
487
491
  return `${fontWeight} ${fontSize}px ${fontFamily}`;
488
492
  };
@@ -516,16 +520,15 @@ const getContext = () => {
516
520
  return ctx;
517
521
  };
518
522
 
519
- const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
523
+ // TODO for text editor, could dispose measuring canvas after editor has been initialized to free up offscreencanvas space
524
+
525
+ const measureTextWidthSlow = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
520
526
  string(text);
521
527
  number$1(fontWeight);
522
528
  number$1(fontSize);
523
529
  string(fontFamily);
524
530
  boolean(isMonoSpaceFont);
525
531
  number$1(charWidth);
526
- if (isMonoSpaceFont) {
527
- return text.length * charWidth;
528
- }
529
532
  if (typeof letterSpacing !== 'number') {
530
533
  throw new TypeError('letterSpacing must be of type number');
531
534
  }
@@ -539,6 +542,13 @@ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing,
539
542
  return width;
540
543
  };
541
544
 
545
+ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
546
+ if (isMonoSpaceFont) {
547
+ return measureTextWidthFast(text, charWidth);
548
+ }
549
+ return measureTextWidthSlow(text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth);
550
+ };
551
+
542
552
  const normalizeText = (text, normalize, tabSize) => {
543
553
  if (normalize) {
544
554
  return text.replaceAll(Tab, Space$1.repeat(tabSize));
@@ -1833,13 +1843,10 @@ const getVisibleDiagnostics = (editor, diagnostics) => {
1833
1843
  return visibleDiagnostics;
1834
1844
  };
1835
1845
 
1836
- const updateDiagnostics = async uid => {
1846
+ const updateDiagnostics = async newState => {
1837
1847
  try {
1838
1848
  // TODO handle error
1839
1849
  // TODO handle race condition
1840
- const {
1841
- newState
1842
- } = get$6(uid);
1843
1850
 
1844
1851
  // TODO sync textdocument incrementally
1845
1852
  // TODO sync and ask for diagnostics at the same time?
@@ -1847,7 +1854,7 @@ const updateDiagnostics = async uid => {
1847
1854
  const content = getText$1(newState);
1848
1855
  await invoke$2(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
1849
1856
  const diagnostics = await executeDiagnosticProvider(newState);
1850
- const latest = get$6(uid);
1857
+ const latest = get$6(newState.id);
1851
1858
  if (!latest) {
1852
1859
  return;
1853
1860
  }
@@ -1857,8 +1864,8 @@ const updateDiagnostics = async uid => {
1857
1864
  diagnostics,
1858
1865
  decorations
1859
1866
  };
1860
- set$6(uid, latest.oldState, newEditor);
1861
- await invoke$3('Editor.rerender', uid);
1867
+ set$6(newState.id, latest.oldState, newEditor);
1868
+ await invoke$3('Editor.rerender', newState.id);
1862
1869
  } catch (error) {
1863
1870
  // @ts-ignore
1864
1871
  if (error && error.message.includes('No diagnostic provider found')) {
@@ -1993,7 +2000,7 @@ const createEditor = async ({
1993
2000
  set$6(id, emptyEditor, newEditor4);
1994
2001
  await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
1995
2002
  if (diagnosticsEnabled) {
1996
- updateDiagnostics(editor.uid);
2003
+ updateDiagnostics(newEditor4);
1997
2004
  }
1998
2005
  };
1999
2006
 
@@ -9363,7 +9370,7 @@ const editorDiagnosticEffect = {
9363
9370
  },
9364
9371
  // TODO set effects delay / diagnostic delay
9365
9372
  async apply(editor) {
9366
- await updateDiagnostics(editor.id);
9373
+ await updateDiagnostics(editor);
9367
9374
  }
9368
9375
  };
9369
9376
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",