From 55038b7c07e9a7c08fca39793c5c4602e7099a0c Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 29 Feb 2024 08:30:46 +0400 Subject: Pass prev_idx explicitly to animate_view_offset_to_column() --- src/layout/workspace.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index fce5719d..2b0b0823 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -459,14 +459,24 @@ impl Workspace { self.animate_view_offset(current_x, idx, new_view_offset); } - fn animate_view_offset_to_column(&mut self, current_x: i32, idx: usize) { + fn animate_view_offset_to_column( + &mut self, + current_x: i32, + idx: usize, + prev_idx: Option, + ) { match self.options.center_focused_column { CenterFocusedColumn::Always => { self.animate_view_offset_to_column_centered(current_x, idx) } CenterFocusedColumn::OnOverflow => { + let Some(prev_idx) = prev_idx else { + self.animate_view_offset_to_column_fit(current_x, idx); + return; + }; + // Always take the left or right neighbor of the target as the source. - let source_idx = if self.active_column_idx > idx { + let source_idx = if prev_idx > idx { min(idx + 1, self.columns.len() - 1) } else { idx.saturating_sub(1) @@ -503,7 +513,7 @@ impl Workspace { } let current_x = self.view_pos(); - self.animate_view_offset_to_column(current_x, idx); + self.animate_view_offset_to_column(current_x, idx, Some(self.active_column_idx)); self.active_column_idx = idx; @@ -770,13 +780,9 @@ impl Workspace { // We might need to move the view to ensure the resized window is still visible. let current_x = self.view_pos(); - if self.options.center_focused_column == CenterFocusedColumn::Always { - // FIXME: we will want to skip the animation in some cases here to make - // continuously resizing windows not look janky. - self.animate_view_offset_to_column_centered(current_x, idx); - } else { - self.animate_view_offset_to_column_fit(current_x, idx); - } + // FIXME: we will want to skip the animation in some cases here to make continuously + // resizing windows not look janky. + self.animate_view_offset_to_column(current_x, idx, None); } } -- cgit