windingwind / zotero-plugin-toolkit

Toolkit for Zotero Plugin Developers.
https://www.npmjs.com/package/zotero-plugin-toolkit
MIT License
115 stars 13 forks source link

Get selected text in library tab? #60

Closed ImperialSquid closed 1 month ago

ImperialSquid commented 2 months ago

Getting the selected text in a reader tab is relatively simple, I was wondering if it's possible to get the selected text in the library tab too (eg if the user has selected some text in a note)

I didn't see anything like that in this toolkit, and a skim of the main Zotero repo didn't show anything, but I might have missed it.

Thanks in advance!

windingwind commented 2 months ago

Note editor is in an iframe and thus getting the selection can be complicated. What do you plan to do with the selection in note editor?

ImperialSquid commented 2 months ago

A user of my text to speech plugin expressed that they'd like to be able to selectively speak text due to how they use RSS feed items (the note item was just an example)

("an iframe and thus getting the selection can be complicated", yeah that's been one of my biggest struggles with plugin development honestly, I'm not a web dev by any extent so a lot of my work has been running face first into all sorts of security and privacy measures and stuff lol)

windingwind commented 2 months ago

I'm not familiar with the accessibility issues, but I guess Zotero has support for screen readers. For me, the MacOS VoiceOver can read the selection in the note as expected.

Back to your question, try this:

if (ZoteroPane.itemPane.mode === "note") {
    Zotero.debug(ZoteroPane.itemPane.getCurrentPane()._iframe.contentDocument.getSelection());
}
ImperialSquid commented 2 months ago

I was making a joke about my continued struggles with highlighting text within the reader iframe, sorry for any confusion...!

For the solution, that works perfectly, thanks! Looks like there's some variation in terms of what fields exist on what types, but this definitely helps point me in the right direction!