diff options
author | paavininanda <paavininanda@gmail.com> | 2018-02-04 20:19:52 +0530 |
---|---|---|
committer | paavininanda <paavininanda@gmail.com> | 2018-02-07 01:18:50 +0530 |
commit | 7b58fb5fddbb12215578d6717f1f33ab535aaad3 (patch) | |
tree | 4d5b4d2d88093b83f411bc087e91365c8ec1c479 /components/script/textinput.rs | |
parent | 1662fd735731fcdd6184b4b89f8eb704357fd102 (diff) | |
download | servo-7b58fb5fddbb12215578d6717f1f33ab535aaad3.tar.gz servo-7b58fb5fddbb12215578d6717f1f33ab535aaad3.zip |
Changed offset_to_text_point function and added unit tests for the same
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 937ab38ed5d..4d8479346f3 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -871,13 +871,12 @@ impl<T: ClipboardProvider> TextInput<T> { fn offset_to_text_point(&self, abs_point: usize) -> TextPoint { let mut index = abs_point; let mut line = 0; - let last_line_idx = self.lines.len() - 1; self.lines.iter().enumerate().fold(0, |acc, (i, val)| { if i != last_line_idx { - let line_end = max(val.len(), 1); - let new_acc = acc + line_end; - if abs_point > new_acc && index > line_end { + let line_end = val.len(); + let new_acc = acc + line_end + 1; + if abs_point >= new_acc && index > line_end { index -= line_end + 1; line += 1; } |