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())
|
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> {
|
pub fn soft_wrap_indent(&self, display_row: u32) -> Option<u32> {
|
||||||
let wrap_row = self
|
let wrap_row = self
|
||||||
.blocks_snapshot
|
.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 {
|
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
||||||
cursor.seek(&BlockRow(point.row), Bias::Right, &());
|
cursor.seek(&BlockRow(point.row), Bias::Right, &());
|
||||||
|
|
|
@ -33,11 +33,17 @@ pub fn up(
|
||||||
map.column_to_chars(point.row(), point.column())
|
map.column_to_chars(point.row(), point.column())
|
||||||
};
|
};
|
||||||
|
|
||||||
if point.row() > 0 {
|
loop {
|
||||||
*point.row_mut() -= 1;
|
if point.row() > 0 {
|
||||||
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
*point.row_mut() -= 1;
|
||||||
} else {
|
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
||||||
point = DisplayPoint::new(0, 0);
|
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()) {
|
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())
|
map.column_to_chars(point.row(), point.column())
|
||||||
};
|
};
|
||||||
|
|
||||||
if point.row() < max_point.row() {
|
loop {
|
||||||
*point.row_mut() += 1;
|
if point.row() < max_point.row() {
|
||||||
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
*point.row_mut() += 1;
|
||||||
} else {
|
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
||||||
point = max_point;
|
if !map.is_block_line(point.row()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
point = max_point;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let clip_bias = if point.column() == map.line_len(point.row()) {
|
let clip_bias = if point.column() == map.line_len(point.row()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue