Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jeremypw/fixmarkdown unorderededlist extend #1480

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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, 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;
Expand Down Expand Up @@ -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;
}

Expand Down