From f7a6e615ca1e0f38b6c5786f706bcd8e51bb9386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 21 Nov 2017 10:25:11 +0100 Subject: [PATCH] [code] The cursor in a toolbox command does not go before a point. The cursor now goes either after the first open parenthesis or at the end of the command. Fixed z.real and z.imag. Change-Id: I46ca3be0415832fd91273ca7fed12ed3d6f125dc --- apps/code/catalog.universal.i18n | 2 ++ apps/code/toolbox.cpp | 6 +++--- apps/shared/toolbox_helpers.cpp | 7 +------ apps/shared/toolbox_helpers.h | 6 ++---- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index f8f0b2029..1b778d08a 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -77,3 +77,5 @@ PythonCommandTanh = "tanh(x)" PythonCommandTrunc = "trunc(x)" PythonCommandImag = "z.imag" PythonCommandReal = "z.real" +PythonCommandImagWithoutArg = "().imag" +PythonCommandRealWithoutArg = "().real" diff --git a/apps/code/toolbox.cpp b/apps/code/toolbox.cpp index ef707ccdb..9ba72d9f2 100644 --- a/apps/code/toolbox.cpp +++ b/apps/code/toolbox.cpp @@ -125,8 +125,6 @@ const ToolboxMessageTree catalogChildren[catalogChildrenCount] = { ToolboxMessageTree(I18n::Message::PythonCommandAmpersand, I18n::Message::PythonAmpersand, I18n::Message::PythonCommandAmpersand), ToolboxMessageTree(I18n::Message::PythonCommandSymbolExp, I18n::Message::PythonSymbolExp, I18n::Message::PythonCommandSymbolExp), ToolboxMessageTree(I18n::Message::PythonCommandVerticalBar, I18n::Message::PythonVerticalBar, I18n::Message::PythonCommandVerticalBar), - ToolboxMessageTree(I18n::Message::PythonCommandImag, I18n::Message::PythonImag, I18n::Message::PythonCommandImag), - ToolboxMessageTree(I18n::Message::PythonCommandReal, I18n::Message::PythonReal, I18n::Message::PythonCommandReal), ToolboxMessageTree(I18n::Message::PythonCommandAbs, I18n::Message::PythonAbs, I18n::Message::PythonCommandAbs), ToolboxMessageTree(I18n::Message::PythonCommandAcos, I18n::Message::PythonAcos, I18n::Message::PythonCommandAcos), ToolboxMessageTree(I18n::Message::PythonCommandAcosh, I18n::Message::PythonAcosh, I18n::Message::PythonCommandAcosh), @@ -190,7 +188,9 @@ const ToolboxMessageTree catalogChildren[catalogChildrenCount] = { ToolboxMessageTree(I18n::Message::PythonCommandSum, I18n::Message::PythonSum, I18n::Message::PythonCommandSum), ToolboxMessageTree(I18n::Message::PythonCommandTan, I18n::Message::PythonTan, I18n::Message::PythonCommandTan), ToolboxMessageTree(I18n::Message::PythonCommandTanh, I18n::Message::PythonTanh, I18n::Message::PythonCommandTanh), - ToolboxMessageTree(I18n::Message::PythonCommandTrunc, I18n::Message::PythonTrunc, I18n::Message::PythonCommandTrunc)}; + ToolboxMessageTree(I18n::Message::PythonCommandTrunc, I18n::Message::PythonTrunc, I18n::Message::PythonCommandTrunc), + ToolboxMessageTree(I18n::Message::PythonCommandImag, I18n::Message::PythonImag, I18n::Message::PythonCommandImagWithoutArg), + ToolboxMessageTree(I18n::Message::PythonCommandReal, I18n::Message::PythonReal, I18n::Message::PythonCommandRealWithoutArg)}; const ToolboxMessageTree functionsChildren[functionsChildrenCount] = { ToolboxMessageTree(I18n::Message::PythonCommandDefWithArg, I18n::Message::Default, I18n::Message::PythonCommandDef), diff --git a/apps/shared/toolbox_helpers.cpp b/apps/shared/toolbox_helpers.cpp index af03fc875..ebe83c69d 100644 --- a/apps/shared/toolbox_helpers.cpp +++ b/apps/shared/toolbox_helpers.cpp @@ -8,8 +8,6 @@ int CursorIndexInCommand(const char * text) { for (size_t i = 0; i < strlen(text); i++) { if (text[i] == '(') { return i + 1; - } else if (text[i] == '.') { - return i; } } return strlen(text); @@ -20,10 +18,7 @@ void TextToInsertForCommandMessage(I18n::Message message, char * buffer) { int currentNewTextIndex = 0; int numberOfOpenBrackets = 0; for (size_t i = 0; i < strlen(messageText); i++) { - if (messageText[i] == '.') { - currentNewTextIndex = 0; - numberOfOpenBrackets = 0; - } else if (messageText[i] == ')') { + if (messageText[i] == ')') { numberOfOpenBrackets--; } if (numberOfOpenBrackets == 0 || messageText[i] == ',') diff --git a/apps/shared/toolbox_helpers.h b/apps/shared/toolbox_helpers.h index 505357200..23b75a983 100644 --- a/apps/shared/toolbox_helpers.h +++ b/apps/shared/toolbox_helpers.h @@ -10,14 +10,12 @@ int CursorIndexInCommand(const char * text); /* Returns the index of the cursor position in a Command, which is the smallest * index between : * - After the first open parenthesis - * - Before the first point * - The end of the text */ void TextToInsertForCommandMessage(I18n::Message message, char * buffer); -/* Removes the arguments from a command message in two ways: - * - Removes text between parentheses, except commas - * - Removes text before a point */ +/* Removes the arguments from a command message: + * - Removes text between parentheses, except commas */ } }