@parhelia/core 0.1.12741 → 0.1.12749

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.
@@ -3718,60 +3718,48 @@ export function EditorShell({ configuration, className, item: loadItemDescriptor
3718
3718
  const match = text.match(guidPattern);
3719
3719
  return match ? match[0] : null;
3720
3720
  };
3721
- const getTextFromElement = (element) => {
3722
- if (!element)
3723
- return null;
3724
- // First, check if there's a text selection - user might have selected the GUID
3721
+ // Resolve the text node + character offset under a click point.
3722
+ // Only the text actually under the cursor is considered, so clicking
3723
+ // text adjacent to a GUID (different text node, or different range
3724
+ // within the same text node) does not trigger navigation.
3725
+ const getCaretAtPoint = (x, y) => {
3726
+ const doc = document;
3727
+ if (typeof doc.caretPositionFromPoint === "function") {
3728
+ const pos = doc.caretPositionFromPoint(x, y);
3729
+ if (pos?.offsetNode) {
3730
+ return { node: pos.offsetNode, offset: pos.offset };
3731
+ }
3732
+ }
3733
+ if (typeof document.caretRangeFromPoint === "function") {
3734
+ const range = document.caretRangeFromPoint(x, y);
3735
+ if (range) {
3736
+ return { node: range.startContainer, offset: range.startOffset };
3737
+ }
3738
+ }
3739
+ return null;
3740
+ };
3741
+ const getGuidFromClickPoint = (event) => {
3742
+ // First, honour an active text selection - the user may have
3743
+ // intentionally highlighted a GUID before ctrl+clicking.
3725
3744
  const selection = window.getSelection();
3726
3745
  if (selection && !selection.isCollapsed) {
3727
- const selectedText = selection.toString();
3728
- const guid = extractGuidFromText(selectedText);
3729
- if (guid)
3730
- return guid;
3731
- }
3732
- // Try to get text content from the element itself
3733
- const textContent = element.textContent?.trim();
3734
- if (textContent) {
3735
- const guid = extractGuidFromText(textContent);
3746
+ const guid = extractGuidFromText(selection.toString());
3736
3747
  if (guid)
3737
3748
  return guid;
3738
3749
  }
3739
- // Check if we clicked on a text node's parent
3740
- if (element.childNodes.length === 1) {
3741
- const firstChild = element.childNodes[0];
3742
- if (firstChild && firstChild.nodeType === Node.TEXT_NODE) {
3743
- const text = firstChild.textContent?.trim();
3744
- if (text) {
3745
- const guid = extractGuidFromText(text);
3746
- if (guid)
3747
- return guid;
3748
- }
3749
- }
3750
- }
3751
- // Walk up the parent tree to find a parent that might contain a GUID
3752
- // This helps with JSON viewers where the GUID is split across elements
3753
- let currentElement = element;
3754
- let depth = 0;
3755
- while (currentElement && depth < 5) {
3756
- const parentText = currentElement.textContent?.trim();
3757
- if (parentText && parentText.length < 200) {
3758
- // Avoid huge text blocks
3759
- const guid = extractGuidFromText(parentText);
3760
- if (guid)
3761
- return guid;
3762
- }
3763
- currentElement = currentElement.parentElement;
3764
- depth++;
3765
- }
3766
- // Try to find GUIDs in nearby text
3767
- const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null);
3768
- let node;
3769
- while ((node = walker.nextNode())) {
3770
- const text = node.textContent?.trim();
3771
- if (text) {
3772
- const guid = extractGuidFromText(text);
3773
- if (guid)
3774
- return guid;
3750
+ const caret = getCaretAtPoint(event.clientX, event.clientY);
3751
+ if (!caret || caret.node.nodeType !== Node.TEXT_NODE)
3752
+ return null;
3753
+ const text = caret.node.textContent ?? "";
3754
+ // Find every GUID match in the clicked text node and require the
3755
+ // click offset to fall inside one of them.
3756
+ const guidPattern = /[\{\(]?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}[\}\)]?/g;
3757
+ let match;
3758
+ while ((match = guidPattern.exec(text)) !== null) {
3759
+ const start = match.index;
3760
+ const end = start + match[0].length;
3761
+ if (caret.offset >= start && caret.offset <= end) {
3762
+ return match[0];
3775
3763
  }
3776
3764
  }
3777
3765
  return null;
@@ -3781,7 +3769,6 @@ export function EditorShell({ configuration, className, item: loadItemDescriptor
3781
3769
  modifierWasPressedOnMouseDown = event.ctrlKey || event.metaKey;
3782
3770
  };
3783
3771
  const handleCtrlClick = async (event) => {
3784
- const target = event.target;
3785
3772
  // Only proceed if Ctrl/Cmd was already pressed when the mouse interaction started.
3786
3773
  // This avoids accidental navigation when users press Ctrl after selecting text to copy.
3787
3774
  if (!modifierWasPressedOnMouseDown)
@@ -3790,7 +3777,7 @@ export function EditorShell({ configuration, className, item: loadItemDescriptor
3790
3777
  if (!event.ctrlKey && !event.metaKey)
3791
3778
  return;
3792
3779
  modifierWasPressedOnMouseDown = false;
3793
- const text = getTextFromElement(target);
3780
+ const text = getGuidFromClickPoint(event);
3794
3781
  if (text && isGuid(text)) {
3795
3782
  event.preventDefault();
3796
3783
  event.stopPropagation();