summaryrefslogtreecommitdiff
path: root/scene/gui/line_edit.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-12 12:05:21 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-12 12:05:21 -0300
commit83bf8036def06e8038891b1f143ac86c1d9b0c0c (patch)
tree592d7f10266550962de7ae4e83ddfda81ac3e5e7 /scene/gui/line_edit.cpp
parent1785f6939f2db8e02776559c8a2b5c5d391ad909 (diff)
rewrote LineEdit window repositioning code so it does not eat the last character, closes #4992
Diffstat (limited to 'scene/gui/line_edit.cpp')
-rw-r--r--scene/gui/line_edit.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 2a4e82a8e7..ab556ede0c 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -731,14 +731,21 @@ void LineEdit::set_cursor_pos(int p_pos) {
int width_to_cursor=0;
int wp=window_pos;
- if (font != NULL) {
- for (int i=window_pos;i<cursor_pos;i++)
- width_to_cursor+=font->get_char_size( text[i] ).width;
+ if (font.is_valid()) {
+
+ int accum_width=0;
+
+ for(int i=cursor_pos;i>=window_pos;i--) {
- while (width_to_cursor >= window_width && wp < text.length()) {
+ if (i>=text.length()) {
+ accum_width=font->get_char_size(' ').width; //anything should do
+ } else {
+ accum_width+=font->get_char_size(text[i],i+1<text.length()?text[i+1]:0).width; //anything should do
+ }
+ if (accum_width>=window_width)
+ break;
- width_to_cursor -= font->get_char_size(text[wp]).width;
- wp++;
+ wp=i;
}
}