diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index da5854908..6d551b124 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -60,6 +60,7 @@ protected: // Alignment void setAlignment(float horizontalAlignment, float verticalAlignment); + float horizontalAlignment() const { return m_horizontalAlignment; } // Reload void reloadRectFromPosition(const char * position, bool includeFollowingLines = false); diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index cb7d89a0a..dbcb3b4f2 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -151,15 +151,19 @@ void TextInput::scrollToCursor() { } void TextInput::deleteSelection() { - assert(!contentView()->selectionIsEmpty()); - const char * previousSelectionStart = contentView()->selectionStart(); - const char * previousSelectionEnd = contentView()->selectionEnd(); - bool cursorIsAtEndOfSelection = previousSelectionEnd == contentView()->cursorLocation(); - size_t removedLength = contentView()->deleteSelection(); - if (cursorIsAtEndOfSelection) { - setCursorLocation(contentView()->cursorLocation() - removedLength); + ContentView * cv = contentView(); + assert(!cv->selectionIsEmpty()); + const float horizontalAlignment = cv->horizontalAlignment(); + if (horizontalAlignment == 0.0f) { + cv->reloadRectFromPosition(cv->selectionStart(), true); } - contentView()->reloadRectFromPosition(previousSelectionStart, true); + bool cursorIsAtEndOfSelection = cv->selectionEnd() == cv->cursorLocation(); + size_t removedLength = cv->deleteSelection(); + if (cursorIsAtEndOfSelection) { + setCursorLocation(cv->cursorLocation() - removedLength); + } + layoutSubviews(true); // Set the cursor frame by calling the subviews relayouting + scrollToCursor(); } void TextInput::setAlignment(float horizontalAlignment, float verticalAlignment) {