Simply logic of this method
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
074e3cfbd6
commit
4ead1ecbbf
1 changed files with 4 additions and 9 deletions
|
@ -714,6 +714,7 @@ impl Chunk {
|
||||||
fn point_utf16_to_offset_clamped(&self, target: PointUtf16) -> usize {
|
fn point_utf16_to_offset_clamped(&self, target: PointUtf16) -> usize {
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
let mut point = PointUtf16::new(0, 0);
|
let mut point = PointUtf16::new(0, 0);
|
||||||
|
|
||||||
for ch in self.0.chars() {
|
for ch in self.0.chars() {
|
||||||
if point == target {
|
if point == target {
|
||||||
break;
|
break;
|
||||||
|
@ -722,25 +723,19 @@ impl Chunk {
|
||||||
if ch == '\n' {
|
if ch == '\n' {
|
||||||
point.row += 1;
|
point.row += 1;
|
||||||
point.column = 0;
|
point.column = 0;
|
||||||
|
|
||||||
if point.row > target.row {
|
|
||||||
//point is beyond the end of the line
|
|
||||||
//Return the offset up to but not including the newline
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
point.column += ch.len_utf16() as u32;
|
point.column += ch.len_utf16() as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
if point > target {
|
if point > target {
|
||||||
//point is inside of a codepoint
|
// If the point is past the end of a line or inside of a code point,
|
||||||
//Return the offset before adding the len of the codepoint which
|
// return the last valid offset before the point.
|
||||||
//we have landed within, bias left
|
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += ch.len_utf8();
|
offset += ch.len_utf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
offset
|
offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue