Skip block lines when moving up and down

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-11-18 13:45:06 +01:00
parent 856768a43c
commit 0f1eb3dd2e
3 changed files with 32 additions and 10 deletions

View file

@ -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<u32> {
let wrap_row = self
.blocks_snapshot

View file

@ -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, &());

View file

@ -33,11 +33,17 @@ pub fn up(
map.column_to_chars(point.row(), point.column())
};
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())
};
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()) {