From d9b284c1ecb297f2b713dfdaf9e50a2798934e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 9 Jan 2020 14:39:30 +0100 Subject: [PATCH] [escher/text_input] ShiftUp/Down selects whole textfield on left/right --- escher/include/escher/text_input.h | 2 +- escher/src/text_area.cpp | 2 +- escher/src/text_field.cpp | 4 ++-- escher/src/text_input.cpp | 20 +++++++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) 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; }