-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hello,
I see this code in CodeAttributedString of Highlightr. It has a non-nil check for language else it doesn't proceed and hence doesn't highlight nor auto-detect the language. Is this expected?
func highlight(_ range: NSRange)
{
if(language == nil)
{
return;
}
if let highlightDelegate = highlightDelegate
{
let shouldHighlight : Bool? = highlightDelegate.shouldHighlight?(range)
if(shouldHighlight != nil && !shouldHighlight!)
{
return;
}
}
let string = (self.string as NSString)
let line = string.substring(with: range)
DispatchQueue.global().async
{
let tmpStrg = self.highlightr.highlight(line, as: self.language!)
DispatchQueue.main.async(execute: {
//Checks to see if this highlighting is still valid.
if((range.location + range.length) > self.stringStorage.length)
{
self.highlightDelegate?.didHighlight?(range, success: false)
return;
}
if(tmpStrg?.string != self.stringStorage.attributedSubstring(from: range).string)
{
self.highlightDelegate?.didHighlight?(range, success: false)
return;
}
self.beginEditing()
tmpStrg?.enumerateAttributes(in: NSMakeRange(0, (tmpStrg?.length)!), options: [], using: { (attrs, locRange, stop) in
var fixedRange = NSMakeRange(range.location+locRange.location, locRange.length)
fixedRange.length = (fixedRange.location + fixedRange.length < string.length) ? fixedRange.length : string.length-fixedRange.location
fixedRange.length = (fixedRange.length >= 0) ? fixedRange.length : 0
self.stringStorage.setAttributes(attrs, range: fixedRange)
})
self.endEditing()
self.edited(TextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
self.highlightDelegate?.didHighlight?(range, success: true)
})
}
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request