Fix possible crash with text length change