mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher/text_input] Factorize and clean handleEvent Right and Left
This commit is contained in:
committed by
EmilieNumworks
parent
5a8596acd7
commit
cc8403e020
@@ -50,7 +50,7 @@ protected:
|
||||
virtual const char * editedText() const = 0;
|
||||
virtual size_t editedTextLength() const = 0;
|
||||
};
|
||||
protected:
|
||||
|
||||
/* If the text to be appended is too long to be added without overflowing the
|
||||
* buffer, nothing is done (not even adding few letters from the text to reach
|
||||
* the maximum buffer capacity) and false is returned. */
|
||||
@@ -60,6 +60,8 @@ protected:
|
||||
return const_cast<ContentView *>(nonEditableContentView());
|
||||
}
|
||||
virtual const ContentView * nonEditableContentView() const = 0;
|
||||
bool moveCursorLeft();
|
||||
bool moveCursorRight();
|
||||
private:
|
||||
virtual void willSetCursorLocation(const char * * location) {}
|
||||
virtual bool privateRemoveEndOfLine();
|
||||
|
||||
@@ -99,18 +99,9 @@ bool TextArea::handleEvent(Ion::Events::Event event) {
|
||||
} else if (handleBoxEvent(app(), event)) {
|
||||
return true;
|
||||
} else if (event == Ion::Events::Left) {
|
||||
if (cursorLocation() <= text()) {
|
||||
assert(cursorLocation() == text());
|
||||
return false;
|
||||
}
|
||||
UTF8Decoder decoder(text(), cursorLocation());
|
||||
return setCursorLocation(decoder.previousGlyphPosition());
|
||||
return TextInput::moveCursorLeft();
|
||||
} else if (event == Ion::Events::Right) {
|
||||
if (UTF8Helper::CodePointIs(cursorLocation(), UCodePointNull)) {
|
||||
return false;
|
||||
}
|
||||
UTF8Decoder decoder(cursorLocation());
|
||||
return setCursorLocation(decoder.nextGlyphPosition());
|
||||
return TextInput::moveCursorRight();
|
||||
} else if (event == Ion::Events::Up) {
|
||||
contentView()->moveCursorGeo(0, -1);
|
||||
} else if (event == Ion::Events::Down) {
|
||||
|
||||
@@ -432,23 +432,21 @@ void TextField::scrollToCursor() {
|
||||
}
|
||||
|
||||
bool TextField::privateHandleMoveEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Left && isEditing() && cursorLocation() > m_contentView.draftTextBuffer()) {
|
||||
assert(isEditing());
|
||||
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorLocation());
|
||||
return setCursorLocation(decoder.previousGlyphPosition());
|
||||
if (!isEditing()) {
|
||||
return false;
|
||||
}
|
||||
if (event == Ion::Events::ShiftLeft && isEditing()) {
|
||||
assert(isEditing());
|
||||
return setCursorLocation(m_contentView.draftTextBuffer());
|
||||
const char * draftBuffer = m_contentView.draftTextBuffer();
|
||||
if (event == Ion::Events::Left && cursorLocation() > draftBuffer) {
|
||||
return TextInput::moveCursorLeft();
|
||||
}
|
||||
if (event == Ion::Events::Right && isEditing() && cursorLocation() < m_contentView.draftTextBuffer() + draftTextLength()) {
|
||||
assert(isEditing());
|
||||
UTF8Decoder decoder(cursorLocation());
|
||||
return setCursorLocation(decoder.nextGlyphPosition());
|
||||
if (event == Ion::Events::Right && cursorLocation() < draftBuffer + draftTextLength()) {
|
||||
return TextInput::moveCursorRight();
|
||||
}
|
||||
if (event == Ion::Events::ShiftRight && isEditing()) {
|
||||
assert(isEditing());
|
||||
return setCursorLocation(m_contentView.draftTextBuffer() + draftTextLength());
|
||||
if (event == Ion::Events::ShiftLeft) {
|
||||
return setCursorLocation(draftBuffer);
|
||||
}
|
||||
if (event == Ion::Events::ShiftRight) {
|
||||
return setCursorLocation(draftBuffer + draftTextLength());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,23 @@ bool TextInput::removeEndOfLine() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TextInput::moveCursorLeft() {
|
||||
if (cursorLocation() <= text()) {
|
||||
assert(cursorLocation() == text());
|
||||
return false;
|
||||
}
|
||||
UTF8Decoder decoder(text(), cursorLocation());
|
||||
return setCursorLocation(decoder.previousGlyphPosition());
|
||||
}
|
||||
|
||||
bool TextInput::moveCursorRight() {
|
||||
if (UTF8Helper::CodePointIs(cursorLocation(), UCodePointNull)) {
|
||||
return false;
|
||||
}
|
||||
UTF8Decoder decoder(cursorLocation());
|
||||
return setCursorLocation(decoder.nextGlyphPosition());
|
||||
}
|
||||
|
||||
bool TextInput::privateRemoveEndOfLine() {
|
||||
return contentView()->removeEndOfLine();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user