Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-08-05 07:10:36 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-08-05 08:53:27 +0300
commit94dce826a9a7b77dd99fa7cd8d3b7147913ba591 (patch)
tree04d0fc9728b2661d972130a9cb275e0a41b089e7
parent91fa07dfb18f35783177db47d4c721e5a03aad43 (diff)
Text: only un-comment blocks which are completely commented
It's common to select a block of code and comment it which may already contains some comments. Now only un-comment blocks which are completely commented (ignoring white-space). Makes toggle comments behave more usefully, resolves T68060.
-rw-r--r--source/blender/blenkernel/intern/text.c31
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)