[escher] In text area, correct move cursor

Change-Id: I4705129f3739c0548381a555f03e6ca08704bec7
This commit is contained in:
Émilie Feral
2017-08-11 13:59:48 +02:00
parent 779db66a15
commit 8f65fb6535
2 changed files with 11 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
#ifndef ESCHER_TEXT_AREA_H
#define ESCHER_TEXT_AREA_H
#include <assert.h>
#include <string.h>
#include <escher/scrollable_view.h>
#include <escher/text_area_delegate.h>
@@ -61,7 +62,10 @@ private:
void insertChar(char c, size_t index);
char removeChar(size_t index);
size_t bufferLength() const;
char operator[](int index) {
assert(index >= 0 && index < m_bufferSize);
return m_buffer[index];
}
private:
char * m_buffer;
size_t m_bufferSize;

View File

@@ -109,11 +109,6 @@ TextArea::Text::Position TextArea::Text::span() const {
return Position(width, height);
}
size_t TextArea::Text::bufferLength() const {
return strlen(m_buffer);
}
/* TextArea::ContentView */
TextArea::ContentView::ContentView(char * textBuffer, size_t textBufferSize, KDText::FontSize fontSize, KDColor textColor, KDColor backgroundColor) :
@@ -226,10 +221,13 @@ void TextArea::TextArea::ContentView::moveCursorGeo(int deltaX, int deltaY) {
}
void TextArea::TextArea::ContentView::moveCursorIndex(int deltaX) {
if ((deltaX < 0 && m_cursorIndex <= 0) || (deltaX > 0 && m_cursorIndex >= m_text.bufferLength())) {
return;
assert(deltaX == -1 || deltaX == 1);
if (deltaX == -1 && m_cursorIndex>0) {
m_cursorIndex--;
}
if (deltaX == 1 && m_text[m_cursorIndex] != 0) {
m_cursorIndex++;
}
m_cursorIndex += deltaX;
layoutSubviews();
}