mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #19946 - paavininanda:Issue18613, r=jdm
Change Offset_to_text_point function and add unit tests <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #18613. <!-- Either: --> - [x] Added unit tests and web platform tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19946) <!-- Reviewable:end -->
This commit is contained in:
commit
36eb711d3b
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