From 4a1e4c9883cdf70f0e9d3f8961a5c03e3675bb3e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 7 May 2018 23:13:25 +0200 Subject: Fix text 'got to end of line' --- src/Text.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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); } } -- cgit v1.2.3