diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2019-08-13 16:35:48 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2019-08-14 17:59:37 +0300 |
commit | 05417b22206c479b5ebe8ac8e7dd73ae154c8c96 (patch) | |
tree | aa11344ee7e5fa0bf8c95ce380e347d11a3df16f /source/blender/editors/space_text/text_draw.c | |
parent | 72eb70f93328e4e19a319aa199f6c46a0c8ab420 (diff) |
Text editor: syntax highlighting + line numbers on by default
The most common use of the text editor seems to be for scripting. Having
line numbers and syntax highlighting enabled by default seems sensible.
Syntax highlighting is now enabled by default, but is automatically
disabled when the datablock has a non-highlighted extension.
Highlighting is enabled for filenames like:
- Text
- Text.001
- somefile.py
and is automatically disabled when the datablock has an extension for
which Blender has no syntax highlighter registered.
Reviewers: billreynish, campbellbarton
Subscribers: brecht, billreynish
Differential Revision: https://developer.blender.org/D5472
Diffstat (limited to 'source/blender/editors/space_text/text_draw.c')
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 9dc8dfa93b6..e99bf680077 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -54,6 +54,7 @@ typedef struct TextDrawContext { int font_id; int cwidth; int lheight_dpi; + bool syntax_highlight; } TextDrawContext; static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc) @@ -61,6 +62,7 @@ static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc) tdc->font_id = blf_mono_font; tdc->cwidth = 0; tdc->lheight_dpi = st->lheight_dpi; + tdc->syntax_highlight = st->showsyntax && ED_text_is_syntax_highlight_supported(st->text); } static void text_font_begin(const TextDrawContext *tdc) @@ -418,7 +420,7 @@ static int text_draw_wrapped(const SpaceText *st, const char *format, int skip) { - const bool use_syntax = (st->showsyntax && format); + const bool use_syntax = (tdc->syntax_highlight && format); FlattenString fs; int basex, lines; int i, wrap, end, max, columns, padding; /* column */ @@ -514,7 +516,7 @@ static void text_draw(const SpaceText *st, int y, const char *format) { - const bool use_syntax = (st->showsyntax && format); + const bool use_syntax = (tdc->syntax_highlight && format); FlattenString fs; int columns, size, n, w = 0, padding, amount = 0; const char *in = NULL; @@ -1383,8 +1385,8 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi char ch; - // showsyntax must be on or else the format string will be null - if (!text->curl || !st->showsyntax) { + // syntax_highlight must be on or else the format string will be null + if (!text->curl || !tdc->syntax_highlight) { return; } @@ -1576,7 +1578,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) tmp = text->lines.first; lineno = 0; for (i = 0; i < st->top && tmp; i++) { - if (st->showsyntax && !tmp->format) { + if (tdc.syntax_highlight && !tmp->format) { tft->format_line(st, tmp, false); } @@ -1631,7 +1633,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) UI_FontThemeColor(tdc.font_id, TH_TEXT); for (i = 0; y > clip_min_y && i < st->viewlines && tmp; i++, tmp = tmp->next) { - if (st->showsyntax && !tmp->format) { + if (tdc.syntax_highlight && !tmp->format) { tft->format_line(st, tmp, false); } |