diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-08-01 13:31:57 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-08-01 13:31:57 +0300 |
commit | 433eb3f35d5cf3933801027e33399923609c6539 (patch) | |
tree | bf1eecf7af214c1b2dc6b78c951eb3457ee41e7b /source/blender/blenkernel | |
parent | 3a47fbfac520f6a9c0aaef19e351a1a00cb83af5 (diff) |
Text: toggle comment operator
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 17 |
2 files changed, 12 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 6509788932c..f018e912945 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -90,10 +90,10 @@ void txt_backspace_word(struct Text *text); bool txt_add_char(struct Text *text, unsigned int add); bool txt_add_raw_char(struct Text *text, unsigned int add); bool txt_replace_char(struct Text *text, unsigned int add); -void txt_unindent(struct Text *text); +bool txt_unindent(struct Text *text); void txt_comment(struct Text *text); void txt_indent(struct Text *text); -void txt_uncomment(struct Text *text); +bool txt_uncomment(struct Text *text); void txt_move_lines(struct Text *text, const int direction); void txt_duplicate_line(struct Text *text); int txt_setcurr_tab_spaces(struct Text *text, int space); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 056229ceb1c..29aa3ca1659 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2045,11 +2045,12 @@ static void txt_select_prefix(Text *text, const char *add) * * \note caller must handle undo. */ -static void txt_select_unprefix(Text *text, const char *remove) +static bool txt_select_unprefix(Text *text, const char *remove) { int num = 0; const int indentlen = strlen(remove); bool unindented_first = false; + bool changed_any = false; BLI_assert(!ELEM(NULL, text->curl, text->sell)); @@ -2062,6 +2063,7 @@ static void txt_select_unprefix(Text *text, const char *remove) text->curl->len -= indentlen; memmove(text->curl->line, text->curl->line + indentlen, text->curl->len + 1); changed = true; + changed_any = true; } txt_make_dirty(text); @@ -2089,6 +2091,7 @@ static void txt_select_unprefix(Text *text, const char *remove) } /* caller must handle undo */ + return changed_any; } void txt_comment(Text *text) @@ -2102,15 +2105,15 @@ void txt_comment(Text *text) txt_select_prefix(text, prefix); } -void txt_uncomment(Text *text) +bool txt_uncomment(Text *text) { const char *prefix = "#"; if (ELEM(NULL, text->curl, text->sell)) { - return; + return false; } - txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix); } void txt_indent(Text *text) @@ -2124,15 +2127,15 @@ void txt_indent(Text *text) txt_select_prefix(text, prefix); } -void txt_unindent(Text *text) +bool txt_unindent(Text *text) { const char *prefix = (text->flags & TXT_TABSTOSPACES) ? tab_to_spaces : "\t"; if (ELEM(NULL, text->curl, text->sell)) { - return; + return false; } - txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix); } void txt_move_lines(struct Text *text, const int direction) |