RyotaUshio / obsidian-pdf-plus

PDF++: The most Obsidian-native PDF annotation, viewing & editing tool ever. Comes with optional Vim keybindings.
https://ryotaushio.github.io/obsidian-pdf-plus/
MIT License
823 stars 15 forks source link

[FR] Use `search` in link instead of bounding box and `selection` #92

Open mdbraber opened 8 months ago

mdbraber commented 8 months ago

Describe your request

Thanks for writing PDF++ - I had never imagined this level of integration would be possible in Obsidian. I'm wondering if it would be possible to create links which link through the selected text instead of the selection offsets. As I can see now selection is already just referencing the text layer: https://github.com/RyotaUshio/obsidian-pdf-plus/blob/11f16fd343aa51911b306c2ab6cc3c4cfad53a0b/src/lib/copy-link.ts#L42

Would it be possible to configure an option that is not creating a selection but a search parameter? As a first step, it would already be helpful if a search parameter would execute a search in the PDF and scroll to the found text. Having it similar to selection would also help with having permanent highlights.

My use case is that I'm creating the highlights in different ways than through the PDF. E.g. I've got a lot of clipped content from webpages. I'm adding selected text from that webpage in a file, that I later want to search back in the captured PDF. I'm wondering if an option for that would be possible.

The advanced use case here I'm after is having one link in frontmatter with a source PDF (as can already be done with PDF++ - awesome!) and automatically adding links after quotations based on the text. I've got a plugin ready that can already do the automatic linking.

RyotaUshio commented 8 months ago

First of all, thank you so much for the sponsorship! I really appreciate your support.

As a first step, it would already be helpful if a search parameter would execute a search in the PDF and scroll to the found text.

The search parameter is now available in 0.37.12. For example: [[file.pdf#search=query]] or [[file.pdf#search=Query&case-sensitive=true]] etc. Please see the following section in the plugin settings for the details:

image

You can copy a link with the search param appended from the context menu ("Copy link to search").

RyotaUshio commented 8 months ago

However, text search in PDF is expensive, so it might be difficult to use search links for backlink highlighting, unfortunately.

mdbraber commented 8 months ago

That's absolutely awesome - thanks so much! I can imagine that search is expensive so backlinks with search won't work. Suppose I would be writing my own extension on PDF++ - would it be possible to hook in to an API call or something else that I would input the search phrase and get the selection coordinates of the first result returned? My idea is to e.g. build a command that I can run once that would update all the quote blocks with the relevant links based on their text.

mdbraber commented 8 months ago

I just noticed: when opening a backlink that contains a search parameter the PDF is focused, which is different from opening a backlink that has a select parameter where the note file stays focused. I'm guessing because the search box gets focus? Would it be more logical they both behave the same?