mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[escher] In text area, correct move cursor
Change-Id: I4705129f3739c0548381a555f03e6ca08704bec7
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user