diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index c29e9791b..34c75dcd8 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -100,8 +100,6 @@ protected: virtual const ContentView * nonEditableContentView() const = 0; bool moveCursorLeft(); bool moveCursorRight(); - bool moveCursorBegin(); - bool moveCursorEnd(); 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) {} diff --git a/escher/src/selectable_table_view.cpp b/escher/src/selectable_table_view.cpp index 1551b6074..27f4bd395 100644 --- a/escher/src/selectable_table_view.cpp +++ b/escher/src/selectable_table_view.cpp @@ -133,30 +133,28 @@ HighlightCell * SelectableTableView::selectedCell() { } bool SelectableTableView::handleEvent(Ion::Events::Event event) { - bool noAlphaLock = Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::AlphaLock && Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::ShiftAlphaLock; - if (event == Ion::Events::Down) { return selectCellAtLocation(selectedColumn(), selectedRow()+1); } - if ((noAlphaLock && event == Ion::Events::AlphaDown) && selectedRow() < dataSource()->numberOfRows()-1) { + if ((event == Ion::Events::ShiftDown || event == Ion::Events::AlphaDown) && selectedRow() < dataSource()->numberOfRows()-1) { return selectCellAtLocation(selectedColumn(), dataSource()->numberOfRows()-1); } if (event == Ion::Events::Up) { return selectCellAtLocation(selectedColumn(), selectedRow()-1); } - if ((noAlphaLock && event == Ion::Events::AlphaUp) && selectedRow() > 0) { + if ((event == Ion::Events::ShiftUp || event == Ion::Events::AlphaUp) && selectedRow() > 0) { return selectCellAtLocation(selectedColumn(), 0); } if (event == Ion::Events::Left) { return selectCellAtLocation(selectedColumn()-1, selectedRow()); } - if ((noAlphaLock && event == Ion::Events::AlphaLeft) && selectedColumn() > 0) { + if ((event == Ion::Events::ShiftLeft || event == Ion::Events::AlphaLeft) && selectedColumn() > 0) { return selectCellAtLocation(0, selectedRow()); } if (event == Ion::Events::Right) { return selectCellAtLocation(selectedColumn()+1, selectedRow()); } - if ((noAlphaLock && event == Ion::Events::AlphaRight) && selectedColumn() < dataSource()->numberOfColumns()-1) { + if ((event == Ion::Events::ShiftRight || event == Ion::Events::AlphaRight) && selectedColumn() < dataSource()->numberOfColumns()-1) { return selectCellAtLocation(dataSource()->numberOfColumns()-1, selectedRow()); } if (event == Ion::Events::Copy || event == Ion::Events::Cut) { diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 98e216a3b..bb99860a0 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -100,8 +100,6 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for } bool TextArea::handleEvent(Ion::Events::Event event) { - bool noAlphaLock = Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::AlphaLock && Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::ShiftAlphaLock; - if (m_delegate != nullptr && m_delegate->textAreaDidReceiveEvent(this, event)) { return true; } @@ -115,21 +113,25 @@ bool TextArea::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::ShiftUp || event == Ion::Events::ShiftDown) { selectUpDown(event == Ion::Events::ShiftUp); return true; - } else if (noAlphaLock && event == Ion::Events::AlphaLeft) { + } else if (event == Ion::Events::AlphaLeft) { contentView()->moveCursorGeo(-INT_MAX/2, 0); TextInput::scrollToCursor(); - return true; - } else if (noAlphaLock && event == Ion::Events::AlphaRight) { + } else if (event == Ion::Events::AlphaRight) { contentView()->moveCursorGeo(INT_MAX/2, 0); TextInput::scrollToCursor(); - return true; - } else if (event == Ion::Events::Left || event == Ion::Events::AlphaLeft) { + } else if (event == Ion::Events::AlphaUp) { + contentView()->moveCursorGeo(0, -INT_MAX/2); + TextInput::scrollToCursor(); + } else if (event == Ion::Events::AlphaDown) { + contentView()->moveCursorGeo(0, INT_MAX/2); + TextInput::scrollToCursor(); + } else if (event == Ion::Events::Left) { if (contentView()->resetSelection()) { return true; } return TextInput::moveCursorLeft(); } - if (event == Ion::Events::Right || event == Ion::Events::AlphaRight) { + if (event == Ion::Events::Right) { if (contentView()->resetSelection()) { return true; } @@ -167,18 +169,10 @@ bool TextArea::handleEvent(Ion::Events::Event event) { deleteSelection(); return true; } - } else if (noAlphaLock && event == Ion::Events::AlphaUp) { - contentView()->moveCursorGeo(0, -INT_MAX/2); - TextInput::scrollToCursor(); - return true; - } else if (noAlphaLock && event == Ion::Events::AlphaDown) { - contentView()->moveCursorGeo(0, INT_MAX/2); - TextInput::scrollToCursor(); - return true; - } else if (event == Ion::Events::Up || event == Ion::Events::AlphaUp) { + } else if (event == Ion::Events::Up) { contentView()->resetSelection(); contentView()->moveCursorGeo(0, -1); - } else if (event == Ion::Events::Down || event == Ion::Events::AlphaDown) { + } else if (event == Ion::Events::Down) { contentView()->resetSelection(); contentView()->moveCursorGeo(0, 1); } else if (event == Ion::Events::Backspace) { diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 7f4f12e08..36500b007 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -317,14 +317,10 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) { /* If a move event was not caught before, we handle it here to avoid bubbling * the event up. */ if (isEditing() - && (event == Ion::Events::Up - || event == Ion::Events::AlphaUp + && (event == Ion::Events::Up || event == Ion::Events::Down - || event == Ion::Events::AlphaDown || event == Ion::Events::Left - || event == Ion::Events::AlphaLeft - || event == Ion::Events::Right - || event == Ion::Events::AlphaRight)) + || event == Ion::Events::Right)) { return true; } @@ -463,25 +459,17 @@ bool TextField::privateHandleMoveEvent(Ion::Events::Event event) { return false; } const char * draftBuffer = m_contentView.editedText(); - if (event == Ion::Events::Left || event == Ion::Events::AlphaLeft || event == Ion::Events::Right || event == Ion::Events::AlphaRight) { - bool noAlphaLock = Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::AlphaLock && Ion::Events::shiftAlphaStatus() != Ion::Events::ShiftAlphaStatus::ShiftAlphaLock; - + if (event == Ion::Events::Left || event == Ion::Events::Right) { if (!m_contentView.selectionIsEmpty()) { resetSelection(); return true; } - if ((event == Ion::Events::Left || (event == Ion::Events::AlphaLeft && !noAlphaLock)) && cursorLocation() > draftBuffer) { + if (event == Ion::Events::Left && cursorLocation() > draftBuffer) { return TextInput::moveCursorLeft(); } - if (event == Ion::Events::AlphaLeft && noAlphaLock && cursorLocation() > draftBuffer) { - return TextInput::moveCursorBegin(); - } - if ((event == Ion::Events::Right || (event == Ion::Events::AlphaRight && !noAlphaLock)) && cursorLocation() < draftBuffer + draftTextLength()) { + if (event == Ion::Events::Right && cursorLocation() < draftBuffer + draftTextLength()) { return TextInput::moveCursorRight(); } - if (event == Ion::Events::AlphaRight && noAlphaLock && cursorLocation() < draftBuffer + draftTextLength()) { - return TextInput::moveCursorEnd(); - } } return false; } diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index 973c7a64d..6e573a045 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -187,29 +187,6 @@ bool TextInput::removeEndOfLine() { return false; } -bool TextInput::moveCursorBegin() { - if (cursorLocation() <= text()) { - assert(cursorLocation() == text()); - return false; - } - - return setCursorLocation(text()); -} - -bool TextInput::moveCursorEnd() { - if (UTF8Helper::CodePointIs(cursorLocation(), UCodePointNull)) { - return false; - } - - UTF8Decoder decoder(text(), cursorLocation()); - - while(decoder.nextCodePoint() != UCodePointNull) { - decoder.setPosition(decoder.nextGlyphPosition()); - } - - return setCursorLocation(decoder.stringPosition()); -} - bool TextInput::moveCursorLeft() { if (cursorLocation() <= text()) { assert(cursorLocation() == text()); diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index f9535dae3..f195bf3dc 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -74,6 +74,18 @@ Event getEvent(int * timeout) { bool shift = isShiftActive() || state.keyDown(Keyboard::Key::Shift); bool alpha = isAlphaActive() || state.keyDown(Keyboard::Key::Alpha); bool lock = isLockActive(); + + if ( key == Keyboard::Key::Left + || key == Keyboard::Key::Right + || key == Keyboard::Key::Up + || key == Keyboard::Key::Down) { + if (lock) { + lock = false; + alpha = false; + shift = false; + } + } + Event event(key, shift, alpha, lock); sLastEventShift = shift; sLastEventAlpha = alpha;