In 1.8.0, PDF "Copy link to selection" fails to copy proper links in some cases

Once you’ve done the above, delete everything above this line.

Steps to reproduce

  1. Open a sandbox vault
  2. Import this sample PDF to the vault
  3. Open the PDF and select the last word in the first page (“tincidunt.”)
  4. Right click and select “Copy link to selection”
  5. Paste the copied link to a markdown file, and click it

Did you follow the troubleshooting guide? [Y/N]

Y

Expected result

The exact range of text that we selected in the step 3 should be highlighted.

Actual result

The page number (“1”) is highlighted instead of the last word in the page.

Environment

SYSTEM INFO:
Obsidian version: v1.8.0
Installer version: v1.7.7
Operating system: Darwin Kernel Version 22.6.0: Mon Feb 19 19:43:41 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_ARM64_T8103 22.6.0
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: on
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 0
Plugins enabled: 0

RECOMMENDATIONS:
none


Additional information

Screen recording of the “steps to reproduce”

Screen Recording 2024-12-22 at 3.17.09

In Obsidian v1.7.7,

  • if the text selection contains the period, Obsidian does not show the “Copy link to selection” menu item in the first place.
  • if the text selection does not contain the period, the copied link looks like ...selection=86,9,86,19... and it can highlight the correct range of text.

In Obsidian v1.8.0,

  • if the text selection contains the period, Obsidian still shows the “Copy link to selection” menu item, and the copied link looks like ...selection=87,10,87,20...
  • if the text selection does not contain the period, the copied link looks like ...selection=87,10,87,18...

and it highlights the page number (“1”) in both cases.

thanks

I’m not sure if the team has already figured out the cause of this bug, but I have just now, so I will share it just in case.

As you know, in the PDF viewer, each PDF page (div.page) has a text layer (div.textLayer), and the text layer contains a number of text layer nodes (span.textLayerNode).
Each text layer node has a data attribute called data-idx, which is simply the index of the node within the text layer.

In Obsidian 1.7.7, data-idx starts from 0. However, in 1.8.0, it starts from 1.

As a result, the getTextSelectionRangeStr method of the class of pdfView.viewer.child needs to be modified accordingly.

Hope it helps and this bug will be fixed soon.

Will be fixed 1.8.2

1 Like