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/fix markdown numberedlist #1474

Draft
wants to merge 3 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
21 changes: 11 additions & 10 deletions plugins/markdown-actions/markdown-actions.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,19 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable

private void fix_ordered_list_numbering () {
Gtk.TextIter next;
var count = 1;
var item_text = "";
var current_buffer = current_source.buffer;

current_buffer.get_iter_at_offset (out next, current_buffer.cursor_position);
var line = get_current_line (next).strip ();
int count = 1;
string item_text;
// Get list item number from current line
parse_ordered_list_item (line, ref count, out item_text);

while (next.forward_line ()) {
// Start checking following lines
next.forward_line ();
line = get_current_line (next).strip ();
while (parse_ordered_list_item (line, ref count, out item_text)) {
count++;
line = get_current_line (next).strip ();
if (line.length == 0) {
break;
}

var next_mark = current_buffer.create_mark (null, next, true);
var point_offset = line.index_of_char ('.');
var start = next;
Expand All @@ -140,10 +139,12 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable

var to_insert = "%d".printf (count);
current_buffer.insert (ref next, to_insert, to_insert.length);
next.forward_line ();
line = get_current_line (next).strip ();
}
}

private string get_current_line (Gtk.TextIter? start=null) {
private string get_current_line (Gtk.TextIter? start = null) {
var current_buffer = current_source.buffer;
Gtk.TextIter end;

Expand Down