I have a long HTML document that contains multiple paragraphs. When I try to select the text either in Mobile Safari on iOS or in a UIWebView, the following happens:
When I set the CSS contentEditable
property to true
, I retain the character-level precision, but the keyboard also shows up, which of course I don't want.
Is there any way to retain the character-level selection precision no matter how long the text is that I am selecting?
iOS 8's WKWebView
might be able to solve this problem. WKWebViewConfiguration
has a property called selectionGranularity
. The comment reads:
The level of granularity with which the user can interactively select content in the web view. Possible values are described in WKSelectionGranularity. The default value is WKSelectionGranularityDynamic.
One of the two possible values is WKSelectionGranularityCharacter
. The comment says:
Selection endpoints can be placed at any character boundary.
I have not tried it yet, but it sounds very promising!
Update 7/6/15: It looks like it's not that easy: Text Selection in WKWebView: WKSelectionGranularityCharacter
Update 7/10/15: When you closely investigate the iOS Kindle app, you can see that they have re-implemented "native" text selection in JavaScript because they couldn't make native text selection behave the way they wanted to. I'm pretty sure they must have tried everything else before they decided to re-implement it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With