Compare commits

...

1 Commits

Author SHA1 Message Date
Peter Tripp
48c6be8242 WIP.
Co-Authored-By: Nathan <nathan@zed.dev>
Co-Authored-By: Antonio <antonio@zed.dev>
2025-06-02 14:01:45 -04:00
4 changed files with 56 additions and 6 deletions

View File

@@ -1103,7 +1103,7 @@ impl DisplaySnapshot {
pub fn clip_point(&self, point: DisplayPoint, bias: Bias) -> DisplayPoint {
let mut clipped = self.block_snapshot.clip_point(point.0, bias);
if self.clip_at_line_ends {
if dbg!(self.clip_at_line_ends) {
clipped = self.clip_at_line_end(DisplayPoint(clipped)).0
}
DisplayPoint(clipped)

View File

@@ -1570,12 +1570,15 @@ impl BlockSnapshot {
}
}
None => {
dbg!();
let input_point = if point.row >= output_end_row.0 {
dbg!();
let line_len = self.wrap_snapshot.line_len(input_end_row.0 - 1);
self.wrap_snapshot
.clip_point(WrapPoint::new(input_end_row.0 - 1, line_len), bias)
} else {
let output_overshoot = point.0.saturating_sub(output_start);
dbg!(input_start, output_overshoot);
self.wrap_snapshot
.clip_point(WrapPoint(input_start + output_overshoot), bias)
};

View File

@@ -761,16 +761,18 @@ impl WrapSnapshot {
}
pub fn make_wrap_point(&self, point: Point, bias: Bias) -> WrapPoint {
self.tab_point_to_wrap_point(self.tab_snapshot.make_tab_point(point, bias))
self.tab_point_to_wrap_point(self.tab_snapshot.make_tab_point(point, bias), bias)
}
pub fn tab_point_to_wrap_point(&self, point: TabPoint) -> WrapPoint {
pub fn tab_point_to_wrap_point(&self, point: TabPoint, bias: Bias) -> WrapPoint {
let mut cursor = self.transforms.cursor::<(TabPoint, WrapPoint)>(&());
cursor.seek(&point, Bias::Right, &());
cursor.seek(&point, bias, &());
WrapPoint(cursor.start().1.0 + (point.0 - cursor.start().0.0))
}
pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint {
dbg!(point, bias);
if bias == Bias::Left {
let mut cursor = self.transforms.cursor::<WrapPoint>(&());
cursor.seek(&point, Bias::Right, &());
@@ -780,7 +782,14 @@ impl WrapSnapshot {
}
}
self.tab_point_to_wrap_point(self.tab_snapshot.clip_point(self.to_tab_point(point), bias))
dbg!(point);
let tab_point = self.to_tab_point(point);
dbg!(&tab_point);
let clipped_tab_point = self.tab_snapshot.clip_point(tab_point, bias);
dbg!(&clipped_tab_point);
let result = self.tab_point_to_wrap_point(clipped_tab_point);
dbg!(&result);
result
}
pub fn prev_row_boundary(&self, mut point: WrapPoint) -> u32 {

View File

@@ -247,9 +247,10 @@ pub fn line_end(
display_point: DisplayPoint,
stop_at_soft_boundaries: bool,
) -> DisplayPoint {
dbg!(display_point, map.line_len(display_point.row()));
let soft_line_end = map.clip_point(
DisplayPoint::new(display_point.row(), map.line_len(display_point.row())),
Bias::Left,
Bias::Right,
);
if stop_at_soft_boundaries && display_point != soft_line_end {
soft_line_end
@@ -1240,6 +1241,43 @@ mod tests {
});
}
#[gpui::test]
async fn test_move_to_end_of_soft_wrapped_line(cx: &mut gpui::TestAppContext) {
cx.update(|cx| {
init_test(cx);
});
let mut cx = EditorTestContext::new(cx).await;
let editor = cx.editor.clone();
let window = cx.window;
_ = cx.update_window(window, |_, window, cx| {
let _text_layout_details = editor.read(cx).text_layout_details(window);
let multibuffer = MultiBuffer::build_simple("mmmmmmmmmmmmmmmmmmmmmmmnnnnnn", cx);
let display_map = cx.new(|cx| {
DisplayMap::new(
multibuffer,
font("Helvetica"),
px(14.0),
Some(px(200.)),
0,
0,
FoldPlaceholder::test(),
DiagnosticSeverity::Warning,
cx,
)
});
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(snapshot.text(), "mmmmmmmmmmmmmmmmmmmmmmm\nnnnnnn");
// Test moving to end of first soft-wrapped line
assert_eq!(
line_end(&snapshot, DisplayPoint::new(DisplayRow(0), 0), true),
DisplayPoint::new(DisplayRow(0), 23)
);
});
}
fn init_test(cx: &mut gpui::App) {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);