@@ -1109,8 +1109,45 @@ class BlockFormatter(editor: AztecText,
11091109 }
11101110
11111111 fun containsPreformat (selStart : Int = selectionStart, selEnd : Int = selectionEnd): Boolean {
1112- val spans = editableText.getSpans(selStart, selEnd, AztecPreformatSpan ::class .java)
1113- return spans.isNotEmpty()
1112+ val lines = TextUtils .split(editableText.toString(), " \n " )
1113+ val list = ArrayList <Int >()
1114+
1115+ for (i in lines.indices) {
1116+ val lineStart = (0 until i).sumBy { lines[it].length + 1 }
1117+ val lineEnd = lineStart + lines[i].length
1118+
1119+ if (lineStart > lineEnd) {
1120+ continue
1121+ }
1122+
1123+ if (lineStart <= selectionEnd && lineEnd >= selectionStart) {
1124+ list.add(i)
1125+ }
1126+ }
1127+
1128+ if (list.isEmpty()) return false
1129+
1130+ return list.any { containsPreformat(it) }
1131+ }
1132+
1133+ fun containsPreformat (index : Int ): Boolean {
1134+ val lines = TextUtils .split(editableText.toString(), " \n " )
1135+ if (index < 0 || index >= lines.size) {
1136+ return false
1137+ }
1138+
1139+ val start = (0 until index).sumBy { lines[it].length + 1 }
1140+ val end = start + lines[index].length
1141+
1142+ if (start > end) {
1143+ return false
1144+ }
1145+
1146+ val spans = editableText.getSpans(start, end, AztecPreformatSpan ::class .java)
1147+ return spans.any {
1148+ val spanEnd = editableText.getSpanEnd(it)
1149+ spanEnd != start || editableText[spanEnd] != ' \n '
1150+ }
11141151 }
11151152
11161153 private fun switchListType (listTypeToSwitchTo : ITextFormat , start : Int = selectionStart, end : Int = selectionEnd, attrs : AztecAttributes = AztecAttributes ()) {
0 commit comments