diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-02-20 16:12:58 -0500 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-02-20 16:12:58 -0500 |
commit | 837be2734764807491de4a8ed2b5b24fd5668f03 (patch) | |
tree | 0aeb76c0b8cd2d778cd99abfafe139a562875495 /components/script/textinput.rs | |
parent | 172db80703fc19ff078f2f46fb299cadd99a483b (diff) | |
download | servo-837be2734764807491de4a8ed2b5b24fd5668f03.tar.gz servo-837be2734764807491de4a8ed2b5b24fd5668f03.zip |
Use platform-sized integers for textinput.rs
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 8c1a6214098..20b396d45d1 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -24,9 +24,9 @@ enum Selection { #[derive(Copy)] struct TextPoint { /// 0-based line number - line: uint, + line: usize, /// 0-based column number - index: uint, + index: usize, } /// Encapsulated state for handling keyboard input in a single or multiline text input control. @@ -166,13 +166,13 @@ impl TextInput { } /// Return the length of the current line under the editing point. - fn current_line_length(&self) -> uint { + fn current_line_length(&self) -> usize { self.lines[self.edit_point.line].chars().count() } /// Adjust the editing point position by a given of lines. The resulting column is /// as close to the original column position as possible. - fn adjust_vertical(&mut self, adjust: int, select: Selection) { + fn adjust_vertical(&mut self, adjust: isize, select: Selection) { if !self.multiline { return; } @@ -187,26 +187,26 @@ impl TextInput { assert!(self.edit_point.line < self.lines.len()); - let target_line: int = self.edit_point.line as int + adjust; + let target_line: isize = self.edit_point.line as isize + adjust; if target_line < 0 { self.edit_point.index = 0; self.edit_point.line = 0; return; - } else if target_line as uint >= self.lines.len() { + } else if target_line as usize >= self.lines.len() { self.edit_point.line = self.lines.len() - 1; self.edit_point.index = self.current_line_length(); return; } - self.edit_point.line = target_line as uint; + self.edit_point.line = target_line as usize; self.edit_point.index = min(self.current_line_length(), self.edit_point.index); } /// Adjust the editing point position by a given number of columns. If the adjustment /// requested is larger than is available in the current line, the editing point is /// adjusted vertically and the process repeats with the remaining adjustment requested. - fn adjust_horizontal(&mut self, adjust: int, select: Selection) { + fn adjust_horizontal(&mut self, adjust: isize, select: Selection) { if select == Selection::Selected { if self.selection_begin.is_none() { self.selection_begin = Some(self.edit_point); @@ -222,23 +222,23 @@ impl TextInput { if adjust < 0 { let remaining = self.edit_point.index; - if adjust.abs() as uint > remaining && self.edit_point.line > 0 { + if adjust.abs() as usize > remaining && self.edit_point.line > 0 { self.adjust_vertical(-1, select); self.edit_point.index = self.current_line_length(); self.adjust_horizontal(adjust + remaining as int + 1, select); } else { - self.edit_point.index = max(0, self.edit_point.index as int + adjust) as uint; + self.edit_point.index = max(0, self.edit_point.index as int + adjust) as usize; } } else { let remaining = self.current_line_length() - self.edit_point.index; - if adjust as uint > remaining && self.lines.len() > self.edit_point.line + 1 { + if adjust as usize > remaining && self.lines.len() > self.edit_point.line + 1 { self.adjust_vertical(1, select); self.edit_point.index = 0; // one shift is consumed by the change of line, hence the -1 self.adjust_horizontal(adjust - remaining as int - 1, select); } else { self.edit_point.index = min(self.current_line_length(), - self.edit_point.index + adjust as uint); + self.edit_point.index + adjust as usize); } } } |