From de681705e62bc9b0fd5bec900ec0b02bed4d68a2 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 8 Jul 2020 11:23:51 +0200 Subject: [PATCH] [escher/expression_field] Renamed dumpLayout Changed dumpLayout's name to moveCursorAndDumpContent, as the name suggested the method was only usable on layouts (while it also works on text). The method is also no longer marked const, and the previous name could imply that it had no side effects. Likewise, renamed restoreLayout to restoreContent. Change-Id: I46b320e74c07b48e256dc2146f9ecc15af38a8e6 --- .../edit_expression_controller.cpp | 4 ++-- escher/include/escher/expression_field.h | 4 ++-- escher/src/expression_field.cpp | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index e72762f7f..750038907 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -56,13 +56,13 @@ void EditExpressionController::insertTextBody(const char * text) { void EditExpressionController::didBecomeFirstResponder() { m_contentView.mainView()->scrollToBottom(); m_contentView.expressionField()->setEditing(true, false); - m_contentView.expressionField()->restoreLayout(m_cacheBuffer, *m_cacheBufferInformation); + m_contentView.expressionField()->restoreContent(m_cacheBuffer, *m_cacheBufferInformation); clearCacheBuffer(); Container::activeApp()->setFirstResponder(m_contentView.expressionField()); } void EditExpressionController::willExitResponderChain(Responder * nextFirstResponder) { - *m_cacheBufferInformation = m_contentView.expressionField()->dumpLayout(m_cacheBuffer, k_cacheBufferSize); + *m_cacheBufferInformation = m_contentView.expressionField()->moveCursorAndDumpContent(m_cacheBuffer, k_cacheBufferSize); ::ViewController::willExitResponderChain(nextFirstResponder); } diff --git a/escher/include/escher/expression_field.h b/escher/include/escher/expression_field.h index f0931d5db..7ecaf57d4 100644 --- a/escher/include/escher/expression_field.h +++ b/escher/include/escher/expression_field.h @@ -26,8 +26,8 @@ public: bool inputViewHeightDidChange(); bool handleEventWithText(const char * text, bool indentation = false, bool forceCursorRightOfText = false); void setLayoutInsertionCursorEvent(Ion::Events::Event event) { m_layoutField.setInsertionCursorEvent(event); } - size_t dumpLayout(char * buffer, size_t bufferSize); - void restoreLayout(const char * buffer, size_t size); + size_t moveCursorAndDumpContent(char * buffer, size_t bufferSize); + void restoreContent(const char * buffer, size_t size); /* View */ int numberOfSubviews() const override { return 1; } diff --git a/escher/src/expression_field.cpp b/escher/src/expression_field.cpp index 723d89543..ad75892c7 100644 --- a/escher/src/expression_field.cpp +++ b/escher/src/expression_field.cpp @@ -122,13 +122,14 @@ KDCoordinate ExpressionField::inputViewHeight() const { std::max(k_minimalHeight, m_layoutField.minimalSizeForOptimalDisplay().height()))); } -size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) { +size_t ExpressionField::moveCursorAndDumpContent(char * buffer, size_t bufferSize) { size_t size; size_t returnValue; - char * currentLayout; + char * currentContent; if (editionIsInTextField()) { size = strlen(m_textField.draftTextBuffer()) + 1; - currentLayout = m_textField.draftTextBuffer(); + m_textField.setCursorLocation(m_textField.cursorLocation() + size - 1); + currentContent = m_textField.draftTextBuffer(); /* We take advantage of the fact that draftTextBuffer is null terminated to * use a size of 0 as a shorthand for "The buffer contains raw text instead * of layouts", since the size of a layout is at least 32 (the size of an @@ -136,9 +137,9 @@ size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) { * has changed and invalidate the data.*/ returnValue = 0; } else { - /* dumpLayout will be called whenever Calculation exits, event when an - * exception occurs. We thus need to check the validity of the layout we - * are dumping (m_layoutField.m_contentView.m_expressionView.m_layout). + /* moveCursorAndDumpContent will be called whenever Calculation exits, + * even when an exception occurs. We thus need to check the validity of the + * layout we are dumping (m_layoutField.contentView.expressionView.layout). * However, attempting to get a handle on a layout that has been erased * will crash the program. We need the check to be performed on the * original object in expressionView. */ @@ -148,18 +149,18 @@ size_t ExpressionField::dumpLayout(char * buffer, size_t bufferSize) { } m_layoutField.putCursorRightOfLayout(); size = m_layoutField.layout().size(); - currentLayout = reinterpret_cast(m_layoutField.layout().node()); + currentContent = reinterpret_cast(m_layoutField.layout().node()); returnValue = size; } if (size > bufferSize - 1) { buffer[0] = 0; return 0; } - memcpy(buffer, currentLayout, size); + memcpy(buffer, currentContent, size); return returnValue; } -void ExpressionField::restoreLayout(const char * buffer, size_t size) { +void ExpressionField::restoreContent(const char * buffer, size_t size) { if (editionIsInTextField()) { if (size != 0 || buffer[0] == 0) { /* A size other than 0 means the buffer contains Layout information