From 99f6d73e1981ecd195fcebc695b0e0a18d33b5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 16 May 2018 11:44:48 +0200 Subject: [PATCH] [apps/code] Put cursor inside parentheses when inserting function In Code::VariableBoxController. Change-Id: Ib129781d46159c017bcb02e97c6667b6084f5b67 --- apps/code/script_node_cell.cpp | 1 + apps/code/script_node_cell.h | 2 ++ apps/code/variable_box_controller.cpp | 4 ++-- escher/src/text_area.cpp | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/code/script_node_cell.cpp b/apps/code/script_node_cell.cpp index 771d83c36..3928955ba 100644 --- a/apps/code/script_node_cell.cpp +++ b/apps/code/script_node_cell.cpp @@ -5,6 +5,7 @@ namespace Code { constexpr char ScriptNodeCell::k_parentheses[]; +constexpr char ScriptNodeCell::k_parenthesesWithEmpty[]; ScriptNodeCell::ScriptNodeView::ScriptNodeView() : HighlightCell(), diff --git a/apps/code/script_node_cell.h b/apps/code/script_node_cell.h index 78053ea84..4cc32f9ea 100644 --- a/apps/code/script_node_cell.h +++ b/apps/code/script_node_cell.h @@ -4,6 +4,7 @@ #include "script_node.h" #include "script_store.h" #include +#include #include namespace Code { @@ -22,6 +23,7 @@ public: void reloadCell() override; constexpr static char k_parentheses[] = "()"; + constexpr static char k_parenthesesWithEmpty[] = {'(', Ion::Charset::Empty, ')', 0}; protected: class ScriptNodeView : public HighlightCell { public: diff --git a/apps/code/variable_box_controller.cpp b/apps/code/variable_box_controller.cpp index b97b69d07..3b6ea4190 100644 --- a/apps/code/variable_box_controller.cpp +++ b/apps/code/variable_box_controller.cpp @@ -87,7 +87,7 @@ bool VariableBoxController::ContentViewController::handleEvent(Ion::Events::Even ScriptNode selectedScriptNode = m_scriptNodes[m_selectableTableView.selectedRow()]; insertTextInCaller(selectedScriptNode.name()); if (selectedScriptNode.type() == ScriptNode::Type::Function) { - insertTextInCaller(ScriptNodeCell::k_parentheses); + insertTextInCaller(ScriptNodeCell::k_parenthesesWithEmpty); } m_selectableTableView.deselectTable(); app()->dismissModalViewController(); @@ -117,7 +117,7 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl void VariableBoxController::ContentViewController::insertTextInCaller(const char * text) { int commandBufferMaxSize = strlen(text)+1; char commandBuffer[commandBufferMaxSize]; - Shared::ToolboxHelpers::TextToInsertForCommandText(text, commandBuffer, commandBufferMaxSize); + Shared::ToolboxHelpers::TextToInsertForCommandText(text, commandBuffer, commandBufferMaxSize, true); m_textInputCaller->handleEventWithText(commandBuffer); } diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 016e3e5a3..afb3f773a 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -304,6 +304,8 @@ bool TextArea::handleEventWithText(const char * text, bool indentation) { for (size_t i = bufferIndex; i < eventTextSize; i++) { if (text[i] != Ion::Charset::Empty) { buffer[bufferIndex++] = text[i]; + } else if (i < cursorIndexInCommand) { + cursorIndexInCommand--; } }