Skip to content

Commit f79e23f

Browse files
committed
Remove newlines from insert media method
1 parent 06da6d9 commit f79e23f

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/formatting/LineBlockFormatter.kt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,15 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
268268
}
269269

270270
fun insertMedia(drawable: Drawable, source: String) {
271-
//check if we add media into a block element, at the end of the line, but not at the end of last line
272-
var applyingOnTheEndOfBlockLine = false
273-
editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java).forEach {
274-
if (editableText.getSpanEnd(it) > selectionEnd && editableText[selectionEnd] == '\n') {
275-
applyingOnTheEndOfBlockLine = true
276-
return@forEach
277-
}
278-
}
279-
280-
val mediaStartIndex = selectionStart + 1
281-
val mediaEndIndex = selectionStart + source.length + 1
271+
val mediaStartIndex = selectionStart
272+
val mediaEndIndex = selectionStart + source.length
282273

283274
editor.disableTextChangedListener()
284-
editableText.replace(selectionStart, selectionEnd, "\n" + source + if (applyingOnTheEndOfBlockLine) "" else "\n")
275+
editableText.replace(selectionStart, selectionEnd, source)
285276

286-
editor.removeBlockStylesFromRange(mediaStartIndex, mediaEndIndex + 1, true)
287-
editor.removeHeadingStylesFromRange(mediaStartIndex, mediaEndIndex + 1)
288-
editor.removeInlineStylesFromRange(mediaStartIndex, mediaEndIndex + 1)
277+
editor.removeBlockStylesFromRange(mediaStartIndex, mediaEndIndex, true)
278+
editor.removeHeadingStylesFromRange(mediaStartIndex, mediaEndIndex)
279+
editor.removeInlineStylesFromRange(mediaStartIndex, mediaEndIndex)
289280

290281
val span = AztecMediaSpan(editor.context, drawable, source)
291282

@@ -303,7 +294,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
303294
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
304295
)
305296

306-
editor.setSelection(mediaEndIndex + 1)
297+
editor.setSelection(mediaEndIndex)
307298
editor.isMediaAdded = true
308299
}
309300
}

0 commit comments

Comments
 (0)