Swap active split panes
This commit is contained in:
@@ -109,6 +109,30 @@ impl SplitLayout {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn swap_tab_with_previous(&mut self, tab_id: &TabId) -> bool {
|
||||
let Some(index) = self.pane_index(tab_id) else {
|
||||
return false;
|
||||
};
|
||||
if index == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.panes.swap(index - 1, index);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn swap_tab_with_next(&mut self, tab_id: &TabId) -> bool {
|
||||
let Some(index) = self.pane_index(tab_id) else {
|
||||
return false;
|
||||
};
|
||||
if index + 1 >= self.panes.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.panes.swap(index, index + 1);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn remove_tab(&mut self, tab_id: &TabId) -> bool {
|
||||
let original_len = self.panes.len();
|
||||
self.panes.retain(|pane| pane.tab_id() != tab_id);
|
||||
@@ -119,4 +143,8 @@ impl SplitLayout {
|
||||
self.title = title.into();
|
||||
self.saved = true;
|
||||
}
|
||||
|
||||
fn pane_index(&self, tab_id: &TabId) -> Option<usize> {
|
||||
self.panes.iter().position(|pane| pane.tab_id() == tab_id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user