From 86ff6e2c8ec2501b31e09d3658b9aa86e2b184c2 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 5 Nov 2024 15:32:44 -0700 Subject: [PATCH] vim: Fix paragraphs with softwrap (#20259) Closes #19778 Release Notes: - vim: Fixed paragraph object in the presence of softwrap --- crates/editor/src/display_map.rs | 20 ++++++++++++++++++-- crates/vim/src/object.rs | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index ed616ac49a71eeb0887df03daf37e4367394b337..1efb27ef7dd3c6044b8eb04395dc69c85719ee4f 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -1172,7 +1172,7 @@ impl Sub for DisplayPoint { #[serde(transparent)] pub struct DisplayRow(pub u32); -impl Add for DisplayRow { +impl Add for DisplayRow { type Output = Self; fn add(self, other: Self) -> Self::Output { @@ -1180,7 +1180,15 @@ impl Add for DisplayRow { } } -impl Sub for DisplayRow { +impl Add for DisplayRow { + type Output = Self; + + fn add(self, other: u32) -> Self::Output { + DisplayRow(self.0 + other) + } +} + +impl Sub for DisplayRow { type Output = Self; fn sub(self, other: Self) -> Self::Output { @@ -1188,6 +1196,14 @@ impl Sub for DisplayRow { } } +impl Sub for DisplayRow { + type Output = Self; + + fn sub(self, other: u32) -> Self::Output { + DisplayRow(self.0 - other) + } +} + impl DisplayPoint { pub fn new(row: DisplayRow, column: u32) -> Self { Self(BlockPoint(Point::new(row.0, column))) diff --git a/crates/vim/src/object.rs b/crates/vim/src/object.rs index c73cee836e3f5ae1b88f67c62180dacc725131c8..502f00aa8d1f4c9bead43c5975602d90b7d86a42 100644 --- a/crates/vim/src/object.rs +++ b/crates/vim/src/object.rs @@ -738,11 +738,11 @@ fn paragraph( let paragraph_start_row = paragraph_start.row(); if paragraph_start_row.0 != 0 { let previous_paragraph_last_line_start = - Point::new(paragraph_start_row.0 - 1, 0).to_display_point(map); + DisplayPoint::new(paragraph_start_row - 1, 0); paragraph_start = start_of_paragraph(map, previous_paragraph_last_line_start); } } else { - let next_paragraph_start = Point::new(paragraph_end_row.0 + 1, 0).to_display_point(map); + let next_paragraph_start = DisplayPoint::new(paragraph_end_row + 1, 0); paragraph_end = end_of_paragraph(map, next_paragraph_start); } }