mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-05 20:51:42 +02:00
refactor(workspace): extract fns for container focusing
This commit is contained in:
+17
-15
@@ -303,7 +303,7 @@ impl Workspace {
|
|||||||
|
|
||||||
pub fn add_container(&mut self, container: Container) {
|
pub fn add_container(&mut self, container: Container) {
|
||||||
self.containers_mut().push_back(container);
|
self.containers_mut().push_back(container);
|
||||||
self.focus_container(self.containers().len() - 1);
|
self.focus_last_container();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_container_by_idx(&mut self, idx: usize) -> Option<Container> {
|
fn remove_container_by_idx(&mut self, idx: usize) -> Option<Container> {
|
||||||
@@ -358,9 +358,7 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if container_idx != 0 {
|
self.focus_previous_container();
|
||||||
self.focus_container(container_idx - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -368,10 +366,7 @@ impl Workspace {
|
|||||||
pub fn remove_focused_container(&mut self) -> Option<Container> {
|
pub fn remove_focused_container(&mut self) -> Option<Container> {
|
||||||
let focused_idx = self.focused_container_idx();
|
let focused_idx = self.focused_container_idx();
|
||||||
let container = self.remove_container_by_idx(focused_idx);
|
let container = self.remove_container_by_idx(focused_idx);
|
||||||
|
self.focus_previous_container();
|
||||||
if focused_idx != 0 {
|
|
||||||
self.focus_container(focused_idx - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
container
|
container
|
||||||
}
|
}
|
||||||
@@ -560,10 +555,7 @@ impl Workspace {
|
|||||||
|
|
||||||
self.set_monocle_container(Option::from(container));
|
self.set_monocle_container(Option::from(container));
|
||||||
self.set_monocle_container_restore_idx(Option::from(focused_idx));
|
self.set_monocle_container_restore_idx(Option::from(focused_idx));
|
||||||
|
self.focus_previous_container();
|
||||||
if focused_idx != 0 {
|
|
||||||
self.focus_container(focused_idx - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.monocle_container_mut()
|
self.monocle_container_mut()
|
||||||
.as_mut()
|
.as_mut()
|
||||||
@@ -626,9 +618,7 @@ impl Workspace {
|
|||||||
window.maximize();
|
window.maximize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if focused_idx != 0 {
|
self.focus_previous_container();
|
||||||
self.focus_container(focused_idx - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -716,4 +706,16 @@ impl Workspace {
|
|||||||
|
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn focus_previous_container(&mut self) {
|
||||||
|
let focused_idx = self.focused_container_idx();
|
||||||
|
|
||||||
|
if focused_idx != 0 {
|
||||||
|
self.focus_container(focused_idx - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn focus_last_container(&mut self) {
|
||||||
|
self.focus_container(self.containers().len() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user