diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-07 23:13:25 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-07 23:13:28 +0200 |
commit | 4a1e4c9883cdf70f0e9d3f8961a5c03e3675bb3e (patch) | |
tree | 400c0bc4c59b288b283eb42c71ba8d9c57195be5 /src | |
parent | 2b7d030551a357272f9cc39e347855bd2e3faba2 (diff) |
Fix text 'got to end of line'
Diffstat (limited to 'src')
-rw-r--r-- | src/Text.cpp | 11 |
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); } } |