From 09e1c2eb8b5911775ba21dff9e655cdcef2a31a1 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Tue, 28 Jan 2020 15:43:47 +0100 Subject: [PATCH] [escher/text_input] insertTextAtLocation location parameter not const anymore --- escher/include/escher/text_area.h | 2 +- escher/include/escher/text_field.h | 2 +- escher/include/escher/text_input.h | 4 ++-- escher/src/text_area.cpp | 6 +++--- escher/src/text_field.cpp | 10 +++++----- escher/src/text_input.cpp | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/escher/include/escher/text_area.h b/escher/include/escher/text_area.h index c7f131a16..a0fe9399c 100644 --- a/escher/include/escher/text_area.h +++ b/escher/include/escher/text_area.h @@ -115,7 +115,7 @@ protected: const char * editedText() const override { return m_text.text(); } size_t editedTextLength() const override { return m_text.textLength(); } const Text * getText() const { return &m_text; } - bool insertTextAtLocation(const char * text, const char * location) override; + bool insertTextAtLocation(const char * text, char * location) override; void moveCursorGeo(int deltaX, int deltaY); bool removePreviousGlyph() override; bool removeEndOfLine() override; diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index 92c05a2fd..a61e2e0d9 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -57,7 +57,7 @@ protected: /* If the text to be appended is too long to be added without overflowing the * buffer, nothing is done (not even adding few letters from the text to reach * the maximum buffer capacity) and false is returned. */ - bool insertTextAtLocation(const char * text, const char * location) override; + bool insertTextAtLocation(const char * text, char * location) override; KDSize minimalSizeForOptimalDisplay() const override; bool removePreviousGlyph() override; bool removeEndOfLine() override; diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index 9e31eff6f..fd961cd71 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -47,7 +47,7 @@ protected: // Virtual text get/add/remove virtual const char * text() const = 0; - virtual bool insertTextAtLocation(const char * text, const char * location) = 0; + virtual bool insertTextAtLocation(const char * text, char * location) = 0; virtual bool removePreviousGlyph() = 0; virtual bool removeEndOfLine() = 0; @@ -90,7 +90,7 @@ protected: /* If the text to be appended is too long to be added without overflowing the * buffer, nothing is done (not even adding few letters from the text to reach * the maximum buffer capacity) and false is returned. */ - bool insertTextAtLocation(const char * textBuffer, const char * location); + bool insertTextAtLocation(const char * textBuffer, char * location); bool removeEndOfLine(); ContentView * contentView() { return const_cast(nonEditableContentView()); diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index e90a3320e..57e033d63 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -458,7 +458,7 @@ void TextArea::ContentView::setText(char * textBuffer, size_t textBufferSize) { m_cursorLocation = text(); } -bool TextArea::ContentView::insertTextAtLocation(const char * text, const char * location) { +bool TextArea::ContentView::insertTextAtLocation(const char * text, char * location) { int textSize = strlen(text); if (m_text.textLength() + textSize >= m_text.bufferSize() || textSize == 0) { return false; @@ -475,9 +475,9 @@ bool TextArea::ContentView::insertTextAtLocation(const char * text, const char * &lineBreak, 0); assert(UTF8Helper::CodePointIs(nullLocation, 0)); - m_text.insertText(text, nullLocation - text, const_cast(location)); + m_text.insertText(text, nullLocation - text, location); // Replace System parentheses (used to keep layout tree structure) by normal parentheses - Poincare::SerializationHelper::ReplaceSystemParenthesesByUserParentheses(const_cast(location), nullLocation - text); + Poincare::SerializationHelper::ReplaceSystemParenthesesByUserParentheses(location, nullLocation - text); reloadRectFromPosition(location, lineBreak); return true; } diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index a3bfe4a2d..842d784cc 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -113,7 +113,7 @@ void TextField::ContentView::reinitDraftTextBuffer() { setCursorLocation(s_draftTextBuffer); } -bool TextField::ContentView::insertTextAtLocation(const char * text, const char * location) { +bool TextField::ContentView::insertTextAtLocation(const char * text, char * location) { assert(m_isEditing); int textLength = strlen(text); @@ -121,12 +121,12 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, const char return false; } - memmove(const_cast(location + textLength), location, (s_draftTextBuffer + m_currentDraftTextLength + 1) - location); + memmove(location + textLength, location, (s_draftTextBuffer + m_currentDraftTextLength + 1) - location); // Caution! One byte will be overridden by the null-terminating char of strlcpy - char * overridenByteLocation = const_cast(location + strlen(text)); + char * overridenByteLocation = location + textLength; char overridenByte = *overridenByteLocation; - strlcpy(const_cast(location), text, (s_draftTextBuffer + m_draftTextBufferSize) - location); + strlcpy(location, text, (s_draftTextBuffer + m_draftTextBufferSize) - location); assert(overridenByteLocation < s_draftTextBuffer + m_draftTextBufferSize); *overridenByteLocation = overridenByte; m_currentDraftTextLength += textLength; @@ -512,7 +512,7 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo Poincare::SerializationHelper::ReplaceSystemParenthesesByUserParentheses(buffer); const char * nextCursorLocation = m_contentView.editedText() + draftTextLength(); - if (insertTextAtLocation(buffer, cursorLocation())) { + if (insertTextAtLocation(buffer, const_cast(cursorLocation()))) { /* The cursor position depends on the text as we sometimes want to position * the cursor at the end of the text and sometimes after the first * parenthesis. */ diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index 0bb05749e..0bc583bc7 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -170,7 +170,7 @@ void TextInput::setAlignment(float horizontalAlignment, float verticalAlignment) contentView()->setAlignment(horizontalAlignment, verticalAlignment); } -bool TextInput::insertTextAtLocation(const char * text, const char * location) { +bool TextInput::insertTextAtLocation(const char * text, char * location) { if (contentView()->insertTextAtLocation(text, location)) { /* We layout the scrollable view before scrolling to cursor because the * content size might have changed. */