diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 024e97c3b..36bc50d5d 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -76,15 +76,19 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable } if (evt.keyval == Gdk.Key.Return) { - char ul_marker; + var line = get_current_line (); + if (line.strip () == "") { + return false; + } + + string ul_marker; int ol_number = 1; string item_text; - var line = get_current_line (); if (parse_unordered_list_item (line, out ul_marker)) { - if (line.length <= 3) { // empty item + if (line.strip ().length <= 3) { // empty list item delete_empty_item (); } else { - string to_insert = "\n%c ".printf (ul_marker); + string to_insert = "\n%s".printf (ul_marker); current_source.buffer.insert_at_cursor (to_insert, to_insert.length); } return true; @@ -174,12 +178,16 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable return true; } - private bool parse_unordered_list_item (string line, out char ul_marker) { - if ((line[0] == '*' || line[0] == '-') && line[1] == ' ') { - ul_marker = line[0]; + private bool parse_unordered_list_item (string line, out string ul_marker) { + var chugged_line = line.chug (); + if ((chugged_line[0] == '*' || chugged_line[0] == '-') && + chugged_line[1] == ' ') { + var ul_marker_index = line.index_of_char (chugged_line[0]); + ul_marker = "%s%c ".printf (string.nfill (ul_marker_index, ' '), chugged_line[0]); return true; } - ul_marker = '\0'; + + ul_marker = ""; return false; }