Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions plugins/markdown-actions/markdown-actions.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Scratch.Services
}

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;
Expand Down Expand Up @@ -175,12 +179,16 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Scratch.Services
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;
}

Expand Down