mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Optimize url detection (close #831)
This commit is contained in:
parent
d72efa5f8b
commit
54742deda1
11
CHANGELOG.md
11
CHANGELOG.md
@ -2,7 +2,16 @@
|
||||
Change Log
|
||||
==========================
|
||||
|
||||
3.5.0 (unreleased)
|
||||
3.5.0-beta.2 (unreleased)
|
||||
--------------------------
|
||||
|
||||
### Improvements
|
||||
|
||||
- Optimize auto URL detection with paste to a large document.
|
||||
|
||||
|
||||
|
||||
3.5.0-beta (263)
|
||||
--------------------------
|
||||
|
||||
### New Features
|
||||
|
@ -1255,21 +1255,21 @@ final class EditorTextView: NSTextView, Themable {
|
||||
}
|
||||
|
||||
|
||||
/// make link-like text clickable
|
||||
/// make URL-like text clickable
|
||||
private func detectLinkIfNeeded() {
|
||||
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
guard self.isAutomaticLinkDetectionEnabled else { return }
|
||||
|
||||
self.undoManager?.disableUndoRegistration()
|
||||
// -> use own dataDetector instead of `checkTextInDocument(_:)` due to performance issue (2018-07)
|
||||
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
|
||||
let currentCheckingType = self.enabledTextCheckingTypes
|
||||
self.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
|
||||
self.checkTextInDocument(nil)
|
||||
self.enabledTextCheckingTypes = currentCheckingType
|
||||
|
||||
self.undoManager?.enableUndoRegistration()
|
||||
detector.enumerateMatches(in: self.string, range: self.string.nsRange) { (result, _, _) in
|
||||
guard let result = result, let url = result.url else { return }
|
||||
|
||||
self.textStorage?.addAttribute(.link, value: url, range: result.range)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user