@lvce-editor/editor-worker 16.1.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.
@@ -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
  };
@@ -5440,6 +5477,10 @@ const setPosition$1 = position => {
5440
5477
  state$3.position = position;
5441
5478
  };
5442
5479
 
5480
+ const openExternal = async url => {
5481
+ await invoke$b('Open.openUrl', url);
5482
+ };
5483
+
5443
5484
  // TODO first change cursor position, then run go to definition
5444
5485
  // cursor should appear at mousedown position immediately
5445
5486
  const handleSingleClickWithAlt = async (editor, position) => {
@@ -5447,12 +5488,21 @@ const handleSingleClickWithAlt = async (editor, position) => {
5447
5488
  columnIndex,
5448
5489
  rowIndex
5449
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
5450
5502
  const newEditor = {
5451
5503
  ...editor,
5452
5504
  selections: new Uint32Array([rowIndex, columnIndex, rowIndex, columnIndex])
5453
5505
  };
5454
- // TODO rectangular selection with alt click,
5455
- // but also go to definition with alt click
5456
5506
  const newEditor2 = await goToDefinition(newEditor);
5457
5507
  return newEditor2;
5458
5508
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "16.1.0",
3
+ "version": "16.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"