readium / swift-toolkit

A toolkit for ebooks, audiobooks and comics written in Swift
https://readium.org/mobile/
BSD 3-Clause "New" or "Revised" License
225 stars 96 forks source link

How do I catch sentences that long press on words #296

Closed sokach-dev closed 1 year ago

sokach-dev commented 1 year ago

When I press and select a word, can I get the sentence of the word? How should I call the function if I can?

Examples: Today is a wonderful day!

When I press "wonderful", I also get "Today is a wonderful day!"

mickael-menu commented 1 year ago

Implement this API in the EPUBNavigatorDelegate: https://github.com/readium/swift-toolkit/blob/9e0339787aa69f96bb16335f55a858d626eaccb9/Sources/Navigator/SelectableNavigator.swift#L38

Then look at the text context in selection.locator.text. The before and after properties should contain more text context around the current selected word.

If this doesn't work, you will need to implement your own JavaScript to do that:

https://github.com/readium/swift-toolkit/blob/9e0339787aa69f96bb16335f55a858d626eaccb9/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift#L17