Commit eaefe20 1 parent 10c95a5 commit eaefe20 Copy full SHA for eaefe20
File tree 1 file changed +11
-16
lines changed
editor/src/main/java/com/canopas/editor/ui/data
1 file changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -266,21 +266,14 @@ class QuillTextManager(quillSpan: QuillSpan) {
266
266
val fromIndex = selection.min
267
267
val toIndex = if (selection.collapsed) fromIndex else selection.max
268
268
269
- val startIndex: Int = max(0 , text.lastIndexOf(" \n " , fromIndex - 1 ))
270
- var endIndex: Int = text.indexOf(" \n " , toIndex)
271
-
272
- if (endIndex == - 1 ) endIndex = text.length - 1
273
- val selectedParts =
274
- quillTextSpans.filter { endIndex >= it.to && startIndex <= it.from && it.style.any { it.isHeaderStyle() } }
275
-
276
- quillTextSpans.removeAll(selectedParts)
277
- quillTextSpans.add(
278
- QuillTextSpan (
279
- from = startIndex,
280
- to = endIndex,
281
- style = listOf (style)
282
- )
283
- )
269
+ val currentSpan = quillTextSpans.find {
270
+ it.from <= fromIndex && it.to >= toIndex
271
+ }
272
+ val index = quillTextSpans.indexOf(currentSpan)
273
+ quillTextSpans[index] =
274
+ currentSpan?.copy(style = currentSpan.style.filterNot { it.isHeaderStyle() } + listOf (
275
+ style
276
+ )) ? : return
284
277
updateText()
285
278
}
286
279
@@ -308,7 +301,9 @@ class QuillTextManager(quillSpan: QuillSpan) {
308
301
part.from < endIndex && part.to >= startIndex
309
302
}
310
303
311
- quillTextSpans.removeAll(selectedParts.filter { it.style.any { it.isHeaderStyle() } })
304
+ quillTextSpans.removeAll(selectedParts.filter {
305
+ it.style.size == 1 && it.style.first().isHeaderStyle()
306
+ })
312
307
}
313
308
314
309
private fun removeStylesFromSelectedPart (
You can’t perform that action at this time.
0 commit comments