diff --git a/data/io.elementary.code.appdata.xml.in b/data/io.elementary.code.appdata.xml.in
index 652111fdf7..e5074c3a0a 100644
--- a/data/io.elementary.code.appdata.xml.in
+++ b/data/io.elementary.code.appdata.xml.in
@@ -40,6 +40,7 @@
It is now possible to change Git branch with untracked files present in a project
Crashes are prevented while searching in large projects
The correct document is now focused after opening Code from an external program
+ Line duplication is now actioned correctly if there is no selection present
Minor updates:
diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala
index fa361ef52f..d14724d371 100644
--- a/src/Widgets/SourceView.vala
+++ b/src/Widgets/SourceView.vala
@@ -344,7 +344,7 @@ namespace Scratch.Widgets {
// If selected text does not exists duplicate current line.
// If selected text is only in one line duplicate in place.
- // If seected text covers more than one line, duplicate all lines complete.
+ // If selected text covers more than one line, duplicate all lines complete.
public void duplicate_selection () {
Gtk.TextIter? start = null;
Gtk.TextIter? end = null;
@@ -357,7 +357,6 @@ namespace Scratch.Widgets {
buffer.get_selection_bounds (out start, out end);
start_line = start.get_line ();
end_line = end.get_line ();
-
if (start_line != end_line) {
buffer.get_iter_at_line (out start, start_line);
buffer.get_iter_at_line (out end, end_line);
@@ -370,10 +369,13 @@ namespace Scratch.Widgets {
selection_end_offset = end.get_offset ();
} else {
buffer.get_iter_at_mark (out start, buffer.get_insert ());
- start.backward_line (); //To start of previous line
- start.forward_line (); //To start of original line
+ start.backward_chars (start.get_line_offset ());
end = start.copy ();
- end.forward_to_line_end ();
+ end.forward_chars (end.get_chars_in_line ());
+ if (end.get_line () != start.get_line ()) { // Line lacked final return character
+ end.backward_char ();
+ }
+
selection = "\n" + buffer.get_text (start, end, true);
}