Fix bug of TextInput.adjust_horizontal causing stack overflow or wraparound

When the edit_point is in the first position of a multiline TextInput
adjust_horizontal(-1) moves the edit_point to the end of the first line.
When the first line is empty this causes a stack overflow. When the edit_point
is in the last position adjust_horizontal(1) causes a stack overflow.
This commit is contained in:
Emanuel Rylke 2014-12-06 20:59:04 +01:00
parent f99c0e2c15
commit b5e7cba598

View file

@ -178,29 +178,20 @@ impl TextInput {
/// adjusted vertically and the process repeats with the remaining adjustment requested.
fn adjust_horizontal(&mut self, adjust: int) {
if adjust < 0 {
if self.multiline {
let remaining = self.edit_point.index;
if adjust.abs() as uint > remaining {
self.edit_point.index = 0;
if adjust.abs() as uint > remaining && self.edit_point.line > 0 {
self.adjust_vertical(-1);
self.edit_point.index = self.current_line_length();
self.adjust_horizontal(adjust + remaining as int);
} else {
self.edit_point.index = (self.edit_point.index as int + adjust) as uint;
}
} else {
self.edit_point.index = max(0, self.edit_point.index as int + adjust) as uint;
}
} else {
if self.multiline {
let remaining = self.current_line_length() - self.edit_point.index;
if adjust as uint > remaining {
if adjust as uint > remaining && self.edit_point.line < self.lines.len() - 1 {
self.edit_point.index = 0;
self.adjust_vertical(1);
self.adjust_horizontal(adjust - remaining as int);
} else {
self.edit_point.index += adjust as uint;
}
} else {
self.edit_point.index = min(self.current_line_length(),
self.edit_point.index + adjust as uint);