layout: Extract move_column_to()
Browse files at this commit310aa2b464d22a9b43309f237d2b3732eee03d77Parent: d6c55301 changed file +7 -14
- src/layout/workspace.rs +7 -14
src/layout/workspace.rsmodified+7 -14
| @@ -645,8 +645,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 645 | self.columns[self.active_column_idx].focus_up(); | 645 | self.columns[self.active_column_idx].focus_up(); |
| 646 | } | 646 | } |
| 647 | 647 | ||
| 648 | - pub fn move_left(&mut self) { | 648 | + fn move_column_to(&mut self, new_idx: usize) { |
| 649 | - let new_idx = self.active_column_idx.saturating_sub(1); | ||
| 650 | if self.active_column_idx == new_idx { | 649 | if self.active_column_idx == new_idx { |
| 651 | return; | 650 | return; |
| 652 | } | 651 | } |
| @@ -661,24 +660,18 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 661 | self.activate_column(new_idx); | 660 | self.activate_column(new_idx); |
| 662 | } | 661 | } |
| 663 | 662 | ||
| 663 | + pub fn move_left(&mut self) { | ||
| 664 | + let new_idx = self.active_column_idx.saturating_sub(1); | ||
| 665 | + self.move_column_to(new_idx); | ||
| 666 | + } | ||
| 667 | + | ||
| 664 | pub fn move_right(&mut self) { | 668 | pub fn move_right(&mut self) { |
| 665 | if self.columns.is_empty() { | 669 | if self.columns.is_empty() { |
| 666 | return; | 670 | return; |
| 667 | } | 671 | } |
| 668 | 672 | ||
| 669 | let new_idx = min(self.active_column_idx + 1, self.columns.len() - 1); | 673 | let new_idx = min(self.active_column_idx + 1, self.columns.len() - 1); |
| 670 | - if self.active_column_idx == new_idx { | 674 | + self.move_column_to(new_idx); |
| 671 | - return; | ||
| 672 | - } | ||
| 673 | - | ||
| 674 | - let current_x = self.view_pos(); | ||
| 675 | - | ||
| 676 | - self.columns.swap(self.active_column_idx, new_idx); | ||
| 677 | - | ||
| 678 | - self.view_offset = | ||
| 679 | - self.compute_new_view_offset_for_column(current_x, self.active_column_idx); | ||
| 680 | - | ||
| 681 | - self.activate_column(new_idx); | ||
| 682 | } | 675 | } |
| 683 | 676 | ||
| 684 | pub fn move_down(&mut self) { | 677 | pub fn move_down(&mut self) { |