Change summary
zed/src/editor/display_map.rs | 8 +++++---
zed/src/editor/display_map/wrap_map.rs | 17 +++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
Detailed changes
@@ -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 {
@@ -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, &());