@@ -42,17 +42,14 @@ class MediaFormatter(editor: AztecText) : AztecFormatter(editor) {
4242 val builder = SpannableStringBuilder (Constants .MAGIC_STRING )
4343 builder.setSpan(span, 0 , 1 , Spanned .SPAN_EXCLUSIVE_EXCLUSIVE )
4444
45- val start = if (inline) {
45+ if (inline) {
4646 editableText.replace(selectionStart, selectionEnd, builder)
47- selectionStart
47+ val newSelectionPosition = editableText.indexOf(Constants .MAGIC_CHAR , selectionStart) + 1
48+ editor.setSelection(newSelectionPosition)
4849 } else {
49- val position = getEndOfBlock()
50- editableText.insert(position, builder)
51- position
50+ builder.append(" \n " )
51+ insertSpanAfterBlock(builder)
5252 }
53-
54- val newSelectionPosition = editableText.indexOf(Constants .MAGIC_CHAR , start) + 1
55- editor.setSelection(newSelectionPosition)
5653 }
5754
5855 fun insertVideo (inline : Boolean , drawable : Drawable ? , attributes : Attributes , onVideoTappedListener : AztecText .OnVideoTappedListener ? ,
@@ -95,10 +92,14 @@ class MediaFormatter(editor: AztecText) : AztecFormatter(editor) {
9592 }
9693
9794 private fun insertMediaAfterBlock (span : AztecMediaSpan ) {
98- val position = getEndOfBlock()
9995 val ssb = SpannableStringBuilder (Constants .IMG_STRING )
10096 ssb.append(" \n " )
10197 buildClickableMediaSpan(ssb, span)
98+ insertSpanAfterBlock(ssb)
99+ }
100+
101+ private fun insertSpanAfterBlock (ssb : SpannableStringBuilder ) {
102+ val position = getEndOfBlock()
102103 // We need to be sure the cursor is placed correctly after media insertion
103104 // Note that media has '\n' around them when needed
104105 val isLastItem = position == EndOfBufferMarkerAdder .safeLength(editor)
0 commit comments