From f6ff15144f88328ff1699d44cd727eb095ffd45e Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 14 Oct 2024 17:24:33 +0100 Subject: [PATCH 1/2] Ensure only list lines are renumbered --- .../markdown-actions/markdown-actions.vala | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 024e97c3b6..48006675bf 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -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; @@ -140,6 +139,8 @@ 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 (); } } From 901d71585e5aa3498f5132b3506cf973d1fbafdd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 14 Oct 2024 17:24:45 +0100 Subject: [PATCH 2/2] Fix code style --- plugins/markdown-actions/markdown-actions.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 48006675bf..29e5fb4d40 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -144,7 +144,7 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable } } - 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;