From 05417b22206c479b5ebe8ac8e7dd73ae154c8c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 13 Aug 2019 15:35:48 +0200 Subject: 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 --- source/blender/editors/space_text/text_draw.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/space_text/text_draw.c') 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); } -- cgit v1.2.3