aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Text.cpp b/src/Text.cpp
index 6fa1fcc..252d27f 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -504,6 +504,14 @@ namespace dchat
void Text::updateCaret()
{
assert(!dirty && !dirtyText);
+ if(textElements.size() == 0)
+ {
+ float vspace = font->getLineSpacing(characterSize);
+ caretIndex = 0;
+ caretPosition = sf::Vector2f(0.0f, -vspace);
+ return;
+ }
+
switch(caretMoveDirection)
{
case CaretMoveDirection::UP:
@@ -531,6 +539,8 @@ namespace dchat
break;
}
+ caretIndex = std::min(std::max(0, caretIndex), (int)textElements[0].text.size);
+
usize vertexIndex = caretIndex * 4;
if(vertexIndex == 0)
{
@@ -566,7 +576,6 @@ namespace dchat
int row = getRowByPosition(topLeftVertex.position);
if(row != startRow)
{
- printf("start of line %u, startIndex: %u\n", i, startIndex * 4);
return std::max(0, i / 4 + 1);
}
}