Fix DisplaySnapshot::x_for_point always returning 0
Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
c81440424b
commit
d273fa6dd0
1 changed files with 8 additions and 8 deletions
|
@ -572,7 +572,6 @@ impl DisplaySnapshot {
|
||||||
) -> Line {
|
) -> Line {
|
||||||
let mut runs = Vec::new();
|
let mut runs = Vec::new();
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
let mut ended_in_newline = false;
|
|
||||||
|
|
||||||
let range = display_row..display_row + 1;
|
let range = display_row..display_row + 1;
|
||||||
for chunk in self.highlighted_chunks(range, false, &editor_style) {
|
for chunk in self.highlighted_chunks(range, false, &editor_style) {
|
||||||
|
@ -588,17 +587,18 @@ impl DisplaySnapshot {
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(&editor_style.text)
|
Cow::Borrowed(&editor_style.text)
|
||||||
};
|
};
|
||||||
ended_in_newline = chunk.chunk.ends_with("\n");
|
|
||||||
|
|
||||||
runs.push(text_style.to_run(chunk.chunk.len()))
|
runs.push(text_style.to_run(chunk.chunk.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// our pixel positioning logic assumes each line ends in \n,
|
if line.ends_with('\n') {
|
||||||
// this is almost always true except for the last line which
|
line.pop();
|
||||||
// may have no trailing newline.
|
if let Some(last_run) = runs.last_mut() {
|
||||||
if !ended_in_newline && display_row == self.max_point().row() {
|
last_run.len -= 1;
|
||||||
line.push_str("\n");
|
if last_run.len == 0 {
|
||||||
runs.push(editor_style.text.to_run("\n".len()));
|
runs.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue