Ensure that we use the WrapMap where appropriate in DisplayMap

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-07-21 18:04:58 +02:00
co-authored by Nathan Sobo
parent 0875a86c69
commit 915c710f94
2 changed files with 22 additions and 3 deletions
+5 -3
View File
@@ -156,7 +156,9 @@ impl DisplayMapSnapshot {
}
pub fn is_line_folded(&self, display_row: u32) -> bool {
self.folds_snapshot.is_line_folded(display_row)
let wrap_point = DisplayPoint::new(display_row, 0).0;
let row = self.wraps_snapshot.to_input_point(wrap_point).row();
self.folds_snapshot.is_line_folded(row)
}
pub fn text(&self) -> String {
@@ -191,11 +193,11 @@ impl DisplayMapSnapshot {
}
pub fn line_len(&self, row: u32) -> u32 {
self.tabs_snapshot.line_len(row)
self.wraps_snapshot.line_len(row)
}
pub fn longest_row(&self) -> u32 {
self.tabs_snapshot.longest_row()
self.wraps_snapshot.longest_row()
}
pub fn anchor_before(&self, point: DisplayPoint, bias: Bias) -> Anchor {
+17
View File
@@ -164,6 +164,23 @@ impl Snapshot {
self.to_output_point(self.input.max_point())
}
pub fn line_len(&self, row: u32) -> u32 {
let mut len = 0;
for chunk in self.chunks_at(OutputPoint::new(row, 0)) {
if let Some(newline_ix) = chunk.find('\n') {
len += newline_ix;
break;
} else {
len += chunk.len();
}
}
len as u32
}
pub fn longest_row(&self) -> u32 {
self.transforms.summary().output.longest_row
}
pub fn buffer_rows(&self, start_row: u32) -> BufferRows {
let mut transforms = self.transforms.cursor::<OutputPoint, InputPoint>();
transforms.seek(&OutputPoint::new(start_row, 0), Bias::Right, &());