@@ -85,20 +85,24 @@ function INPUT.set_text(input, text)
85
85
input .empty = # text == 0 and # marked_text == 0
86
86
87
87
-- measure it
88
- input .text_width = get_text_width (input .node , text )
89
- input .marked_text_width = get_text_width (input .node , marked_text )
90
- input .total_width = input .text_width + input .marked_text_width
88
+ local text_width = get_text_width (input .node , text )
89
+ local marked_text_width = get_text_width (input .node , marked_text )
91
90
92
91
-- prevent text from overflowing the input field
93
- local visible_text_width = input .total_width
94
- local visible_text = text .. marked_text
92
+ -- this will get increasingly expensive the longer the text
93
+ -- future improvement is to make a best guess and then either add or
94
+ -- remove characters depending on if the text is too short or long
95
95
local field_width = gui .get_size (input .node ).x * gui .get_scale (input .node ).x
96
- while visible_text_width > field_width do
97
- visible_text = visible_text :sub (2 )
98
- visible_text_width = get_text_width (input .node , visible_text )
96
+ while ( text_width + marked_text_width ) > field_width do
97
+ text = text :sub (2 )
98
+ text_width = get_text_width (input .node , text )
99
99
end
100
-
101
- gui .set_text (input .node , visible_text )
100
+
101
+ input .text_width = text_width
102
+ input .marked_text_width = marked_text_width
103
+ input .total_width = text_width + marked_text_width
104
+
105
+ gui .set_text (input .node , text .. marked_text )
102
106
end
103
107
end
104
108
function INPUT .set_long_pressed_time (input , time )
0 commit comments