Skip to content

Commit 6af36fa

Browse files
jeremypwJeremy Woottenzeebokleonardo-lemos
authored
Markdown: fix numbered list (#1474)
* Ensure only list lines are renumbered * Fix code style --------- Co-authored-by: Jeremy Wootten <jeremy@Proteus-EL07R6-9b3c42bb.localdomain> Co-authored-by: Ryan Kornheisl <ryan@skarva.tech> Co-authored-by: Leonardo Lemos <leonardolemos@live.com>
1 parent 7c20038 commit 6af36fa

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

plugins/markdown-actions/markdown-actions.vala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,19 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Scratch.Services
115115

116116
private void fix_ordered_list_numbering () {
117117
Gtk.TextIter next;
118+
var count = 1;
119+
var item_text = "";
118120
var current_buffer = current_source.buffer;
121+
119122
current_buffer.get_iter_at_offset (out next, current_buffer.cursor_position);
120123
var line = get_current_line (next).strip ();
121-
int count = 1;
122-
string item_text;
124+
// Get list item number from current line
123125
parse_ordered_list_item (line, ref count, out item_text);
124-
125-
while (next.forward_line ()) {
126+
// Start checking following lines
127+
next.forward_line ();
128+
line = get_current_line (next).strip ();
129+
while (parse_ordered_list_item (line, ref count, out item_text)) {
126130
count++;
127-
line = get_current_line (next).strip ();
128-
if (line.length == 0) {
129-
break;
130-
}
131-
132131
var next_mark = current_buffer.create_mark (null, next, true);
133132
var point_offset = line.index_of_char ('.');
134133
var start = next;
@@ -140,10 +139,12 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Scratch.Services
140139

141140
var to_insert = "%d".printf (count);
142141
current_buffer.insert (ref next, to_insert, to_insert.length);
142+
next.forward_line ();
143+
line = get_current_line (next).strip ();
143144
}
144145
}
145146

146-
private string get_current_line (Gtk.TextIter? start=null) {
147+
private string get_current_line (Gtk.TextIter? start = null) {
147148
var current_buffer = current_source.buffer;
148149
Gtk.TextIter end;
149150

0 commit comments

Comments
 (0)