diff options
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 29aa3ca1659..b2ea5b12603 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2042,10 +2042,12 @@ static void txt_select_prefix(Text *text, const char *add) * * \param r_line_index_mask: List of lines that are already at indent level 0, * to store them later into the undo buffer. + * \param require_all: When true, all non-empty lines must have this prefix. + * Needed for comments where we might want to un-comment a block which contains some comments. * * \note caller must handle undo. */ -static bool txt_select_unprefix(Text *text, const char *remove) +static bool txt_select_unprefix(Text *text, const char *remove, const bool require_all) { int num = 0; const int indentlen = strlen(remove); @@ -2054,6 +2056,29 @@ static bool txt_select_unprefix(Text *text, const char *remove) BLI_assert(!ELEM(NULL, text->curl, text->sell)); + if (require_all) { + /* Check all non-empty lines use this 'remove', + * so the operation is applied equally or not at all. */ + TextLine *l = text->curl; + while (true) { + if (STREQLEN(l->line, remove, indentlen)) { + /* pass */ + } + else { + /* Blank lines or whitespace can be skipped. */ + for (int i = 0; i < l->len; i++) { + if (!ELEM(l->line[i], '\t', ' ')) { + return false; + } + } + } + if (l == text->sell) { + break; + } + l = l->next; + } + } + while (true) { bool changed = false; if (STREQLEN(text->curl->line, remove, indentlen)) { @@ -2113,7 +2138,7 @@ bool txt_uncomment(Text *text) return false; } - return txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix, true); } void txt_indent(Text *text) @@ -2135,7 +2160,7 @@ bool txt_unindent(Text *text) return false; } - return txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix, false); } void txt_move_lines(struct Text *text, const int direction) |