From 2893c9bdb705a72636f790b251caae3a000b5650 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 21 Mar 2023 17:52:53 +0100 Subject: [PATCH] Don't move up/down by more rows than the requested ones Co-Authored-By: Max Brunsfeld --- crates/editor/src/movement.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs index 3e5f896564f81a3eea5c3be3152f02a0d7e3b4fe..8685f0709971ac965feac432cbe328c1f2c747fc 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(