mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Changed offset_to_text_point function and added unit tests for the same
This commit is contained in:
parent
1662fd7357
commit
7b58fb5fdd
5 changed files with 63 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue