@lvce-editor/editor-worker 5.2.0 → 5.3.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.
- package/dist/editorWorkerMain.js +57 -9
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1797,12 +1797,36 @@ const getDiagnosticType = diagnostic => {
|
|
|
1797
1797
|
|
|
1798
1798
|
const getVisibleDiagnostics = (editor, diagnostics) => {
|
|
1799
1799
|
const visibleDiagnostics = [];
|
|
1800
|
+
const {
|
|
1801
|
+
width,
|
|
1802
|
+
rowHeight,
|
|
1803
|
+
minLineY,
|
|
1804
|
+
charWidth,
|
|
1805
|
+
letterSpacing,
|
|
1806
|
+
lines,
|
|
1807
|
+
fontWeight,
|
|
1808
|
+
fontSize,
|
|
1809
|
+
fontFamily,
|
|
1810
|
+
isMonospaceFont,
|
|
1811
|
+
tabSize
|
|
1812
|
+
} = editor;
|
|
1800
1813
|
for (const diagnostic of diagnostics) {
|
|
1814
|
+
const {
|
|
1815
|
+
rowIndex,
|
|
1816
|
+
columnIndex,
|
|
1817
|
+
endColumnIndex
|
|
1818
|
+
} = diagnostic;
|
|
1819
|
+
const columnDelta = endColumnIndex - columnIndex;
|
|
1820
|
+
const diagnosticWidth = columnDelta * charWidth;
|
|
1821
|
+
const endLineDifference = 0;
|
|
1822
|
+
const halfCursorWidth = 0;
|
|
1823
|
+
const x = getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
|
|
1824
|
+
const y = getY(rowIndex, minLineY, rowHeight);
|
|
1801
1825
|
visibleDiagnostics.push({
|
|
1802
|
-
x
|
|
1803
|
-
y
|
|
1804
|
-
width:
|
|
1805
|
-
height:
|
|
1826
|
+
x,
|
|
1827
|
+
y,
|
|
1828
|
+
width: diagnosticWidth,
|
|
1829
|
+
height: rowHeight,
|
|
1806
1830
|
type: getDiagnosticType(diagnostic)
|
|
1807
1831
|
});
|
|
1808
1832
|
}
|
|
@@ -1816,7 +1840,12 @@ const updateDiagnostics = async uid => {
|
|
|
1816
1840
|
const {
|
|
1817
1841
|
newState
|
|
1818
1842
|
} = get$6(uid);
|
|
1819
|
-
|
|
1843
|
+
|
|
1844
|
+
// TODO sync textdocument incrementally
|
|
1845
|
+
// TODO sync and ask for diagnostics at the same time?
|
|
1846
|
+
// TODO throttle diagnostics
|
|
1847
|
+
const content = getText$1(newState);
|
|
1848
|
+
await invoke$2(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
|
|
1820
1849
|
const diagnostics = await executeDiagnosticProvider(newState);
|
|
1821
1850
|
const latest = get$6(uid);
|
|
1822
1851
|
if (!latest) {
|
|
@@ -1831,6 +1860,10 @@ const updateDiagnostics = async uid => {
|
|
|
1831
1860
|
set$6(uid, latest.oldState, newEditor);
|
|
1832
1861
|
await invoke$3('Editor.rerender', uid);
|
|
1833
1862
|
} catch (error) {
|
|
1863
|
+
// @ts-ignore
|
|
1864
|
+
if (error && error.message.includes('No diagnostic provider found')) {
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1834
1867
|
console.error(`Failed to update diagnostics: ${error}`);
|
|
1835
1868
|
}
|
|
1836
1869
|
};
|
|
@@ -8377,9 +8410,6 @@ const loadFont = async (fontName, fontUrl) => {
|
|
|
8377
8410
|
}
|
|
8378
8411
|
};
|
|
8379
8412
|
|
|
8380
|
-
const load = async (fontName, fontUrl) => {
|
|
8381
|
-
return loadFont(fontName, fontUrl);
|
|
8382
|
-
};
|
|
8383
8413
|
const ensure = async (fontName, fontUrl) => {
|
|
8384
8414
|
if (isLoaded(fontName)) {
|
|
8385
8415
|
return;
|
|
@@ -8387,7 +8417,7 @@ const ensure = async (fontName, fontUrl) => {
|
|
|
8387
8417
|
if (hasPending(fontName)) {
|
|
8388
8418
|
return getPending(fontName);
|
|
8389
8419
|
}
|
|
8390
|
-
const promise =
|
|
8420
|
+
const promise = loadFont(fontName, fontUrl);
|
|
8391
8421
|
setPending(fontName, promise);
|
|
8392
8422
|
await promise;
|
|
8393
8423
|
removePending(fontName);
|
|
@@ -9326,6 +9356,17 @@ const renderEditor = async id => {
|
|
|
9326
9356
|
return commands;
|
|
9327
9357
|
};
|
|
9328
9358
|
|
|
9359
|
+
const editorDiagnosticEffect = {
|
|
9360
|
+
isActive(oldEditor, newEditor) {
|
|
9361
|
+
// TODO avoid slow comparison
|
|
9362
|
+
return newEditor.diagnosticsEnabled && JSON.stringify(oldEditor.lines) !== JSON.stringify(newEditor.lines);
|
|
9363
|
+
},
|
|
9364
|
+
// TODO set effects delay / diagnostic delay
|
|
9365
|
+
async apply(editor) {
|
|
9366
|
+
await updateDiagnostics(editor.id);
|
|
9367
|
+
}
|
|
9368
|
+
};
|
|
9369
|
+
|
|
9329
9370
|
const keep = [
|
|
9330
9371
|
// 'ColorPicker.handleSliderPointerDown',
|
|
9331
9372
|
// 'ColorPicker.handleSliderPointerMove',
|
|
@@ -9383,9 +9424,16 @@ const widgetCommands = {
|
|
|
9383
9424
|
|
|
9384
9425
|
// TODO wrap commands globally, not per editor
|
|
9385
9426
|
// TODO only store editor state in editor worker, not in renderer worker also
|
|
9427
|
+
|
|
9428
|
+
const effects = [editorDiagnosticEffect];
|
|
9386
9429
|
const wrapCommand = fn => async (editorUid, ...args) => {
|
|
9387
9430
|
const oldInstance = get$6(editorUid);
|
|
9388
9431
|
const newEditor = await fn(oldInstance.newState, ...args);
|
|
9432
|
+
for (const effect of effects) {
|
|
9433
|
+
if (effect.isActive(oldInstance.newState, newEditor)) {
|
|
9434
|
+
effect.apply(newEditor);
|
|
9435
|
+
}
|
|
9436
|
+
}
|
|
9389
9437
|
set$6(editorUid, oldInstance.newState, newEditor);
|
|
9390
9438
|
// TODO if possible, rendering should be sync
|
|
9391
9439
|
const commands = await renderEditor(editorUid);
|