@lvce-editor/editor-worker 16.0.0 → 16.2.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 +52 -8
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -3373,6 +3373,43 @@ const detectAllLinksAsDecorations = editor => {
|
|
|
3373
3373
|
return decorations;
|
|
3374
3374
|
};
|
|
3375
3375
|
|
|
3376
|
+
/**
|
|
3377
|
+
* Gets the URL text at a given offset in the editor if it's a link
|
|
3378
|
+
* @param editor The editor
|
|
3379
|
+
* @param offset The offset in the document
|
|
3380
|
+
* @returns The URL string if the offset is on a link, or undefined
|
|
3381
|
+
*/
|
|
3382
|
+
const getUrlAtOffset = (editor, offset) => {
|
|
3383
|
+
const {
|
|
3384
|
+
decorations,
|
|
3385
|
+
lines
|
|
3386
|
+
} = editor;
|
|
3387
|
+
|
|
3388
|
+
// Iterate through decorations in groups of 4 (offset, length, type, modifiers)
|
|
3389
|
+
for (let i = 0; i < decorations.length; i += 4) {
|
|
3390
|
+
const decorationOffset = decorations[i];
|
|
3391
|
+
const decorationLength = decorations[i + 1];
|
|
3392
|
+
const decorationType = decorations[i + 2];
|
|
3393
|
+
|
|
3394
|
+
// Check if this decoration is a link and if the offset falls within it
|
|
3395
|
+
if (decorationType === Link && offset >= decorationOffset && offset < decorationOffset + decorationLength) {
|
|
3396
|
+
// Extract the URL text from the editor content
|
|
3397
|
+
let currentOffset = 0;
|
|
3398
|
+
for (const line of lines) {
|
|
3399
|
+
const lineLength = line.length + 1; // +1 for newline
|
|
3400
|
+
if (currentOffset + lineLength > decorationOffset) {
|
|
3401
|
+
// The link starts in this line
|
|
3402
|
+
const linkStartInLine = decorationOffset - currentOffset;
|
|
3403
|
+
const url = line.slice(linkStartInLine, linkStartInLine + decorationLength);
|
|
3404
|
+
return url;
|
|
3405
|
+
}
|
|
3406
|
+
currentOffset += lineLength;
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
return undefined;
|
|
3411
|
+
};
|
|
3412
|
+
|
|
3376
3413
|
const measureCharacterWidth = async (fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3377
3414
|
return await measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
|
|
3378
3415
|
};
|
|
@@ -3635,9 +3672,6 @@ const createEditor = async ({
|
|
|
3635
3672
|
focused: true,
|
|
3636
3673
|
textInfos
|
|
3637
3674
|
};
|
|
3638
|
-
console.error({
|
|
3639
|
-
newEditor4
|
|
3640
|
-
});
|
|
3641
3675
|
set$6(id, emptyEditor, newEditor4);
|
|
3642
3676
|
|
|
3643
3677
|
// TODO only sync when needed
|
|
@@ -5443,6 +5477,10 @@ const setPosition$1 = position => {
|
|
|
5443
5477
|
state$3.position = position;
|
|
5444
5478
|
};
|
|
5445
5479
|
|
|
5480
|
+
const openExternal = async url => {
|
|
5481
|
+
await invoke$b('Open.openUrl', url);
|
|
5482
|
+
};
|
|
5483
|
+
|
|
5446
5484
|
// TODO first change cursor position, then run go to definition
|
|
5447
5485
|
// cursor should appear at mousedown position immediately
|
|
5448
5486
|
const handleSingleClickWithAlt = async (editor, position) => {
|
|
@@ -5450,12 +5488,21 @@ const handleSingleClickWithAlt = async (editor, position) => {
|
|
|
5450
5488
|
columnIndex,
|
|
5451
5489
|
rowIndex
|
|
5452
5490
|
} = position;
|
|
5491
|
+
|
|
5492
|
+
// Check if the click is on a link
|
|
5493
|
+
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
5494
|
+
const url = getUrlAtOffset(editor, offset);
|
|
5495
|
+
if (url) {
|
|
5496
|
+
// Open the link
|
|
5497
|
+
await openExternal(url);
|
|
5498
|
+
return editor;
|
|
5499
|
+
}
|
|
5500
|
+
|
|
5501
|
+
// Otherwise, perform the default go to definition
|
|
5453
5502
|
const newEditor = {
|
|
5454
5503
|
...editor,
|
|
5455
5504
|
selections: new Uint32Array([rowIndex, columnIndex, rowIndex, columnIndex])
|
|
5456
5505
|
};
|
|
5457
|
-
// TODO rectangular selection with alt click,
|
|
5458
|
-
// but also go to definition with alt click
|
|
5459
5506
|
const newEditor2 = await goToDefinition(newEditor);
|
|
5460
5507
|
return newEditor2;
|
|
5461
5508
|
};
|
|
@@ -10479,9 +10526,6 @@ const renderLines = {
|
|
|
10479
10526
|
} = newState;
|
|
10480
10527
|
const relativeLine = highlightedLine - minLineY;
|
|
10481
10528
|
const dom = getEditorRowsVirtualDom(textInfos, differences, true, relativeLine);
|
|
10482
|
-
console.error({
|
|
10483
|
-
dom
|
|
10484
|
-
});
|
|
10485
10529
|
return [/* method */'setText', dom];
|
|
10486
10530
|
},
|
|
10487
10531
|
isEqual(oldState, newState) {
|