Skip to content

Commit

Permalink
Merge pull request #3 from pbineteco/mentionsLabel
Browse files Browse the repository at this point in the history
Mentions label
  • Loading branch information
Asuard authored Nov 9, 2018
2 parents e092475 + 38d0495 commit ad22c62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions ActiveLabel/ActiveBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,21 @@ struct ActiveBuilder {
let matches = RegexParser.getElements(from: text, with: type.pattern, range: range)
let nsstring = text as NSString
var elements: [ElementTuple] = []


for match in matches where match.range.length > minLength {
var word = nsstring.substring(with: match.range)
.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
if word.hasPrefix("@"), let mentions = mentions {
if let mention = mentions.first(where: {(word.contains($0.name) && word != $0.name) || word == $0.name }) {
word = mention.name
}
if word.hasPrefix("@"), let mentions = mentions, let mention = mentions.first(where: {(word.contains($0.name))}) {
word = mention.name
if filterPredicate?(word) ?? true {
let element = ActiveElement.create(with: type, text: word)
let range = NSRange(location: match.range.location, length: word.count + 1)
var range = NSRange(location: match.range.location, length: word.count + 1)
if range.location + range.length >= text.count {
range = NSRange(location: range.location, length: text.count - range.location)
}
elements.append((range, element, type))
}
} else {
if filterPredicate?(word) ?? true {
if word.hasPrefix("#"), filterPredicate?(word) ?? true {
let element = ActiveElement.create(with: type, text: word)
elements.append((match.range, element, type))
}
Expand Down
4 changes: 2 additions & 2 deletions ActiveLabel/ActiveLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public typealias MentionToPass = (userId: Int, name: String)
open var urlMaximumLength: Int?

open var configureLinkAttribute: ConfigureLinkAttribute?

@IBInspectable open var mentionColor: UIColor = .blue {
@IBInspectable open var mentionColor: UIColor = .black {
didSet { updateTextStorage(parseText: false) }
}
@IBInspectable open var mentionSelectedColor: UIColor? {
Expand Down

0 comments on commit ad22c62

Please sign in to comment.