From 263afc4d59f72ce89e0d7105e53e1755154dd516 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 18 Sep 2023 08:53:38 -0600 Subject: [PATCH] clip FoldPoint earlier (#2982) fold_point_to_display_point calls to_offset on the fold point, which panics if it hasn't been clipped. https://zed-industries.slack.com/archives/C04S6T1T7TQ/p1694850156370919 Release Notes: - vim: Fix a crash when moving up/down in some circumstances. --- crates/vim/src/motion.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 3e65e6d504c6a3de90fcc06f84155315f4025eb8..08256bffb1d761221ab7ce3821d5b28a292c8a83 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -536,8 +536,12 @@ fn down( map.buffer_snapshot.max_point().row, ); let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row)); - let point = map.fold_point_to_display_point(FoldPoint::new(new_row, new_col)); + let point = map.fold_point_to_display_point( + map.fold_snapshot + .clip_point(FoldPoint::new(new_row, new_col), Bias::Left), + ); + // clip twice to "clip at end of line" (map.clip_point(point, Bias::Left), goal) } @@ -573,7 +577,10 @@ pub(crate) fn up( let new_row = start.row().saturating_sub(times as u32); let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row)); - let point = map.fold_point_to_display_point(FoldPoint::new(new_row, new_col)); + let point = map.fold_point_to_display_point( + map.fold_snapshot + .clip_point(FoldPoint::new(new_row, new_col), Bias::Left), + ); (map.clip_point(point, Bias::Left), goal) }