@lvce-editor/editor-worker 19.80.2 → 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 +51 -1
- package/dist/editorWorkerMain.js +51 -1
- package/package.json +1 -1
package/dist/diff-sdk.js
CHANGED
|
@@ -2481,10 +2481,56 @@ const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, t
|
|
|
2481
2481
|
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
2482
2482
|
};
|
|
2483
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
|
+
|
|
2484
2529
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
2485
2530
|
const getLargeFileVisible = editor => {
|
|
2486
2531
|
const {
|
|
2487
2532
|
deltaX,
|
|
2533
|
+
languageId,
|
|
2488
2534
|
lines,
|
|
2489
2535
|
tabSize,
|
|
2490
2536
|
visibleLineIndices,
|
|
@@ -2497,6 +2543,11 @@ const getLargeFileVisible = editor => {
|
|
|
2497
2543
|
const differences = [];
|
|
2498
2544
|
for (const row of visibleLineIndices) {
|
|
2499
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
|
+
}
|
|
2500
2551
|
let text = '';
|
|
2501
2552
|
if (line.includes('\t')) {
|
|
2502
2553
|
let column = 0;
|
|
@@ -2513,7 +2564,6 @@ const getLargeFileVisible = editor => {
|
|
|
2513
2564
|
text = line.slice(firstColumn, lastColumn);
|
|
2514
2565
|
}
|
|
2515
2566
|
textInfos.push([text, 'Token Text']);
|
|
2516
|
-
differences.push(firstColumn * charWidth - deltaX);
|
|
2517
2567
|
}
|
|
2518
2568
|
return {
|
|
2519
2569
|
differences,
|
package/dist/editorWorkerMain.js
CHANGED
|
@@ -3882,10 +3882,56 @@ const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, t
|
|
|
3882
3882
|
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
3883
3883
|
};
|
|
3884
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
|
+
|
|
3885
3930
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
3886
3931
|
const getLargeFileVisible = editor => {
|
|
3887
3932
|
const {
|
|
3888
3933
|
deltaX,
|
|
3934
|
+
languageId,
|
|
3889
3935
|
lines,
|
|
3890
3936
|
tabSize,
|
|
3891
3937
|
visibleLineIndices,
|
|
@@ -3898,6 +3944,11 @@ const getLargeFileVisible = editor => {
|
|
|
3898
3944
|
const differences = [];
|
|
3899
3945
|
for (const row of visibleLineIndices) {
|
|
3900
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
|
+
}
|
|
3901
3952
|
let text = '';
|
|
3902
3953
|
if (line.includes('\t')) {
|
|
3903
3954
|
let column = 0;
|
|
@@ -3914,7 +3965,6 @@ const getLargeFileVisible = editor => {
|
|
|
3914
3965
|
text = line.slice(firstColumn, lastColumn);
|
|
3915
3966
|
}
|
|
3916
3967
|
textInfos.push([text, 'Token Text']);
|
|
3917
|
-
differences.push(firstColumn * charWidth - deltaX);
|
|
3918
3968
|
}
|
|
3919
3969
|
return {
|
|
3920
3970
|
differences,
|