From 2ec16a0e88d94aa83a222a3e207cfbe619824815 Mon Sep 17 00:00:00 2001 From: Emanuel Rylke Date: Sat, 6 Dec 2014 14:26:28 +0100 Subject: [PATCH 1/3] Fix bug of TextInput.adjust_vertical(1) always moving to the end of text. --- components/script/textinput.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 6903dfc5c4a..6196a003c2f 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -163,7 +163,7 @@ impl TextInput { self.edit_point.index = 0; self.edit_point.line = 0; return; - } else if adjust > 0 && self.edit_point.line >= min(0, self.lines.len() - adjust as uint) { + } else if adjust > 0 && self.edit_point.line >= self.lines.len() - adjust as uint { self.edit_point.index = self.current_line_length(); self.edit_point.line = self.lines.len() - 1; return; From f99c0e2c1538d3c6e4d857a2062e408905922207 Mon Sep 17 00:00:00 2001 From: Emanuel Rylke Date: Sat, 6 Dec 2014 15:06:13 +0100 Subject: [PATCH 2/3] Implement Page(Up|Down) functionality for TextInput. --- components/script/textinput.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 6196a003c2f..c925c0a5d82 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -163,9 +163,9 @@ impl TextInput { self.edit_point.index = 0; self.edit_point.line = 0; return; - } else if adjust > 0 && self.edit_point.line >= self.lines.len() - adjust as uint { - self.edit_point.index = self.current_line_length(); + } else if adjust > 0 && self.edit_point.line + adjust as uint >= self.lines.len() { self.edit_point.line = self.lines.len() - 1; + self.edit_point.index = self.current_line_length(); return; } @@ -268,6 +268,14 @@ impl TextInput { self.edit_point.index = self.current_line_length(); Nothing } + "PageUp" => { + self.adjust_vertical(-28); + Nothing + } + "PageDown" => { + self.adjust_vertical(28); + Nothing + } "Tab" => TriggerDefaultAction, _ => Nothing, } From b5e7cba598302d3d35ba8a3b735501b1be23b67f Mon Sep 17 00:00:00 2001 From: Emanuel Rylke Date: Sat, 6 Dec 2014 20:59:04 +0100 Subject: [PATCH 3/3] 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. --- components/script/textinput.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/components/script/textinput.rs b/components/script/textinput.rs index c925c0a5d82..d94ae6c4ee6 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -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);