From bd2ea41fbed1cb46d66649107b8e6c33a2372495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 23 Jan 2019 16:11:35 +0100 Subject: [PATCH] [apps/escher] Rename cursorTextLocation as cursorLocation --- apps/code/editor_controller.cpp | 6 +- apps/code/editor_view.h | 4 +- apps/code/menu_controller.cpp | 12 ++-- apps/probability/calculation_controller.cpp | 4 +- .../editable_cell_table_view_controller.cpp | 4 +- apps/shared/text_field_with_extension.cpp | 6 +- apps/shared/text_field_with_extension.h | 2 +- escher/include/escher/text_area.h | 2 +- escher/include/escher/text_input.h | 14 ++-- escher/src/text_area.cpp | 56 ++++++++-------- escher/src/text_field.cpp | 66 +++++++++---------- escher/src/text_input.cpp | 12 ++-- 12 files changed, 94 insertions(+), 94 deletions(-) diff --git a/apps/code/editor_controller.cpp b/apps/code/editor_controller.cpp index 9769f0e23..6bf45eca7 100644 --- a/apps/code/editor_controller.cpp +++ b/apps/code/editor_controller.cpp @@ -44,7 +44,7 @@ void EditorController::didBecomeFirstResponder() { void EditorController::viewWillAppear() { m_editorView.loadSyntaxHighlighter(); - m_editorView.setCursorTextLocation(m_editorView.text() + strlen(m_editorView.text())); + m_editorView.setCursorLocation(m_editorView.text() + strlen(m_editorView.text())); } void EditorController::viewDidDisappear() { @@ -70,7 +70,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events: /* If the cursor is on the left of the text of a line, backspace one * indentation space at a time. */ char * text = const_cast(textArea->text()); - const char * charBeforeCursorPointer = textArea->cursorTextLocation()-1; + const char * charBeforeCursorPointer = textArea->cursorLocation()-1; int indentationSize = 0; while (charBeforeCursorPointer >= text && *charBeforeCursorPointer == ' ') { charBeforeCursorPointer--; @@ -89,7 +89,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events: /* If the cursor is on the left of the text of a line, a space triggers an * indentation. */ char * text = const_cast(textArea->text()); - const char * charBeforeCursorPointer = textArea->cursorTextLocation()-1; + const char * charBeforeCursorPointer = textArea->cursorLocation()-1; while (charBeforeCursorPointer >= text && *charBeforeCursorPointer == ' ') { charBeforeCursorPointer--; } diff --git a/apps/code/editor_view.h b/apps/code/editor_view.h index 170fc9b54..7e4d85ece 100644 --- a/apps/code/editor_view.h +++ b/apps/code/editor_view.h @@ -16,8 +16,8 @@ public: void setText(char * textBuffer, size_t textBufferSize) { m_textArea.setText(textBuffer, textBufferSize); } - bool setCursorTextLocation(const char * location) { - return m_textArea.setCursorTextLocation(location); + bool setCursorLocation(const char * location) { + return m_textArea.setCursorLocation(location); } void loadSyntaxHighlighter() { m_textArea.loadSyntaxHighlighter(); }; void unloadSyntaxHighlighter() { m_textArea.unloadSyntaxHighlighter(); }; diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index 363cdce52..658874d2f 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -126,7 +126,7 @@ void MenuController::renameSelectedScript() { app()->setFirstResponder(myCell); myCell->setHighlighted(false); myCell->textField()->setEditing(true, false); - myCell->textField()->setCursorTextLocation(myCell->textField()->text() + strlen(myCell->textField()->text())); + myCell->textField()->setCursorLocation(myCell->textField()->text() + strlen(myCell->textField()->text())); } void MenuController::deleteScript(Script script) { @@ -285,7 +285,7 @@ bool MenuController::textFieldShouldFinishEditing(TextField * textField, Ion::Ev bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) { if (event == Ion::Events::Right && textField->isEditing() - && textField->cursorTextLocation() == textField->text() + textField->draftTextLength()) { + && textField->cursorLocation() == textField->text() + textField->draftTextLength()) { return true; } if (event == Ion::Events::Clear && textField->isEditing()) { @@ -294,7 +294,7 @@ bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events assert(k_bufferSize >= 1 + strlen(ScriptStore::k_scriptExtension) + 1); strlcpy(&buffer[1], ScriptStore::k_scriptExtension, strlen(ScriptStore::k_scriptExtension) + 1); textField->setText(buffer); - textField->setCursorTextLocation(textField->text()); + textField->setCursorLocation(textField->text()); return true; } return false; @@ -318,7 +318,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char * default name and let the user modify it. */ if (!foundDefaultName) { textField->setText(numberedDefaultName); - textField->setCursorTextLocation(textField->draftTextBuffer() + defaultNameLength); + textField->setCursorLocation(textField->draftTextBuffer() + defaultNameLength); } newName = const_cast(numberedDefaultName); } @@ -351,8 +351,8 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char bool MenuController::textFieldDidHandleEvent(TextField * textField, bool returnValue, bool textSizeDidChange) { int scriptExtensionLength = 1 + strlen(ScriptStore::k_scriptExtension); const char * maxPointerLocation = textField->text() + textField->draftTextLength() - scriptExtensionLength; - if (textField->isEditing() && textField->cursorTextLocation() > maxPointerLocation) { - textField->setCursorTextLocation(maxPointerLocation); + if (textField->isEditing() && textField->cursorLocation() > maxPointerLocation) { + textField->setCursorLocation(maxPointerLocation); } return returnValue; } diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index 90c509640..e517ef379 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -203,10 +203,10 @@ bool CalculationController::textFieldDidHandleEvent(::TextField * textField, boo bool CalculationController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) { return TextFieldDelegate::textFieldShouldFinishEditing(textField, event) || (event == Ion::Events::Right - && textField->cursorTextLocation() == textField->text() + textField->draftTextLength() + && textField->cursorLocation() == textField->text() + textField->draftTextLength() && selectedColumn() < m_calculation->numberOfParameters()) || (event == Ion::Events::Left - && textField->cursorTextLocation() == textField->text()); + && textField->cursorLocation() == textField->text()); } bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { diff --git a/apps/shared/editable_cell_table_view_controller.cpp b/apps/shared/editable_cell_table_view_controller.cpp index a6c411bd8..ba635fc6e 100644 --- a/apps/shared/editable_cell_table_view_controller.cpp +++ b/apps/shared/editable_cell_table_view_controller.cpp @@ -19,8 +19,8 @@ bool EditableCellTableViewController::textFieldShouldFinishEditing(TextField * t return TextFieldDelegate::textFieldShouldFinishEditing(textField, event) || (event == Ion::Events::Down && selectedRow() < numberOfRows()-1) || (event == Ion::Events::Up && selectedRow() > 0) - || (event == Ion::Events::Right && (textField->cursorTextLocation() == textField->draftTextBuffer() + textField->draftTextLength()) && selectedColumn() < numberOfColumns()-1) - || (event == Ion::Events::Left && textField->cursorTextLocation() == textField->draftTextBuffer() && selectedColumn() > 0); + || (event == Ion::Events::Right && (textField->cursorLocation() == textField->draftTextBuffer() + textField->draftTextLength()) && selectedColumn() < numberOfColumns()-1) + || (event == Ion::Events::Left && textField->cursorLocation() == textField->draftTextBuffer() && selectedColumn() > 0); } bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { diff --git a/apps/shared/text_field_with_extension.cpp b/apps/shared/text_field_with_extension.cpp index 5d74cb531..ac31f247b 100644 --- a/apps/shared/text_field_with_extension.cpp +++ b/apps/shared/text_field_with_extension.cpp @@ -2,7 +2,7 @@ namespace Shared { -void TextFieldWithExtension::willSetCursorTextLocation(const char * * location) { +void TextFieldWithExtension::willSetCursorLocation(const char * * location) { size_t textLength = strlen(text()); assert(textLength >= m_extensionLength); const char * maxLocation = m_contentView.draftTextBuffer() + (textLength - m_extensionLength); @@ -24,7 +24,7 @@ bool TextFieldWithExtension::removeTextBeforeExtension(bool whole) { assert(isEditing()); const char * extension = m_contentView.draftTextBuffer() + (strlen(text()) - m_extensionLength); assert(extension >= m_contentView.draftTextBuffer() && extension < m_contentView.draftTextBuffer() + (ContentView::k_maxBufferSize - m_extensionLength)); - char * destination = whole ? m_contentView.draftTextBuffer() : const_cast(cursorTextLocation()); + char * destination = whole ? m_contentView.draftTextBuffer() : const_cast(cursorLocation()); if (destination == extension) { return false; } @@ -32,7 +32,7 @@ bool TextFieldWithExtension::removeTextBeforeExtension(bool whole) { assert(destination < extension); m_contentView.willModifyTextBuffer(); strlcpy(destination, extension, ContentView::k_maxBufferSize - (destination - m_contentView.draftTextBuffer())); - m_contentView.setCursorTextLocation(destination); + m_contentView.setCursorLocation(destination); m_contentView.didModifyTextBuffer(); layoutSubviews(); return true; diff --git a/apps/shared/text_field_with_extension.h b/apps/shared/text_field_with_extension.h index fa2264be4..f4191b3f0 100644 --- a/apps/shared/text_field_with_extension.h +++ b/apps/shared/text_field_with_extension.h @@ -24,7 +24,7 @@ public: m_extensionLength(extensionLength) {} private: - void willSetCursorTextLocation(const char * * location) override; + void willSetCursorLocation(const char * * location) override; bool privateRemoveEndOfLine() override; void removeWholeText() override; bool removeTextBeforeExtension(bool whole); diff --git a/escher/include/escher/text_area.h b/escher/include/escher/text_area.h index b974ae9f9..0f9fa8b77 100644 --- a/escher/include/escher/text_area.h +++ b/escher/include/escher/text_area.h @@ -98,7 +98,7 @@ protected: TextInput::ContentView(font), m_text(nullptr, 0) { - m_cursorTextLocation = m_text.text(); + m_cursorLocation = m_text.text(); } void drawRect(KDContext * ctx, KDRect rect) const override; void drawStringAt(KDContext * ctx, int line, int column, const char * text, size_t length, KDColor textColor, KDColor backgroundColor) const; diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index 4406fba4d..24a8cdeb5 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -12,8 +12,8 @@ public: void setFont(const KDFont * font) { contentView()->setFont(font); } const char * text() const { return nonEditableContentView()->text(); } bool removeCodePoint(); - const char * cursorTextLocation() const { return nonEditableContentView()->cursorTextLocation(); } - bool setCursorTextLocation(const char * location); + const char * cursorLocation() const { return nonEditableContentView()->cursorLocation(); } + bool setCursorLocation(const char * location); virtual void scrollToCursor(); protected: class ContentView : public View { @@ -22,12 +22,12 @@ protected: View(), m_cursorView(), m_font(font), - m_cursorTextLocation(nullptr) + m_cursorLocation(nullptr) {} void setFont(const KDFont * font); const KDFont * font() const { return m_font; } - const char * cursorTextLocation() const { assert(m_cursorTextLocation != nullptr); return m_cursorTextLocation; } - void setCursorTextLocation(const char * cursorTextLocation); + const char * cursorLocation() const { assert(m_cursorLocation != nullptr); return m_cursorLocation; } + void setCursorLocation(const char * cursorLocation); virtual const char * text() const = 0; virtual bool insertTextAtLocation(const char * text, const char * location) = 0; virtual bool removeCodePoint() = 0; @@ -39,7 +39,7 @@ protected: virtual KDRect glyphFrameAtPosition(const char * position) const = 0; TextCursorView m_cursorView; const KDFont * m_font; - const char * m_cursorTextLocation; + const char * m_cursorLocation; virtual KDRect dirtyRectFromPosition(const char * position, bool lineBreak) const; private: int numberOfSubviews() const override { return 1; } @@ -61,7 +61,7 @@ protected: } virtual const ContentView * nonEditableContentView() const = 0; private: - virtual void willSetCursorTextLocation(const char * * location) {} + virtual void willSetCursorLocation(const char * * location) {} virtual bool privateRemoveEndOfLine(); }; diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 57f000dfb..d08d62535 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -21,7 +21,7 @@ TextArea::TextArea(Responder * parentResponder, View * contentView, const KDFont } bool TextArea::handleEventWithText(const char * text, bool indentation, bool forceCursorRightOfText) { - const char * nextCursorLocation = cursorTextLocation(); + const char * nextCursorLocation = cursorLocation(); const char * cursorPositionInCommand = TextInputHelpers::CursorPositionInCommand(text); @@ -32,7 +32,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, text, UCodePointEmpty, &cursorPositionInCommand); // Insert the text - if ((indentation && insertTextWithIndentation(buffer, cursorTextLocation())) || insertTextAtLocation(buffer, cursorTextLocation())) { + if ((indentation && insertTextWithIndentation(buffer, cursorLocation())) || insertTextAtLocation(buffer, cursorLocation())) { // Set the cursor location if (forceCursorRightOfText) { nextCursorLocation += strlen(buffer); @@ -40,7 +40,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for nextCursorLocation += cursorPositionInCommand - text; } } - setCursorTextLocation(nextCursorLocation); + setCursorLocation(nextCursorLocation); return true; } @@ -50,20 +50,20 @@ bool TextArea::handleEvent(Ion::Events::Event event) { } else if (handleBoxEvent(app(), event)) { return true; } else if (event == Ion::Events::Left) { - if (cursorTextLocation() <= text()) { - assert(cursorTextLocation() == text()); + if (cursorLocation() <= text()) { + assert(cursorLocation() == text()); return false; } - UTF8Decoder decoder(text(), cursorTextLocation()); + UTF8Decoder decoder(text(), cursorLocation()); decoder.previousCodePoint(); - return setCursorTextLocation(decoder.stringPosition()); + return setCursorLocation(decoder.stringPosition()); } else if (event == Ion::Events::Right) { - if (*cursorTextLocation() == 0) { + if (*cursorLocation() == 0) { return false; } - UTF8Decoder decoder(text(), cursorTextLocation()); + UTF8Decoder decoder(text(), cursorLocation()); decoder.nextCodePoint(); - return setCursorTextLocation(decoder.stringPosition()); + return setCursorLocation(decoder.stringPosition()); } else if (event == Ion::Events::Up) { contentView()->moveCursorGeo(0, -1); } else if (event == Ion::Events::Down) { @@ -98,7 +98,7 @@ void TextArea::setText(char * textBuffer, size_t textBufferSize) { bool TextArea::insertTextWithIndentation(const char * textBuffer, const char * location) { int indentation = indentationBeforeCursor(); - const char * previousChar = cursorTextLocation()-1; + const char * previousChar = cursorLocation()-1; if (previousChar >= const_cast