fixed out-of-bounds string access when backspacing in a formula

Change-Id: Ic586ce857574e1d28e0e4d754bea0d5251d0efdf