Closed bksubhuti closed 1 year ago
So technically you don't need the text to be selectable, you just need to capture the word when it is tapped?
yes.. exactly. Tap to capture word.
It is very useful for a "reading" program that is dictionary intensive.
Imagine that you read a paragraph of religious text and you need a dictionary for 5 words of that paragraph to help you remember. It is a lot of work, to long_click but not soooo bad. (I really appreciate the onSelectionChange.. it is much better than using a menu popup).
But a single tap would be much better. Currently that is how it works.
Here is video of an older JS electron app called tipitaka pali projector.
https://youtu.be/64PwmEf3utI?t=435
7 minutes 10 sec shows a little bit
and here
https://youtu.be/3rDYs1u9T-8?t=207
3:27
I don't have a video for the flutter (replacement) app.
but it is released already on the android play and ios app store.
Tipitaka Pali Reader You can see how it works.
apple ios https://apps.apple.com/us/developer/path-nirvana-foundation/id1434955292
android https://play.google.com/store/apps/details?id=com.paauk.tipitakapalireader&hl=en&gl=US
You can use hitTest
to obtain the text under the tap. Something like this:
GestureDetector(
child: HtmlWidget(html, key: key),
onTapUp: (details) {
final box = key.currentContext!.findRenderObject()! as RenderBox;
final result = BoxHitTestResult();
final offset = box.globalToLocal(details.globalPosition);
if (!box.hitTest(result, position: offset)) {
return;
}
for (final entry in result.path) {
final target = entry.target;
if (entry is! BoxHitTestEntry || target is! RenderParagraph) {
continue;
}
final p = target.getPositionForOffset(entry.localPosition);
final text = target.text.toPlainText();
print(text.substring(p.offset, p.offset + 5));
}
},
)
With the text and offset, you should be able to figure out the tapped word.
ven pndazza (the main programmer), said this code now works. This helps us a real lot with the ios problem. Keep open .. I'll report about the single click issue later.
To answer your question about needing selectable.. we do need the text to be selectable as well. Some issues exist with some words not getting highlighted -- selectable, but we can capture the word. We will research this more.
We already have a proposed solution so I'm closing this for now. Feel free to reopen if you want to revisit this.
Use case
We have an app that has single click to get a word selected and then a callback with that word. isSelectable and onSelectionChange are good, but we would really like to capture the word with a tap and a mouse click for easy dictionary lookups.
The big work around is to place url links surrounding each word.. but this is heavy .
Proposal
Below is the code that we use to generate a single click callback in WebView widget which we are trying to migrate out of. var pageContent = document.getElementById("page_content"); pageContent.addEventListener('click', function(e) { // e.preventDefault();
}, false);