diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index 6d551b124..90de869c5 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -97,7 +97,7 @@ protected: virtual const ContentView * nonEditableContentView() const = 0; bool moveCursorLeft(); bool moveCursorRight(); - bool selectLeftRight(bool left); + bool selectLeftRight(bool left, bool all); // While indicates if all the text on the left/right should be selected private: virtual void willSetCursorLocation(const char * * location) {} virtual bool privateRemoveEndOfLine(); diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index b22fd17ec..ef764601c 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -109,7 +109,7 @@ bool TextArea::handleEvent(Ion::Events::Event event) { return true; } if (event == Ion::Events::ShiftLeft || event == Ion::Events::ShiftRight) { - selectLeftRight(event == Ion::Events::ShiftLeft); + selectLeftRight(event == Ion::Events::ShiftLeft, false); return true; } if (event == Ion::Events::ShiftUp ||event == Ion::Events::ShiftDown) { diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 28c6ce207..8f157b584 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -481,8 +481,8 @@ bool TextField::privateHandleSelectEvent(Ion::Events::Event event) { if (!isEditing()) { return false; } - if (event == Ion::Events::ShiftLeft || event == Ion::Events::ShiftRight) { - selectLeftRight(event == Ion::Events::ShiftLeft); + if (event == Ion::Events::ShiftLeft || event == Ion::Events::ShiftRight || event == Ion::Events::ShiftUp || event == Ion::Events::ShiftDown) { + selectLeftRight(event == Ion::Events::ShiftLeft || event == Ion::Events::ShiftUp, event == Ion::Events::ShiftUp || event == Ion::Events::ShiftDown); return true; } return false; diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index dbcb3b4f2..41c818743 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -206,13 +206,23 @@ bool TextInput::moveCursorRight() { return setCursorLocation(decoder.nextGlyphPosition()); } -bool TextInput::selectLeftRight(bool left) { +bool TextInput::selectLeftRight(bool left, bool all) { const char * cursorLoc = cursorLocation(); - bool moved = left ? moveCursorLeft() : moveCursorRight(); - if (!moved) { - return false; + const char * nextCursorLoc = nullptr; + if (!all) { + bool moved = left ? moveCursorLeft() : moveCursorRight(); + if (!moved) { + return false; + } + nextCursorLoc = cursorLocation(); + } else { + const char * t = text(); + nextCursorLoc = left ? t : t + strlen(t); + if (cursorLoc == nextCursorLoc) { + return false; + } + setCursorLocation(nextCursorLoc); } - const char * nextCursorLoc = cursorLocation(); contentView()->addSelection(left ? nextCursorLoc : cursorLoc, left ? cursorLoc : nextCursorLoc); return true; }