Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Don't move up/down by more rows than the requested ones

Antonio Scandurra2893c9bdb705
diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs
index 3e5f896564f..8685f070997 100644
--- a/crates/editor/src/movement.rs
+++ b/crates/editor/src/movement.rs
@@ -69,16 +69,11 @@ pub fn up_by_rows(
goal_column = 0;
}
- let clip_bias = if point.column() == map.line_len(point.row()) {
- Bias::Left
- } else {
- Bias::Right
- };
-
- (
- map.clip_point(point, clip_bias),
- SelectionGoal::Column(goal_column),
- )
+ let mut clipped_point = map.clip_point(point, Bias::Left);
+ if clipped_point.row() < point.row() {
+ clipped_point = map.clip_point(point, Bias::Right);
+ }
+ (clipped_point, SelectionGoal::Column(goal_column))
}
pub fn down_by_rows(
@@ -105,16 +100,11 @@ pub fn down_by_rows(
goal_column = map.column_to_chars(point.row(), point.column())
}
- let clip_bias = if point.column() == map.line_len(point.row()) {
- Bias::Left
- } else {
- Bias::Right
- };
-
- (
- map.clip_point(point, clip_bias),
- SelectionGoal::Column(goal_column),
- )
+ let mut clipped_point = map.clip_point(point, Bias::Right);
+ if clipped_point.row() > point.row() {
+ clipped_point = map.clip_point(point, Bias::Left);
+ }
+ (clipped_point, SelectionGoal::Column(goal_column))
}
pub fn line_beginning(