From 1eb03ac9a7ffa32408e3eddb7acae980eabe808f Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Tue, 15 Oct 2024 15:31:08 +0100 Subject: [PATCH 1/2] Fix extension of unordered list --- plugins/markdown-actions/markdown-actions.vala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 024e97c3b6..8ce84ff59e 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -76,15 +76,15 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable } if (evt.keyval == Gdk.Key.Return) { - char ul_marker; + 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 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; @@ -174,12 +174,15 @@ 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 stripped_line = line.strip (); + if ((stripped_line[0] == '*' || stripped_line[0] == '-') && stripped_line[1] == ' ') { + var ul_marker_index = line.index_of_char (stripped_line[0]); + ul_marker = "%s%c ".printf (string.nfill (ul_marker_index, ' '), stripped_line[0]); return true; } - ul_marker = '\0'; + + ul_marker = ""; return false; } From a46686fe645f869d5cc4e211d201a23b93547c73 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Tue, 15 Oct 2024 15:44:26 +0100 Subject: [PATCH 2/2] Fix deleting empty unordered list items --- plugins/markdown-actions/markdown-actions.vala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 8ce84ff59e..36bc50d5de 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -76,12 +76,16 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable } if (evt.keyval == Gdk.Key.Return) { + 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.strip ().length <= 3) { // empty item + if (line.strip ().length <= 3) { // empty list item delete_empty_item (); } else { string to_insert = "\n%s".printf (ul_marker); @@ -175,10 +179,11 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable } private bool parse_unordered_list_item (string line, out string ul_marker) { - var stripped_line = line.strip (); - if ((stripped_line[0] == '*' || stripped_line[0] == '-') && stripped_line[1] == ' ') { - var ul_marker_index = line.index_of_char (stripped_line[0]); - ul_marker = "%s%c ".printf (string.nfill (ul_marker_index, ' '), stripped_line[0]); + 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; }