File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
main/kotlin/org/wordpress/aztec/formatting
test/kotlin/org/wordpress/aztec Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -247,8 +247,12 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
247247 }
248248 }
249249 if (position <= 0 && selectionEnd != 0 ) {
250- // If the text contains "\n" return that as the position, else set the position to the end of the text
251- position = editableText.indexOf(" \n " , selectionEnd).takeIf { it >= 0 } ? : editableText.length
250+ position = if (editableText[selectionEnd - 1 ] == ' \n ' ) {
251+ selectionEnd
252+ } else {
253+ // If the text contains "\n" return that as the position, else set the position to the end of the text
254+ editableText.indexOf(" \n " , selectionEnd).takeIf { it >= 0 } ? : editableText.length
255+ }
252256 }
253257 return position
254258 }
Original file line number Diff line number Diff line change @@ -198,4 +198,17 @@ class ImageBlockTest {
198198
199199 Assert .assertEquals(" Test 1<br>test 2<img id=\" 1234\" /><br>test 3" , editText.toHtml())
200200 }
201+
202+ @Test
203+ @Throws(Exception ::class )
204+ fun addImageInTheMiddleOfParagraphsWhenNoBlocksPresent () {
205+ editText.fromHtml(" <p>Line 1</p><p>Line 2</p><p>Line 3</p>" )
206+
207+ editText.setSelection(editText.editableText.indexOf(" 1" ) + 2 )
208+ val attributes = AztecAttributes ()
209+ attributes.setValue(" id" , " 1234" )
210+ editText.insertImage(null , attributes)
211+
212+ Assert .assertEquals(" <p>Line 1</p><img id=\" 1234\" /><p>Line 2</p><p>Line 3</p>" , editText.toHtml())
213+ }
201214}
You can’t perform that action at this time.
0 commit comments