Fix #104894: Toggle comments assumes '#' prefix (failing for OSL)
Add comment line prefix to format struct so each language can define it's own comment prefix. Ref !104953.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user