@@ -207,6 +207,7 @@ open class TextView: UITextView {
207207 HeaderFormatter ( headerLevel: . h6) ,
208208 FigureFormatter ( ) ,
209209 FigcaptionFormatter ( ) ,
210+ MarkFormatter ( ) ,
210211 ]
211212
212213 /// At some point moving ahead, this could be dynamically generated from the full list of registered formatters
@@ -1154,12 +1155,27 @@ open class TextView: UITextView {
11541155 ///
11551156 /// - Parameter range: The NSRange to edit.
11561157 ///
1157- open func toggleMark( range: NSRange ) {
1158+ open func toggleMark( range: NSRange , color : String ? , resetColor : Bool ) {
11581159 let formatter = MarkFormatter ( )
11591160 formatter. placeholderAttributes = self . defaultAttributes
1160- toggle ( formatter: formatter, atRange: range)
1161+ formatter. defaulTextColor = self . defaultTextColor
1162+ formatter. textColor = color
11611163
1162- formattingDelegate? . textViewCommandToggledAStyle ( )
1164+ // If the format exists remove the current formatting
1165+ // this can happen when the color changed.
1166+ if ( formatter. present ( in: typingAttributes) ) {
1167+ typingAttributes = formatter. remove ( from: typingAttributes)
1168+ let applicationRange = formatter. applicationRange ( for: selectedRange, in: storage)
1169+ formatter. removeAttributes ( from: storage, at: applicationRange)
1170+ typingAttributes = formatter. remove ( from: typingAttributes)
1171+
1172+ // Reflect color changes by enabling the formatting again.
1173+ if ( !resetColor) {
1174+ toggle ( formatter: formatter, atRange: range)
1175+ }
1176+ return
1177+ }
1178+ toggle ( formatter: formatter, atRange: range)
11631179 }
11641180
11651181 /// Replaces with an horizontal ruler on the specified range
0 commit comments