kiwix / kiwix-js

Fully portable & lightweight ZIM reader in Javascript
https://www.kiwix.org/
GNU General Public License v3.0
311 stars 134 forks source link

Add clipboard functionality using clipboard API #585

Open Jaifroid opened 4 years ago

Jaifroid commented 4 years ago

Information about this API is here:

https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API

This could be used to enable selection of text -> long press -> "search this text" link, for example.

mossroy commented 4 years ago

There is such feature in the Android version of Kiwix. It would be cool to implement it in kiwix-js too, even if I don't think it's a high priority. And it works for text selection in any other app.

Could you elaborate on the use-case you imagine?

For webextensions, we could probably do something similar, by adding a context menu (with https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Context_menu_items), that launches a search in kiwix-js. The complicated part might be to open or re-use the kiwix-js tab, and interact with it : this needs to be investigated.

For other contexts, it might be possible to add a context menu for the iframe content (in a generic way). It could have been easy with https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu . Unfortunately, it is currently only supported by Firefox, see https://caniuse.com/#feat=menu , and is considered deprecated by W3C. There are other ways to do it, but I don't like them. Either because they replace the standard menu items, or because they modify the events inside the iframe (which might break the behavior of the ZIM content)

Jaifroid commented 4 years ago

I haven't given it much thought, but I imagined being able to select an interesting word or name or phrase and the text would be copied to the clipboard, and this API could detect that event and then show a menu of options. However, the only option I can currently think of is "Search this text", which is something that is relatively easy to do with standard copy-paste right now. Maybe also "Read this text" (which we have a stalled PR for somewhere, and this would be one way of implementing UI for it). Yes, I agree that this could perhaps be a way of adding a sort-of context menu without adding events in the iframe, because the event in this case is the browser's clipboard event. But it would be non-standard to have to press "copy" to show a menu.