From 3fe6af281fa54c768f764e8aeb29b9805d92b79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 27 Apr 2020 14:13:16 +0200 Subject: [PATCH] [apps/code] Fix variable box that crashed --- apps/code/python_text_area.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/apps/code/python_text_area.cpp b/apps/code/python_text_area.cpp index 5934d0e50..6c39de566 100644 --- a/apps/code/python_text_area.cpp +++ b/apps/code/python_text_area.cpp @@ -80,28 +80,25 @@ PythonTextArea::AutocompletionType PythonTextArea::autocompletionType(const char if (location < tokenStart) { // The location for autocompletion is not in an identifier + assert(autocompleteType == AutocompletionType::NoIdentifier); break; } - if (currentTokenKind == MP_TOKEN_NAME - || (currentTokenKind >= MP_TOKEN_KW_FALSE - && currentTokenKind <= MP_TOKEN_KW_YIELD)) - { - if (location < tokenEnd) { - if (autocompleteType != AutocompletionType::EndOfIdentifier) { - // The location for autocompletion is in the middle of an identifier - autocompleteType = AutocompletionType::MiddleOfIdentifier; - } - break; - } - if (location == tokenEnd) { - // The location for autocompletion is at the end of an identifier + if (location <= tokenEnd) { + if (currentTokenKind == MP_TOKEN_NAME + || (currentTokenKind >= MP_TOKEN_KW_FALSE + && currentTokenKind <= MP_TOKEN_KW_YIELD)) + { + /* The location for autocompletion is in the middle or at the end of + * an identifier. */ beginningOfToken = tokenStart; - autocompleteType = AutocompletionType::EndOfIdentifier; - break; + /* If autocompleteType is already EndOfIdentifier, we are + * autocompleting, so we do not need to update autocompleteType. If we + * recomputed autocompleteType now, we might wrongly think that it is + * MiddleOfIdentifier because of the autocompetion text. */ + if (autocompleteType != AutocompletionType::EndOfIdentifier) { + autocompleteType = location < tokenEnd ? AutocompletionType::MiddleOfIdentifier : AutocompletionType::EndOfIdentifier; + } } - } - if (location < tokenStart) { - // The location for autocompletion is not in an identifier break; } mp_lexer_to_next(lex);