diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 33f166aee6..5d90c36d30 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -302,6 +302,10 @@ impl DisplayMapSnapshot { self.folds_snapshot.is_line_folded(tab_point.row()) } + pub fn is_block_line(&self, display_row: u32) -> bool { + self.blocks_snapshot.is_block_line(display_row) + } + pub fn soft_wrap_indent(&self, display_row: u32) -> Option { let wrap_row = self .blocks_snapshot diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index e41afffe3c..f9731662ee 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -558,6 +558,12 @@ impl BlockSnapshot { } } + pub fn is_block_line(&self, row: u32) -> bool { + let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); + cursor.seek(&BlockRow(row), Bias::Right, &()); + cursor.item().map_or(false, |t| t.block.is_some()) + } + pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint { let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(); cursor.seek(&BlockRow(point.row), Bias::Right, &()); diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs index 7ad1374f8e..c6190fec29 100644 --- a/crates/editor/src/movement.rs +++ b/crates/editor/src/movement.rs @@ -33,11 +33,17 @@ pub fn up( map.column_to_chars(point.row(), point.column()) }; - if point.row() > 0 { - *point.row_mut() -= 1; - *point.column_mut() = map.column_from_chars(point.row(), goal_column); - } else { - point = DisplayPoint::new(0, 0); + loop { + if point.row() > 0 { + *point.row_mut() -= 1; + *point.column_mut() = map.column_from_chars(point.row(), goal_column); + if !map.is_block_line(point.row()) { + break; + } + } else { + point = DisplayPoint::new(0, 0); + break; + } } let clip_bias = if point.column() == map.line_len(point.row()) { @@ -64,11 +70,17 @@ pub fn down( map.column_to_chars(point.row(), point.column()) }; - if point.row() < max_point.row() { - *point.row_mut() += 1; - *point.column_mut() = map.column_from_chars(point.row(), goal_column); - } else { - point = max_point; + loop { + if point.row() < max_point.row() { + *point.row_mut() += 1; + *point.column_mut() = map.column_from_chars(point.row(), goal_column); + if !map.is_block_line(point.row()) { + break; + } + } else { + point = max_point; + break; + } } let clip_bias = if point.column() == map.line_len(point.row()) {