Updated set_max_length() function to actually pull a substring of the current text so it's not all thrown away when the new max length is shorter than the current length. (cherry picked from commit 71febfd6e2)
71febfd6e2