Fix not being able to select text by double clicking with cursor on iPad
Also fix not being able to single-tap data detector value to see menu Closes #499
This commit is contained in:
parent
888f44366c
commit
cee4e15b06
|
@ -36,6 +36,8 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
|
||||||
var emojiFont: UIFont = .preferredFont(forTextStyle: .body)
|
var emojiFont: UIFont = .preferredFont(forTextStyle: .body)
|
||||||
var emojiTextColor: UIColor = .label
|
var emojiTextColor: UIColor = .label
|
||||||
|
|
||||||
|
private let tapRecognizer = UITapGestureRecognizer()
|
||||||
|
|
||||||
// The link range currently being previewed
|
// The link range currently being previewed
|
||||||
private var currentPreviewedLinkRange: NSRange?
|
private var currentPreviewedLinkRange: NSRange?
|
||||||
// The preview created in the previewForHighlighting method, so that we can use the same one in previewForDismissing.
|
// The preview created in the previewForHighlighting method, so that we can use the same one in previewForDismissing.
|
||||||
|
@ -78,8 +80,9 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
|
||||||
updateLinkUnderlineStyle()
|
updateLinkUnderlineStyle()
|
||||||
|
|
||||||
// the text view's builtin link interaction code is tied to isSelectable, so we need to use our own tap recognizer
|
// the text view's builtin link interaction code is tied to isSelectable, so we need to use our own tap recognizer
|
||||||
let recognizer = UITapGestureRecognizer(target: self, action: #selector(textTapped(_:)))
|
tapRecognizer.addTarget(self, action: #selector(textTapped(_:)))
|
||||||
addGestureRecognizer(recognizer)
|
tapRecognizer.delegate = self
|
||||||
|
addGestureRecognizer(tapRecognizer)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(_updateLinkUnderlineStyle), name: UIAccessibility.buttonShapesEnabledStatusDidChangeNotification, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(_updateLinkUnderlineStyle), name: UIAccessibility.buttonShapesEnabledStatusDidChangeNotification, object: nil)
|
||||||
underlineTextLinksCancellable =
|
underlineTextLinksCancellable =
|
||||||
|
@ -132,12 +135,6 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func textTapped(_ recognizer: UITapGestureRecognizer) {
|
@objc func textTapped(_ recognizer: UITapGestureRecognizer) {
|
||||||
// if there currently is a selection, deselct it on single-tap
|
|
||||||
if selectedRange.length > 0 {
|
|
||||||
// location doesn't matter since we are non-editable and the cursor isn't visible
|
|
||||||
selectedRange = NSRange(location: 0, length: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
let location = recognizer.location(in: self)
|
let location = recognizer.location(in: self)
|
||||||
if let (link, range) = getLinkAtPoint(location),
|
if let (link, range) = getLinkAtPoint(location),
|
||||||
link.scheme != dataDetectorsScheme {
|
link.scheme != dataDetectorsScheme {
|
||||||
|
@ -384,3 +381,25 @@ extension ContentTextView: UIContextMenuInteractionDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension ContentTextView: UIGestureRecognizerDelegate {
|
||||||
|
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||||
|
// NB: This method is both a gesture recognizer delegate method and a UIView method.
|
||||||
|
// We only want to prevent our own tap gesture recognizer from beginning, but don't
|
||||||
|
// want to interfere with any other gestures that may begin over this view.
|
||||||
|
if gestureRecognizer === tapRecognizer {
|
||||||
|
let location = gestureRecognizer.location(in: self)
|
||||||
|
if let (link, _) = getLinkAtPoint(location) {
|
||||||
|
if link.scheme == dataDetectorsScheme {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue