diff --git a/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java b/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java index 2c8204ad9a..db50384ce2 100644 --- a/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java +++ b/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java @@ -894,8 +894,10 @@ public static void duplicateLineSelection(final HighlightingEditor hlEditor) { final int[] selEnd = TextViewUtils.getLineOffsetFromIndex(text, sel[1]); hlEditor.withAutoFormatDisabled(() -> { - final String lines_final = String.format("%s\n", lines); - text.insert(linesEnd + 1, lines_final); + // Prepending the newline instead of appending it is required for making + // this logic work even if it's about the last line in the given file. + final String lines_final = String.format("\n%s", lines); + text.insert(linesEnd, lines_final); }); final int sel_offset = selEnd[0] - selStart[0] + 1;