Skip to content

Commit

Permalink
Fix bug of TextInput.adjust_horizontal causing stack overflow or wrap…
Browse files Browse the repository at this point in the history
…around

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.
  • Loading branch information
ema-fox committed Dec 6, 2014
1 parent f99c0e2 commit b5e7cba
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions components/script/textinput.rs
Expand Up @@ -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;
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;
}
let remaining = self.edit_point.index;
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 = 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 {
self.edit_point.index = 0;
self.adjust_vertical(1);
self.adjust_horizontal(adjust - remaining as int);
} else {
self.edit_point.index += adjust as uint;
}
let remaining = self.current_line_length() - self.edit_point.index;
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 = min(self.current_line_length(),
self.edit_point.index + adjust as uint);
Expand Down

5 comments on commit b5e7cba

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at ema-fox@b5e7cba

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ema-fox/servo/textinput = b5e7cba into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ema-fox/servo/textinput = b5e7cba merged ok, testing candidate = 9ac8175

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9ac8175

Please sign in to comment.