[escher] Add behaviour for end and origin events

Change-Id: I363dad3c566289a285179a9f26d3a779f0ff812f
This commit is contained in:
Émilie Feral
2017-09-27 10:22:31 +02:00
committed by EmilieNumworks
parent 5bce67098b
commit feeec6b826
2 changed files with 9 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
#include <stddef.h>
#include <assert.h>
#include <limits.h>
static inline size_t min(size_t a, size_t b) {
@@ -47,7 +48,8 @@ size_t TextArea::Text::indexAtPosition(Position p) {
const char * endOfLastLine = nullptr;
for (Line l : *this) {
if (p.line() == y) {
size_t x = min(p.column(), l.length());
size_t x = p.column() < 0 ? 0 : p.column();
x = min(x, l.length());
return l.text() - m_buffer + x;
}
endOfLastLine = l.text() + l.length();
@@ -313,6 +315,10 @@ bool TextArea::TextArea::handleEvent(Ion::Events::Event event) {
m_contentView.moveCursorGeo(0, -1);
} else if (event == Ion::Events::Down) {
m_contentView.moveCursorGeo(0, 1);
} else if (event == Ion::Events::Origin) {
m_contentView.moveCursorGeo(-INT_MAX, 0);
} else if (event == Ion::Events::End) {
m_contentView.moveCursorGeo(INT_MAX, 0);
} else if (event == Ion::Events::Backspace) {
m_contentView.removeChar();
} else if (event.hasText()) {

View File

@@ -1,4 +1,6 @@
#ifndef LIBA_LIMITS_H
#define LIBA_LIMITS_H
#define INT_MAX 0x7fffffff
#endif