From 10d45d6cc3b15fa2b8baed526efea281033b2f8c Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 9 Jan 2025 12:50:52 -0500 Subject: [PATCH] move column Signed-off-by: kernelkind --- crates/notedeck_columns/src/column.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/notedeck_columns/src/column.rs b/crates/notedeck_columns/src/column.rs index 9756417..c61c2fe 100644 --- a/crates/notedeck_columns/src/column.rs +++ b/crates/notedeck_columns/src/column.rs @@ -211,6 +211,25 @@ impl Columns { self.new_column_picker(); } } + + pub fn move_col(&mut self, from_index: usize, to_index: usize) { + if from_index == to_index + || from_index >= self.columns.len() + || to_index >= self.columns.len() + { + return; + } + + if from_index < to_index { + for i in from_index..to_index { + self.columns.swap_indices(i, i + 1); + } + } else { + for i in (to_index..from_index).rev() { + self.columns.swap_indices(i, i + 1); + } + } + } } pub enum IntermediaryRoute {