diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index edac64879e0..d85a3214dc7 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -103,9 +103,9 @@ 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); bool txt_unindent(struct Text *text); -void txt_comment(struct Text *text); void txt_indent(struct Text *text); -bool txt_uncomment(struct Text *text); +void txt_comment(struct Text *text, const char *prefix); +bool txt_uncomment(struct Text *text, const char *prefix); void txt_move_lines(struct Text *text, 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 9b2f9c72c90..59f1745b035 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2124,10 +2124,8 @@ static bool txt_select_unprefix(Text *text, const char *remove, const bool requi return changed_any; } -void txt_comment(Text *text) +void txt_comment(Text *text, const char *prefix) { - const char *prefix = "#"; - if (ELEM(NULL, text->curl, text->sell)) { return; } @@ -2136,10 +2134,8 @@ void txt_comment(Text *text) txt_select_prefix(text, prefix, skip_blank_lines); } -bool txt_uncomment(Text *text) +bool txt_uncomment(Text *text, const char *prefix) { - const char *prefix = "#"; - if (ELEM(NULL, text->curl, text->sell)) { return false; } diff --git a/source/blender/editors/include/ED_text.h b/source/blender/editors/include/ED_text.h index 5b79f938bdf..8b45e414d90 100644 --- a/source/blender/editors/include/ED_text.h +++ b/source/blender/editors/include/ED_text.h @@ -43,6 +43,8 @@ struct UndoStep *ED_text_undo_push_init(struct bContext *C); /* text_format.c */ +const char *ED_text_format_comment_line_prefix(struct Text *text); + bool ED_text_is_syntax_highlight_supported(struct Text *text); #ifdef __cplusplus diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c index 00186cca51c..2baeff4e0ac 100644 --- a/source/blender/editors/space_text/text_format.c +++ b/source/blender/editors/space_text/text_format.c @@ -199,6 +199,12 @@ TextFormatType *ED_text_format_get(Text *text) return tft_lb.first; } +const char *ED_text_format_comment_line_prefix(Text *text) +{ + const struct TextFormatType *format = ED_text_format_get(text); + return format->comment_line; +} + bool ED_text_is_syntax_highlight_supported(Text *text) { if (text == NULL) { diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h index 00a2f9ad37a..eac83b12cc7 100644 --- a/source/blender/editors/space_text/text_format.h +++ b/source/blender/editors/space_text/text_format.h @@ -75,6 +75,9 @@ typedef struct TextFormatType { void (*format_line)(SpaceText *st, TextLine *line, bool do_next); const char **ext; /* NULL terminated extensions */ + + /** The prefix of a single-line line comment (without trailing space). */ + const char *comment_line; } TextFormatType; enum { diff --git a/source/blender/editors/space_text/text_format_lua.c b/source/blender/editors/space_text/text_format_lua.c index 4b3ee1c15c7..f2dff82306d 100644 --- a/source/blender/editors/space_text/text_format_lua.c +++ b/source/blender/editors/space_text/text_format_lua.c @@ -341,6 +341,7 @@ void ED_text_format_register_lua(void) tft.format_identifier = txtfmt_lua_format_identifier; tft.format_line = txtfmt_lua_format_line; tft.ext = ext; + tft.comment_line = "--"; ED_text_format_register(&tft); } diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c index 575eadeee66..fa041697f01 100644 --- a/source/blender/editors/space_text/text_format_osl.c +++ b/source/blender/editors/space_text/text_format_osl.c @@ -359,6 +359,7 @@ void ED_text_format_register_osl(void) tft.format_identifier = txtfmt_osl_format_identifier; tft.format_line = txtfmt_osl_format_line; tft.ext = ext; + tft.comment_line = "//"; ED_text_format_register(&tft); } diff --git a/source/blender/editors/space_text/text_format_pov.c b/source/blender/editors/space_text/text_format_pov.c index 7c2c4829ad3..746e939752b 100644 --- a/source/blender/editors/space_text/text_format_pov.c +++ b/source/blender/editors/space_text/text_format_pov.c @@ -936,6 +936,7 @@ void ED_text_format_register_pov(void) tft.format_identifier = txtfmt_pov_format_identifier; tft.format_line = txtfmt_pov_format_line; tft.ext = ext; + tft.comment_line = "//"; ED_text_format_register(&tft); } diff --git a/source/blender/editors/space_text/text_format_pov_ini.c b/source/blender/editors/space_text/text_format_pov_ini.c index dda3b7089fe..60e37700efe 100644 --- a/source/blender/editors/space_text/text_format_pov_ini.c +++ b/source/blender/editors/space_text/text_format_pov_ini.c @@ -512,6 +512,7 @@ void ED_text_format_register_pov_ini(void) tft.format_identifier = txtfmt_pov_ini_format_identifier; tft.format_line = txtfmt_pov_ini_format_line; tft.ext = ext; + tft.comment_line = "//"; ED_text_format_register(&tft); } diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index 6aff8c7b966..5827ab7c469 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -507,6 +507,7 @@ void ED_text_format_register_py(void) tft.format_identifier = txtfmt_py_format_identifier; tft.format_line = txtfmt_py_format_line; tft.ext = ext; + tft.comment_line = "#"; ED_text_format_register(&tft); } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 0ddd06ead62..b01ce34617a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1273,6 +1273,7 @@ static int text_comment_exec(bContext *C, wmOperator *op) { Text *text = CTX_data_edit_text(C); int type = RNA_enum_get(op->ptr, "type"); + const char *prefix = ED_text_format_comment_line_prefix(text); text_drawcache_tag_update(CTX_wm_space_text(C), 0); @@ -1284,14 +1285,14 @@ static int text_comment_exec(bContext *C, wmOperator *op) switch (type) { case 1: - txt_comment(text); + txt_comment(text, prefix); break; case -1: - txt_uncomment(text); + txt_uncomment(text, prefix); break; default: - if (txt_uncomment(text) == false) { - txt_comment(text); + if (txt_uncomment(text, prefix) == false) { + txt_comment(text, prefix); } break; }