From 9d9efc985f5e6ad1c8e265649fc3cb7821f06f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 10 Oct 2019 15:09:43 +0200 Subject: [PATCH] [apps/python_text_area] Clean drawLine --- apps/code/python_text_area.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/code/python_text_area.cpp b/apps/code/python_text_area.cpp index 721383e5d..16ebf0ee7 100644 --- a/apps/code/python_text_area.cpp +++ b/apps/code/python_text_area.cpp @@ -94,18 +94,17 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char return; } + /* We're using the MicroPython lexer to do syntax highlighting on a per-line + * basis. This can work, however the MicroPython lexer won't accept a line + * starting with a whitespace. So we're discarding leading whitespaces + * beforehand. */ + const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' '); + if (UTF8Helper::CodePointIs(firstNonSpace, UCodePointNull)) { + return; + } + nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { - /* We're using the MicroPython lexer to do syntax highlighting on a per-line - * basis. This can work, however the MicroPython lexer won't accept a line - * starting with a whitespace. So we're discarding leading whitespaces - * beforehand. */ - const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' '); - if (UTF8Helper::CodePointIs(firstNonSpace, UCodePointNull)) { - nlr_pop(); - return; - } - mp_lexer_t * lex = mp_lexer_new_from_str_len(0, firstNonSpace, byteLength - (firstNonSpace - text), 0); LOG_DRAW("Pop token %d\n", lex->tok_kind);