|
@@ -657,15 +657,16 @@ extension String {
|
|
|
continue
|
|
|
}
|
|
|
if (rangeBold[i].endIndex == textUTF8.count - 1 || checkCharBeforeAfter(char: textUTF8.substring(from: rangeBold[i].endIndex + 1, to: rangeBold[i].endIndex + 1))) {
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
|
|
|
- totalEmoji = totalEmoji + countEmoji
|
|
|
- finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign), length: rangeBold[i].endIndex - lastFirstRange + totalEmoji + 1))
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign), length: 1 + countEmoji))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex - 1 - (2*countRemoveBoldSign) + countEmoji, length: 1 + countEmoji))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex + totalEmoji - (2*countRemoveBoldSign) - 1, length: 1))
|
|
|
countRemoveBoldSign += 1
|
|
|
} else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeBold[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
lastFirstRange = 0
|
|
@@ -694,15 +695,16 @@ extension String {
|
|
|
continue
|
|
|
}
|
|
|
if (rangeItalic[i].endIndex == textAfterbold.count - 1 || checkCharBeforeAfter(char: textAfterbold.substring(from: rangeItalic[i].endIndex + 1, to: rangeItalic[i].endIndex + 1))) {
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
|
|
|
- totalEmoji = totalEmoji + countEmoji
|
|
|
- finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign), length: rangeItalic[i].endIndex - lastFirstRange + totalEmoji + 1))
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
|
|
|
if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign), length: 1 + countEmoji))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex - 1 - (2*countRemoveItalicSign) + countEmoji, length: 1 + countEmoji))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
|
|
|
countRemoveItalicSign += 1
|
|
|
} else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
lastFirstRange = 0
|
|
@@ -731,15 +733,16 @@ extension String {
|
|
|
continue
|
|
|
}
|
|
|
if (rangeUnderline[i].endIndex == textAfterItalic.count - 1 || checkCharBeforeAfter(char: textAfterItalic.substring(from: rangeUnderline[i].endIndex + 1, to: rangeUnderline[i].endIndex + 1))) {
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveUnderlineSign), to: rangeUnderline[i].endIndex - (2*countRemoveUnderlineSign)).countEmojiCharacter()
|
|
|
- totalEmoji = totalEmoji + countEmoji
|
|
|
- finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign), length: rangeUnderline[i].endIndex - lastFirstRange + totalEmoji + 1))
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign) + countEmojiBefore + 1, length: (rangeUnderline[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign), length: 1 + countEmoji))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex - 1 - (2*countRemoveUnderlineSign) + countEmoji, length: 1 + countEmoji))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveUnderlineSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji - (2*countRemoveUnderlineSign) - 1, length: 1))
|
|
|
countRemoveUnderlineSign += 1
|
|
|
} else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
lastFirstRange = 0
|
|
@@ -768,15 +771,16 @@ extension String {
|
|
|
continue
|
|
|
}
|
|
|
if (rangeStrikethrough[i].endIndex == textAfterUnderline.count - 1 || checkCharBeforeAfter(char: textAfterUnderline.substring(from: rangeStrikethrough[i].endIndex + 1, to: rangeStrikethrough[i].endIndex + 1))) {
|
|
|
+ let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveStrikethroughSign), to: rangeStrikethrough[i].endIndex - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
|
|
|
- totalEmoji = totalEmoji + countEmoji
|
|
|
- finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign), length: rangeStrikethrough[i].endIndex - lastFirstRange + totalEmoji + 1))
|
|
|
+ totalEmoji = countEmoji + countEmojiBefore
|
|
|
+ finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign) + countEmojiBefore + 1, length: (rangeStrikethrough[i].endIndex + countEmoji - 1) - lastFirstRange))
|
|
|
if !isEditing{
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign), length: 1 + countEmoji))
|
|
|
- finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex - 1 - (2*countRemoveStrikethroughSign) + countEmoji, length: 1 + countEmoji))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveStrikethroughSign), length: 1))
|
|
|
+ finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji - (2*countRemoveStrikethroughSign) - 1, length: 1))
|
|
|
countRemoveStrikethroughSign += 1
|
|
|
} else {
|
|
|
- finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
|
|
|
+ finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
|
|
|
finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji, length: 1))
|
|
|
}
|
|
|
lastFirstRange = 0
|