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-11 13:50:02 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-08-11 13:52:45 +0300
commitc3a9fc5efb4a81f6efb28d0c787e17503deaee46 (patch)
treeb4962e940b58d6d8bdd96886346563321f32277d
parente2c6cfec184336e6820e805c232a19ffb5f8bfd9 (diff)
Text: support comment without selection
D5451 by @Poulpator with fixes.
-rw-r--r--source/blender/blenkernel/intern/text.c17
-rw-r--r--source/blender/editors/space_text/text_ops.c42
2 files changed, 31 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 1a3e42a7da2..83be64e84c9 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -1931,7 +1931,7 @@ bool txt_replace_char(Text *text, unsigned int add)
*
* \note caller must handle undo.
*/
-static void txt_select_prefix(Text *text, const char *add)
+static void txt_select_prefix(Text *text, const char *add, bool skip_blank_lines)
{
int len, num, curc_old, selc_old;
char *tmp;
@@ -1947,7 +1947,7 @@ static void txt_select_prefix(Text *text, const char *add)
while (true) {
/* don't indent blank lines */
- if (text->curl->len != 0) {
+ if ((text->curl->len != 0) || (skip_blank_lines == 0)) {
tmp = MEM_mallocN(text->curl->len + indentlen + 1, "textline_string");
text->curc = 0;
@@ -1971,7 +1971,9 @@ static void txt_select_prefix(Text *text, const char *add)
}
if (text->curl == text->sell) {
- text->selc += indentlen;
+ if (text->curl->len != 0) {
+ text->selc += indentlen;
+ }
break;
}
else {
@@ -1995,7 +1997,9 @@ static void txt_select_prefix(Text *text, const char *add)
text->curc = 0;
}
else {
- text->curc = curc_old + indentlen;
+ if (text->curl->len != 0) {
+ text->curc = curc_old + indentlen;
+ }
}
}
@@ -2089,7 +2093,8 @@ void txt_comment(Text *text)
return;
}
- txt_select_prefix(text, prefix);
+ const bool skip_blank_lines = txt_has_sel(text);
+ txt_select_prefix(text, prefix, skip_blank_lines);
}
bool txt_uncomment(Text *text)
@@ -2111,7 +2116,7 @@ void txt_indent(Text *text)
return;
}
- txt_select_prefix(text, prefix);
+ txt_select_prefix(text, prefix, true);
}
bool txt_unindent(Text *text)
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index a8af9c73bf2..e1550deb659 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1217,36 +1217,34 @@ static int text_comment_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
int type = RNA_enum_get(op->ptr, "type");
- if (txt_has_sel(text)) {
- text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+ text_drawcache_tag_update(CTX_wm_space_text(C), 0);
- ED_text_undo_push_init(C);
+ ED_text_undo_push_init(C);
+ if (txt_has_sel(text)) {
txt_order_cursors(text, false);
+ }
- switch (type) {
- case 1:
+ switch (type) {
+ case 1:
+ txt_comment(text);
+ break;
+ case -1:
+ txt_uncomment(text);
+ break;
+ default:
+ if (txt_uncomment(text) == false) {
txt_comment(text);
- break;
- case -1:
- txt_uncomment(text);
- break;
- default:
- if (txt_uncomment(text) == false) {
- txt_comment(text);
- }
- break;
- }
-
- text_update_edited(text);
+ }
+ break;
+ }
- text_update_cursor_moved(C);
- WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
+ text_update_edited(text);
- return OPERATOR_FINISHED;
- }
+ text_update_cursor_moved(C);
+ WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
- return OPERATOR_CANCELLED;
+ return OPERATOR_FINISHED;
}
void TEXT_OT_comment_toggle(wmOperatorType *ot)