@lvce-editor/editor-worker 19.72.6 → 19.72.8
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 +49 -47
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -2370,45 +2370,43 @@ const getHorizontalScrollDimensions = ({
|
|
|
2370
2370
|
|
|
2371
2371
|
const defaultThreshold = 500;
|
|
2372
2372
|
const getSegments = line => {
|
|
2373
|
-
if (
|
|
2373
|
+
if (typeof Intl.Segmenter === 'function') {
|
|
2374
2374
|
// @ts-ignore
|
|
2375
|
-
return [...new Intl.Segmenter(undefined, {
|
|
2375
|
+
return [...Array.from(new Intl.Segmenter(undefined, {
|
|
2376
2376
|
granularity: 'grapheme'
|
|
2377
|
-
}).segment(line)
|
|
2377
|
+
}).segment(line), ({
|
|
2378
|
+
index
|
|
2379
|
+
}) => index), line.length];
|
|
2378
2380
|
}
|
|
2379
|
-
const segments = [];
|
|
2381
|
+
const segments = [0];
|
|
2380
2382
|
let index = 0;
|
|
2381
2383
|
for (const segment of line) {
|
|
2382
|
-
segments.push({
|
|
2383
|
-
index,
|
|
2384
|
-
segment
|
|
2385
|
-
});
|
|
2386
2384
|
index += segment.length;
|
|
2385
|
+
segments.push(index);
|
|
2387
2386
|
}
|
|
2388
2387
|
return segments;
|
|
2389
2388
|
};
|
|
2390
|
-
const getCharacterWidth = (
|
|
2391
|
-
if (
|
|
2389
|
+
const getCharacterWidth = (line, start, end, tabSize) => {
|
|
2390
|
+
if (end - start === 1 && line.codePointAt(start) === 9) {
|
|
2392
2391
|
return tabSize;
|
|
2393
2392
|
}
|
|
2394
2393
|
// Grapheme clusters such as combining characters and ZWJ emoji are indivisible.
|
|
2395
2394
|
// Treat each cluster as one display column; the extra cluster below is a safe overscan.
|
|
2396
2395
|
return 1;
|
|
2397
2396
|
};
|
|
2398
|
-
const getHorizontalDisplayColumn = (line, sourceColumn, tabSize) => {
|
|
2397
|
+
const getHorizontalDisplayColumn = (line, sourceColumn, tabSize, segments = getSegments(line)) => {
|
|
2399
2398
|
let displayColumn = 0;
|
|
2400
|
-
for (
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
if (index + segment.length > sourceColumn) {
|
|
2399
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
2400
|
+
const start = segments[i];
|
|
2401
|
+
const end = segments[i + 1];
|
|
2402
|
+
if (end > sourceColumn) {
|
|
2405
2403
|
break;
|
|
2406
2404
|
}
|
|
2407
|
-
displayColumn +=
|
|
2405
|
+
displayColumn += end - start === 1 && line.codePointAt(start) === 9 ? tabSize : end - start;
|
|
2408
2406
|
}
|
|
2409
2407
|
return displayColumn;
|
|
2410
2408
|
};
|
|
2411
|
-
const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSize, threshold = defaultThreshold) => {
|
|
2409
|
+
const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSize, threshold = defaultThreshold, segments = getSegments(line)) => {
|
|
2412
2410
|
if (line.length <= threshold) {
|
|
2413
2411
|
return {
|
|
2414
2412
|
end: line.length,
|
|
@@ -2424,15 +2422,13 @@ const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSiz
|
|
|
2424
2422
|
let index = 0;
|
|
2425
2423
|
let start = 0;
|
|
2426
2424
|
let started = false;
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
} of segments) {
|
|
2432
|
-
const nextColumn = column + getCharacterWidth(segment, tabSize);
|
|
2425
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
2426
|
+
const segmentIndex = segments[i];
|
|
2427
|
+
const segmentEnd = segments[i + 1];
|
|
2428
|
+
const nextColumn = column + getCharacterWidth(line, segmentIndex, segmentEnd, tabSize);
|
|
2433
2429
|
if (!started && nextColumn <= targetStart) {
|
|
2434
2430
|
column = nextColumn;
|
|
2435
|
-
index =
|
|
2431
|
+
index = segmentEnd;
|
|
2436
2432
|
start = index;
|
|
2437
2433
|
continue;
|
|
2438
2434
|
}
|
|
@@ -2440,7 +2436,7 @@ const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSiz
|
|
|
2440
2436
|
start = segmentIndex;
|
|
2441
2437
|
started = true;
|
|
2442
2438
|
}
|
|
2443
|
-
index =
|
|
2439
|
+
index = segmentEnd;
|
|
2444
2440
|
column = nextColumn;
|
|
2445
2441
|
if (column >= targetEnd) {
|
|
2446
2442
|
break;
|
|
@@ -2451,11 +2447,9 @@ const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSiz
|
|
|
2451
2447
|
}
|
|
2452
2448
|
// Keep one extra complete grapheme to cover fractional offsets and avoid a blank edge.
|
|
2453
2449
|
if (index < line.length) {
|
|
2454
|
-
const
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
if (nextSegment) {
|
|
2458
|
-
index = nextSegment.index + nextSegment.segment.length;
|
|
2450
|
+
const nextSegmentIndex = segments.findIndex(segmentIndex => segmentIndex >= index);
|
|
2451
|
+
if (nextSegmentIndex !== -1 && nextSegmentIndex < segments.length - 1) {
|
|
2452
|
+
index = segments[nextSegmentIndex + 1];
|
|
2459
2453
|
}
|
|
2460
2454
|
}
|
|
2461
2455
|
return {
|
|
@@ -2465,10 +2459,11 @@ const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSiz
|
|
|
2465
2459
|
};
|
|
2466
2460
|
const getHorizontalVisibleRangesMeasured = async (requests, measureWidths) => {
|
|
2467
2461
|
const fallback = request => {
|
|
2468
|
-
const
|
|
2462
|
+
const segments = request.segments || getSegments(request.line);
|
|
2463
|
+
const range = getHorizontalVisibleRange(request.line, request.deltaX, request.width, request.averageCharWidth, request.tabSize, request.threshold, segments);
|
|
2469
2464
|
return {
|
|
2470
2465
|
...range,
|
|
2471
|
-
difference: getHorizontalVisibleDifference(request.line, range.start, request.deltaX, request.averageCharWidth, request.tabSize)
|
|
2466
|
+
difference: getHorizontalVisibleDifference(request.line, range.start, request.deltaX, request.averageCharWidth, request.tabSize, segments)
|
|
2472
2467
|
};
|
|
2473
2468
|
};
|
|
2474
2469
|
const results = requests.map(request => fallback(request));
|
|
@@ -2480,11 +2475,7 @@ const getHorizontalVisibleRangesMeasured = async (requests, measureWidths) => {
|
|
|
2480
2475
|
if (request.line.length <= request.threshold) {
|
|
2481
2476
|
continue;
|
|
2482
2477
|
}
|
|
2483
|
-
const
|
|
2484
|
-
const boundaries = [0, ...segments.map(({
|
|
2485
|
-
index,
|
|
2486
|
-
segment
|
|
2487
|
-
}) => index + segment.length)];
|
|
2478
|
+
const boundaries = request.segments || getSegments(request.line);
|
|
2488
2479
|
boundariesByLine[lineIndex] = boundaries;
|
|
2489
2480
|
measurementsByLine[lineIndex] = new Map([[0, 0]]);
|
|
2490
2481
|
const scrollOffset = Math.max(0, Number.isFinite(request.deltaX) ? request.deltaX : 0);
|
|
@@ -2590,10 +2581,10 @@ const getHorizontalVisibleRangesMeasured = async (requests, measureWidths) => {
|
|
|
2590
2581
|
}
|
|
2591
2582
|
return results;
|
|
2592
2583
|
};
|
|
2593
|
-
const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, tabSize) => {
|
|
2584
|
+
const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, tabSize, segments) => {
|
|
2594
2585
|
const charWidth = averageCharWidth > 0 ? averageCharWidth : 1;
|
|
2595
2586
|
const scrollOffset = Number.isFinite(deltaX) ? deltaX : 0;
|
|
2596
|
-
return getHorizontalDisplayColumn(line, start, tabSize) * charWidth - scrollOffset;
|
|
2587
|
+
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
2597
2588
|
};
|
|
2598
2589
|
|
|
2599
2590
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
@@ -3244,6 +3235,13 @@ const positionAt = (textDocument, offset) => {
|
|
|
3244
3235
|
};
|
|
3245
3236
|
|
|
3246
3237
|
const maxTokenizerLoadPasses$1 = 10;
|
|
3238
|
+
const getGraphemeSegments = async lines => {
|
|
3239
|
+
try {
|
|
3240
|
+
return await invoke$e('TextMeasurement.getGraphemeSegments', lines);
|
|
3241
|
+
} catch {
|
|
3242
|
+
return undefined;
|
|
3243
|
+
}
|
|
3244
|
+
};
|
|
3247
3245
|
|
|
3248
3246
|
// const getTokensIncremental = (editor, min, max) => {
|
|
3249
3247
|
// const currentLength = editor.lineStateCache.length
|
|
@@ -3569,10 +3567,13 @@ const getLineInfosViewport = async (editor, tokens, embeddedResults, minLineY, m
|
|
|
3569
3567
|
const tokenMap = get$5(languageId);
|
|
3570
3568
|
let offset = minLineOffset;
|
|
3571
3569
|
const tabSize = editor.tabSize ?? 2;
|
|
3572
|
-
const
|
|
3570
|
+
const visibleLines = lines.slice(minLineY, maxLineY);
|
|
3571
|
+
const graphemeSegments = await getGraphemeSegments(visibleLines);
|
|
3572
|
+
const measuredRanges = await getHorizontalVisibleRangesMeasured(visibleLines.map((line, index) => ({
|
|
3573
3573
|
averageCharWidth,
|
|
3574
3574
|
deltaX,
|
|
3575
3575
|
line,
|
|
3576
|
+
segments: graphemeSegments?.[index],
|
|
3576
3577
|
tabSize,
|
|
3577
3578
|
threshold: horizontalVirtualizationThreshold,
|
|
3578
3579
|
width
|
|
@@ -3604,6 +3605,7 @@ const getLineInfosViewport = async (editor, tokens, embeddedResults, minLineY, m
|
|
|
3604
3605
|
horizontalVisibleRanges.push({
|
|
3605
3606
|
end: measuredRange.end,
|
|
3606
3607
|
rowIndex: i,
|
|
3608
|
+
segments: graphemeSegments?.[i - minLineY],
|
|
3607
3609
|
start: measuredRange.start
|
|
3608
3610
|
});
|
|
3609
3611
|
offset += line.length + 1;
|
|
@@ -17706,16 +17708,16 @@ const mergeConflictActions = [{
|
|
|
17706
17708
|
action: 'both',
|
|
17707
17709
|
label: 'Accept Both Changes'
|
|
17708
17710
|
}];
|
|
17709
|
-
const getUnnecessaryRanges = (diagnostics, rowIndex, textLength, visibleStartColumn, line, hasLine, tabSize) => {
|
|
17710
|
-
const visibleStart = hasLine ? getHorizontalDisplayColumn(line, visibleStartColumn, tabSize) : visibleStartColumn;
|
|
17711
|
+
const getUnnecessaryRanges = (diagnostics, rowIndex, textLength, visibleStartColumn, line, hasLine, tabSize, segments) => {
|
|
17712
|
+
const visibleStart = hasLine ? getHorizontalDisplayColumn(line, visibleStartColumn, tabSize, segments) : visibleStartColumn;
|
|
17711
17713
|
return diagnostics.filter(diagnostic => diagnostic.tags?.includes(DiagnosticTag.Unnecessary)).flatMap(diagnostic => {
|
|
17712
17714
|
if (rowIndex < diagnostic.rowIndex || rowIndex > diagnostic.endRowIndex) {
|
|
17713
17715
|
return [];
|
|
17714
17716
|
}
|
|
17715
17717
|
const diagnosticStart = rowIndex === diagnostic.rowIndex ? diagnostic.columnIndex : 0;
|
|
17716
17718
|
const diagnosticEnd = rowIndex === diagnostic.endRowIndex ? diagnostic.endColumnIndex : line.length;
|
|
17717
|
-
const startColumn = hasLine ? getHorizontalDisplayColumn(line, diagnosticStart, tabSize) : diagnosticStart;
|
|
17718
|
-
const endColumn = hasLine ? getHorizontalDisplayColumn(line, diagnosticEnd, tabSize) : diagnosticEnd;
|
|
17719
|
+
const startColumn = hasLine ? getHorizontalDisplayColumn(line, diagnosticStart, tabSize, segments) : diagnosticStart;
|
|
17720
|
+
const endColumn = hasLine ? getHorizontalDisplayColumn(line, diagnosticEnd, tabSize, segments) : diagnosticEnd;
|
|
17719
17721
|
const start = Math.max(0, startColumn - visibleStart);
|
|
17720
17722
|
const end = Math.min(textLength, endColumn - visibleStart);
|
|
17721
17723
|
return start < end ? [{
|
|
@@ -17799,7 +17801,7 @@ const getEditorRowsVirtualDom$1 = (textInfos, differences, lineNumbers = true, h
|
|
|
17799
17801
|
for (let index = 0; index < textInfo.length; index += 2) {
|
|
17800
17802
|
rowTextLength += textInfo[index].length;
|
|
17801
17803
|
}
|
|
17802
|
-
const tokenParts = getTokenParts(textInfo, getUnnecessaryRanges(diagnostics, rowIndex, rowTextLength, visibleRange.start, line, lines[rowIndex] !== undefined, tabSize));
|
|
17804
|
+
const tokenParts = getTokenParts(textInfo, getUnnecessaryRanges(diagnostics, rowIndex, rowTextLength, visibleRange.start, line, lines[rowIndex] !== undefined, tabSize, visibleRange.segments));
|
|
17803
17805
|
let className = EditorRow;
|
|
17804
17806
|
if (rowIndex === highlightedLine) {
|
|
17805
17807
|
className = mergeClassNames(className, EditorRowHighlighted);
|
|
@@ -18768,7 +18770,7 @@ const renderEventListeners = () => {
|
|
|
18768
18770
|
preventDefault: true
|
|
18769
18771
|
}, {
|
|
18770
18772
|
name: HandlePaste,
|
|
18771
|
-
params: ['paste', 'event.clipboardData
|
|
18773
|
+
params: ['paste', 'event.clipboardData.text'],
|
|
18772
18774
|
preventDefault: true
|
|
18773
18775
|
}, {
|
|
18774
18776
|
name: HandleMouseDown,
|