mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 22:34:13 +00:00
Skip block lines when moving up and down
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
856768a43c
commit
0f1eb3dd2e
3 changed files with 32 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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, &());
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue