[escher/text_input] ShiftUp/Down selects whole textfield on left/right

This commit is contained in:
Léa Saviot
2020-01-09 14:39:30 +01:00
parent cef4466ca8
commit d9b284c1ec
4 changed files with 19 additions and 9 deletions

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;
}