                 
             case .autoLinkDetection:
                 self.isAutomaticLinkDetectionEnabled = new as! Bool
-                if self.isAutomaticLinkDetectionEnabled {
-                    self.detectLinkIfNeeded()
-                } else if let textStorage = self.textStorage {
-                    textStorage.removeAttribute(.link, range: textStorage.range)
+                if let textStorage = self.textStorage {
+                    if self.isAutomaticLinkDetectionEnabled {
+                        textStorage.detectLink()
+                    } else {
+                        textStorage.removeAttribute(.link, range: textStorage.range)
+                    }
                 }
                 
             case .pageGuideColumn:

        
        self.textContainerInset.height = height
        self.sizeToFit()
    }
    
    
    /// make URL-like text clickable
    private func detectLinkIfNeeded(in range: NSRange? = nil) {
        
        assert(Thread.isMainThread)
        
        guard
            self.isAutomaticLinkDetectionEnabled,
            let textStorage = self.textStorage
            else { return }
        
        let range = range.flatMap { (self.string as NSString).lineRange(for: $0) } ?? textStorage.range
        
        // -> use own dataDetector instead of `checkTextInDocument(_:)` due to performance issue (2018-07)
        textStorage.detectLink(in: range)
        
        // ensure layout to avoid unwanted scroll with cursor move after pasting something
        // at the latter part of the document. (2018-10 macOS 10.14)
        self.layoutManager?.ensureLayout(forCharacterRange: range)
    }
    
    

    /// read pasted/dropped item from NSPaseboard (involed in `performDragOperation(_:)`)
    override func readSelection(from pboard: NSPasteboard, type: NSPasteboard.PasteboardType) -> Bool {
        
        // link URLs in pasted string
        defer {
            if self.isAutomaticLinkDetectionEnabled {
                self.textStorage?.detectLink()
            }
        }
        
        // on file drop
