@lvce-editor/editor-worker 19.80.1 → 19.80.3
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/diff-sdk.js +72 -4
- package/dist/editorWorkerMain.js +72 -4
- package/package.json +1 -1
package/dist/diff-sdk.js
CHANGED
|
@@ -417,7 +417,8 @@ const activateByEvent = async (event, assetDir, platform) => {
|
|
|
417
417
|
await ExtensionManagementWorker.invoke('Extensions.activateByEvent', event);
|
|
418
418
|
};
|
|
419
419
|
|
|
420
|
-
|
|
420
|
+
// Older entries may have been measured before the bundled font was loaded.
|
|
421
|
+
const cacheName$1 = 'lvce-editor-character-widths-v2';
|
|
421
422
|
const character = 'a';
|
|
422
423
|
const getKey$2 = (fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
423
424
|
return `https://cache.invalid/character-width/${encodeURIComponent(JSON.stringify([character, fontWeight, fontSize, fontFamily, letterSpacing]))}`;
|
|
@@ -2480,10 +2481,56 @@ const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, t
|
|
|
2480
2481
|
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
2481
2482
|
};
|
|
2482
2483
|
|
|
2484
|
+
// Valid JSON strings cannot cross line breaks. Classify each short visible line
|
|
2485
|
+
// independently so jumping to the end of a large file needs no tokenizer state.
|
|
2486
|
+
const maxJsonLineLength = 4096;
|
|
2487
|
+
const jsonTokens = /(?<property>"(?:[^"\\]|\\.)*"(?= *:))|(?<string>"(?:[^"\\]|\\.)*(?<closingQuote>"|$))|(?<number>-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)|(?<constant>true|false|null)|(?<punctuation>[{}\[\],:])| +|./gsu;
|
|
2488
|
+
const jsonTokenClasses = {
|
|
2489
|
+
constant: 'Token LanguageConstant',
|
|
2490
|
+
number: 'Token Numeric',
|
|
2491
|
+
property: 'Token JsonPropertyName',
|
|
2492
|
+
punctuation: 'Token Punctuation',
|
|
2493
|
+
string: 'Token JsonPropertyValueString'
|
|
2494
|
+
};
|
|
2495
|
+
const jsonTokenKinds = Object.keys(jsonTokenClasses);
|
|
2496
|
+
const getVisibleJson = (line, tabSize, firstColumn, lastColumn) => {
|
|
2497
|
+
const tab = ' '.repeat(Math.max(1, tabSize));
|
|
2498
|
+
const text = line.replaceAll('\t', () => tab);
|
|
2499
|
+
const result = [];
|
|
2500
|
+
const append = (start, end, tokenClass) => {
|
|
2501
|
+
const visibleStart = Math.max(start, firstColumn);
|
|
2502
|
+
const visibleEnd = Math.min(end, lastColumn);
|
|
2503
|
+
if (visibleStart < visibleEnd) {
|
|
2504
|
+
result.push(text.slice(visibleStart, visibleEnd), tokenClass);
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
for (const match of text.matchAll(jsonTokens)) {
|
|
2508
|
+
const start = match.index;
|
|
2509
|
+
if (start >= lastColumn) {
|
|
2510
|
+
break;
|
|
2511
|
+
}
|
|
2512
|
+
const end = start + match[0].length;
|
|
2513
|
+
if (end <= firstColumn) {
|
|
2514
|
+
continue;
|
|
2515
|
+
}
|
|
2516
|
+
const kind = jsonTokenKinds.find(key => match.groups?.[key] !== undefined);
|
|
2517
|
+
if (kind === 'property' || kind === 'string') {
|
|
2518
|
+
const contentEnd = kind === 'property' || match.groups?.closingQuote ? end - 1 : end;
|
|
2519
|
+
append(start, start + 1, jsonTokenClasses.punctuation);
|
|
2520
|
+
append(start + 1, contentEnd, jsonTokenClasses[kind]);
|
|
2521
|
+
append(contentEnd, end, jsonTokenClasses.punctuation);
|
|
2522
|
+
} else {
|
|
2523
|
+
append(start, end, kind ? jsonTokenClasses[kind] : 'Token Text');
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
return result;
|
|
2527
|
+
};
|
|
2528
|
+
|
|
2483
2529
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
2484
2530
|
const getLargeFileVisible = editor => {
|
|
2485
2531
|
const {
|
|
2486
2532
|
deltaX,
|
|
2533
|
+
languageId,
|
|
2487
2534
|
lines,
|
|
2488
2535
|
tabSize,
|
|
2489
2536
|
visibleLineIndices,
|
|
@@ -2496,6 +2543,11 @@ const getLargeFileVisible = editor => {
|
|
|
2496
2543
|
const differences = [];
|
|
2497
2544
|
for (const row of visibleLineIndices) {
|
|
2498
2545
|
const line = lines[row];
|
|
2546
|
+
differences.push(firstColumn * charWidth - deltaX);
|
|
2547
|
+
if (languageId === 'json' && line.length <= maxJsonLineLength) {
|
|
2548
|
+
textInfos.push(getVisibleJson(line, tabSize, firstColumn, lastColumn));
|
|
2549
|
+
continue;
|
|
2550
|
+
}
|
|
2499
2551
|
let text = '';
|
|
2500
2552
|
if (line.includes('\t')) {
|
|
2501
2553
|
let column = 0;
|
|
@@ -2512,7 +2564,6 @@ const getLargeFileVisible = editor => {
|
|
|
2512
2564
|
text = line.slice(firstColumn, lastColumn);
|
|
2513
2565
|
}
|
|
2514
2566
|
textInfos.push([text, 'Token Text']);
|
|
2515
|
-
differences.push(firstColumn * charWidth - deltaX);
|
|
2516
2567
|
}
|
|
2517
2568
|
return {
|
|
2518
2569
|
differences,
|
|
@@ -16353,7 +16404,19 @@ const getLanguages = async (platform, assetDir, applicationId) => {
|
|
|
16353
16404
|
return invoke$9(applicationId, 'Extensions.getLanguages', platform, assetDir);
|
|
16354
16405
|
};
|
|
16355
16406
|
|
|
16407
|
+
const loaded = Object.create(null);
|
|
16408
|
+
const setLoaded = id => {
|
|
16409
|
+
loaded[id] = true;
|
|
16410
|
+
};
|
|
16411
|
+
const isLoaded = id => {
|
|
16412
|
+
return loaded[id];
|
|
16413
|
+
};
|
|
16414
|
+
|
|
16356
16415
|
const measureCharacterWidth = async (fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
16416
|
+
const isFiraCode = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
|
|
16417
|
+
if (isFiraCode && !isLoaded('Fira Code')) {
|
|
16418
|
+
return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
|
|
16419
|
+
}
|
|
16357
16420
|
try {
|
|
16358
16421
|
const cachedWidth = await get$b(fontWeight, fontSize, fontFamily, letterSpacing);
|
|
16359
16422
|
if (cachedWidth !== undefined) {
|
|
@@ -26515,6 +26578,7 @@ const getDiagnostics = async editorUid => {
|
|
|
26515
26578
|
|
|
26516
26579
|
const ensure = async (fontName, fontUrl) => {
|
|
26517
26580
|
await TextMeasurementWorker.invoke('TextMeasurement.ensureFont', fontName, fontUrl);
|
|
26581
|
+
setLoaded(fontName);
|
|
26518
26582
|
};
|
|
26519
26583
|
|
|
26520
26584
|
const getComponentState = uid => {
|
|
@@ -27448,7 +27512,7 @@ const updateFindWidget = async state => {
|
|
|
27448
27512
|
commands
|
|
27449
27513
|
});
|
|
27450
27514
|
};
|
|
27451
|
-
const handleSettingsChanged = async state => {
|
|
27515
|
+
const handleSettingsChanged = async (state, firaCodeFontUrl) => {
|
|
27452
27516
|
const editorPreferences = {
|
|
27453
27517
|
...(await getEditorPreferences(state.applicationId)),
|
|
27454
27518
|
...(state.largeFile && getLargeFilePreferences())
|
|
@@ -27463,8 +27527,12 @@ const handleSettingsChanged = async state => {
|
|
|
27463
27527
|
minimapEnabled,
|
|
27464
27528
|
rowHeight
|
|
27465
27529
|
} = editorPreferences;
|
|
27530
|
+
const isFiraCode = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
|
|
27531
|
+
if (isFiraCode && firaCodeFontUrl) {
|
|
27532
|
+
await ensure('Fira Code', firaCodeFontUrl);
|
|
27533
|
+
}
|
|
27466
27534
|
const [charWidth, completionsOnTypeRaw] = await Promise.all([measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing), state.applicationId === undefined ? get$2('editor.completionsOnType') : get$2('editor.completionsOnType', state.applicationId)]);
|
|
27467
|
-
const isMonospaceFont = !editorPreferences.disableMonospaceOptimizations &&
|
|
27535
|
+
const isMonospaceFont = !editorPreferences.disableMonospaceOptimizations && isFiraCode;
|
|
27468
27536
|
const editorWithUpdatedSettings = {
|
|
27469
27537
|
...state,
|
|
27470
27538
|
...editorPreferences,
|
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1817,7 +1817,8 @@ const activateByEvent = async (event, assetDir, platform) => {
|
|
|
1817
1817
|
await invoke$h('Extensions.activateByEvent', event);
|
|
1818
1818
|
};
|
|
1819
1819
|
|
|
1820
|
-
|
|
1820
|
+
// Older entries may have been measured before the bundled font was loaded.
|
|
1821
|
+
const cacheName$1 = 'lvce-editor-character-widths-v2';
|
|
1821
1822
|
const character = 'a';
|
|
1822
1823
|
const getKey$2 = (fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
1823
1824
|
return `https://cache.invalid/character-width/${encodeURIComponent(JSON.stringify([character, fontWeight, fontSize, fontFamily, letterSpacing]))}`;
|
|
@@ -3881,10 +3882,56 @@ const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, t
|
|
|
3881
3882
|
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
3882
3883
|
};
|
|
3883
3884
|
|
|
3885
|
+
// Valid JSON strings cannot cross line breaks. Classify each short visible line
|
|
3886
|
+
// independently so jumping to the end of a large file needs no tokenizer state.
|
|
3887
|
+
const maxJsonLineLength = 4096;
|
|
3888
|
+
const jsonTokens = /(?<property>"(?:[^"\\]|\\.)*"(?= *:))|(?<string>"(?:[^"\\]|\\.)*(?<closingQuote>"|$))|(?<number>-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)|(?<constant>true|false|null)|(?<punctuation>[{}\[\],:])| +|./gsu;
|
|
3889
|
+
const jsonTokenClasses = {
|
|
3890
|
+
constant: 'Token LanguageConstant',
|
|
3891
|
+
number: 'Token Numeric',
|
|
3892
|
+
property: 'Token JsonPropertyName',
|
|
3893
|
+
punctuation: 'Token Punctuation',
|
|
3894
|
+
string: 'Token JsonPropertyValueString'
|
|
3895
|
+
};
|
|
3896
|
+
const jsonTokenKinds = Object.keys(jsonTokenClasses);
|
|
3897
|
+
const getVisibleJson = (line, tabSize, firstColumn, lastColumn) => {
|
|
3898
|
+
const tab = ' '.repeat(Math.max(1, tabSize));
|
|
3899
|
+
const text = line.replaceAll('\t', () => tab);
|
|
3900
|
+
const result = [];
|
|
3901
|
+
const append = (start, end, tokenClass) => {
|
|
3902
|
+
const visibleStart = Math.max(start, firstColumn);
|
|
3903
|
+
const visibleEnd = Math.min(end, lastColumn);
|
|
3904
|
+
if (visibleStart < visibleEnd) {
|
|
3905
|
+
result.push(text.slice(visibleStart, visibleEnd), tokenClass);
|
|
3906
|
+
}
|
|
3907
|
+
};
|
|
3908
|
+
for (const match of text.matchAll(jsonTokens)) {
|
|
3909
|
+
const start = match.index;
|
|
3910
|
+
if (start >= lastColumn) {
|
|
3911
|
+
break;
|
|
3912
|
+
}
|
|
3913
|
+
const end = start + match[0].length;
|
|
3914
|
+
if (end <= firstColumn) {
|
|
3915
|
+
continue;
|
|
3916
|
+
}
|
|
3917
|
+
const kind = jsonTokenKinds.find(key => match.groups?.[key] !== undefined);
|
|
3918
|
+
if (kind === 'property' || kind === 'string') {
|
|
3919
|
+
const contentEnd = kind === 'property' || match.groups?.closingQuote ? end - 1 : end;
|
|
3920
|
+
append(start, start + 1, jsonTokenClasses.punctuation);
|
|
3921
|
+
append(start + 1, contentEnd, jsonTokenClasses[kind]);
|
|
3922
|
+
append(contentEnd, end, jsonTokenClasses.punctuation);
|
|
3923
|
+
} else {
|
|
3924
|
+
append(start, end, kind ? jsonTokenClasses[kind] : 'Token Text');
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
return result;
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3884
3930
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
3885
3931
|
const getLargeFileVisible = editor => {
|
|
3886
3932
|
const {
|
|
3887
3933
|
deltaX,
|
|
3934
|
+
languageId,
|
|
3888
3935
|
lines,
|
|
3889
3936
|
tabSize,
|
|
3890
3937
|
visibleLineIndices,
|
|
@@ -3897,6 +3944,11 @@ const getLargeFileVisible = editor => {
|
|
|
3897
3944
|
const differences = [];
|
|
3898
3945
|
for (const row of visibleLineIndices) {
|
|
3899
3946
|
const line = lines[row];
|
|
3947
|
+
differences.push(firstColumn * charWidth - deltaX);
|
|
3948
|
+
if (languageId === 'json' && line.length <= maxJsonLineLength) {
|
|
3949
|
+
textInfos.push(getVisibleJson(line, tabSize, firstColumn, lastColumn));
|
|
3950
|
+
continue;
|
|
3951
|
+
}
|
|
3900
3952
|
let text = '';
|
|
3901
3953
|
if (line.includes('\t')) {
|
|
3902
3954
|
let column = 0;
|
|
@@ -3913,7 +3965,6 @@ const getLargeFileVisible = editor => {
|
|
|
3913
3965
|
text = line.slice(firstColumn, lastColumn);
|
|
3914
3966
|
}
|
|
3915
3967
|
textInfos.push([text, 'Token Text']);
|
|
3916
|
-
differences.push(firstColumn * charWidth - deltaX);
|
|
3917
3968
|
}
|
|
3918
3969
|
return {
|
|
3919
3970
|
differences,
|
|
@@ -16804,7 +16855,19 @@ const getLanguages = async (platform, assetDir, applicationId) => {
|
|
|
16804
16855
|
return invoke$9(applicationId, 'Extensions.getLanguages', platform, assetDir);
|
|
16805
16856
|
};
|
|
16806
16857
|
|
|
16858
|
+
const loaded = Object.create(null);
|
|
16859
|
+
const setLoaded = id => {
|
|
16860
|
+
loaded[id] = true;
|
|
16861
|
+
};
|
|
16862
|
+
const isLoaded = id => {
|
|
16863
|
+
return loaded[id];
|
|
16864
|
+
};
|
|
16865
|
+
|
|
16807
16866
|
const measureCharacterWidth = async (fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
16867
|
+
const isFiraCode = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
|
|
16868
|
+
if (isFiraCode && !isLoaded('Fira Code')) {
|
|
16869
|
+
return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
|
|
16870
|
+
}
|
|
16808
16871
|
try {
|
|
16809
16872
|
const cachedWidth = await get$a(fontWeight, fontSize, fontFamily, letterSpacing);
|
|
16810
16873
|
if (cachedWidth !== undefined) {
|
|
@@ -26966,6 +27029,7 @@ const getDiagnostics = async editorUid => {
|
|
|
26966
27029
|
|
|
26967
27030
|
const ensure = async (fontName, fontUrl) => {
|
|
26968
27031
|
await invoke$f('TextMeasurement.ensureFont', fontName, fontUrl);
|
|
27032
|
+
setLoaded(fontName);
|
|
26969
27033
|
};
|
|
26970
27034
|
|
|
26971
27035
|
const getComponentState = uid => {
|
|
@@ -27899,7 +27963,7 @@ const updateFindWidget = async state => {
|
|
|
27899
27963
|
commands
|
|
27900
27964
|
});
|
|
27901
27965
|
};
|
|
27902
|
-
const handleSettingsChanged = async state => {
|
|
27966
|
+
const handleSettingsChanged = async (state, firaCodeFontUrl) => {
|
|
27903
27967
|
const editorPreferences = {
|
|
27904
27968
|
...(await getEditorPreferences(state.applicationId)),
|
|
27905
27969
|
...(state.largeFile && getLargeFilePreferences())
|
|
@@ -27914,8 +27978,12 @@ const handleSettingsChanged = async state => {
|
|
|
27914
27978
|
minimapEnabled,
|
|
27915
27979
|
rowHeight
|
|
27916
27980
|
} = editorPreferences;
|
|
27981
|
+
const isFiraCode = fontFamily === 'Fira Code' || fontFamily === "'Fira Code'";
|
|
27982
|
+
if (isFiraCode && firaCodeFontUrl) {
|
|
27983
|
+
await ensure('Fira Code', firaCodeFontUrl);
|
|
27984
|
+
}
|
|
27917
27985
|
const [charWidth, completionsOnTypeRaw] = await Promise.all([measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing), state.applicationId === undefined ? get$2('editor.completionsOnType') : get$2('editor.completionsOnType', state.applicationId)]);
|
|
27918
|
-
const isMonospaceFont = !editorPreferences.disableMonospaceOptimizations &&
|
|
27986
|
+
const isMonospaceFont = !editorPreferences.disableMonospaceOptimizations && isFiraCode;
|
|
27919
27987
|
const editorWithUpdatedSettings = {
|
|
27920
27988
|
...state,
|
|
27921
27989
|
...editorPreferences,
|