Home:ALL Converter>IOS: Text Selection in WKWebView (WKSelectionGranularityCharacter)

IOS: Text Selection in WKWebView (WKSelectionGranularityCharacter)

Ask Time:2014-09-20T00:24:09         Author:Tom Hamming

Json Formatter

I've got an app that uses a web view where text can be selected. It's long been an annoyance that you can't select text across a block boundary in UIWebView. WKWebView seems to fix this with a property on its configuration: selectionGranularity. One of the possible values is WKSelectionGranularityCharacter:

Selection endpoints can be placed at any character boundary.

Sounds great! Exactly what I need. Except that when I set that in my web view, I often can no longer select text at all. What is going on? Is there something else I need to set? Has anyone figured this out?

Update: I've figured out the following bugs:

  1. When there is more than one WKWebView in an app with selectionGranularity set to WKSelectionGranularityCharacter, only the most recent one to load can select text. I've filed this as bug 18441138.

  2. If there is a click handler attached to an element inside the body in the HTML content of a WKWebView whose selectionGranularity is set to WKSelectionGranularityCharacter, text selection doesn't work inside that element. I've filed this as bug 18440833.

  3. Text selection fails in the WKWebView after you've entered edit mode on a UITextView somewhere else in the app until the WKWebView reloads. I've filed this as bug 18468405.

Has anyone worked around any of these?

Author:Tom Hamming,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25938393/ios-text-selection-in-wkwebview-wkselectiongranularitycharacter
Tom Hamming :

These and other issues are all fixed as of iOS 13.",
2019-11-22T20:51:40
yy