Skip to content

Commit

Permalink
Fix return value of get_total_character_count
Browse files Browse the repository at this point in the history
Also document that it only counts visible characters.

Fixes #23720
  • Loading branch information
ttencate committed Nov 15, 2018
1 parent 397b127 commit 922f2d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Label.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<return type="int">
</return>
<description>
Returns the total length of the text.
Returns the total number of printable characters in the text (excluding spaces and newlines).
</description>
</method>
<method name="get_visible_line_count" qualifiers="const">
Expand Down
5 changes: 2 additions & 3 deletions scene/gui/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void Label::regenerate_word_cache() {

WordCache *last = NULL;

for (int i = 0; i < xl_text.size() + 1; i++) {
for (int i = 0; i <= xl_text.length(); i++) {

CharType current = i < xl_text.length() ? xl_text[i] : ' '; //always a space at the end, so the algo works

Expand Down Expand Up @@ -429,12 +429,11 @@ void Label::regenerate_word_cache() {

if (current == '\n') {
insert_newline = true;
} else {
} else if (current != ' ') {
total_char_cache++;
}

if (i < xl_text.length() && xl_text[i] == ' ') {
total_char_cache--; // do not count spaces
if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) {
space_count++;
line_width += space_width;
Expand Down

0 comments on commit 922f2d6

Please sign in to comment.