From 1a7d1a4cf229ada16cd8dbb40c44fc545d00cb26 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 22 Nov 2025 12:59:35 -0800 Subject: [PATCH] fix(wm): promoting a container shouldn't change resize dimensions This commit was originally contributed as 31c969f to LGUG2Z/komorebi by @alex-ds13 - When promoting a container it is using the `remove_focused_container()` and `insert_container_at_idx` functions which will remove the focused container size from `resize_dimensions` and then add the new container with size `None`. Then it was adding the previously stored size of the main container back to the first one. However this would result in at least 3 issues: 1. We were removing the size from index 0, however when inserting it back on the primary_idx we might not add it to index 0, specially now that there could be locked containers so if container 0 is locked we would be adding it to the next container, which would result in the main container having no size information which would result in a recalculation on the next update and it would revert back to default, so if a user had resized their containers that information would be lost. 2. We were removing the size from index 0. Then on `remove_focused_container` it would remove the size from the focused container index, but since we had already removed one size from the `resize_dimensions` that index would no longer match the actual focused container, so once again we would be losing information. 3. Since we were removing the size of the focused container idx from `resize_dimensions` (albeit the wrong one as stated above), this would mean that the container that moved to that position would have no resize information so it would show up as if the main container was taking up half width of the area, ignoring any user resize, until the next workspace update was triggered. - This commit completely ignores the `resize_dimensions` since promoting a container simply means moving one container from one position to the main one (usually index 0) and then shift all the rest to the "right". The existing `resize_dimensions` should be kept untouched. To do this we use the functions `remove_respecting_locks` and `insert_respecting_locks` on the containers themselves, which simply move the container and shifts the others which is precisely what we want. --- komorebi/src/workspace.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 09852097..37a8ecf3 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -821,18 +821,20 @@ impl Workspace { } pub fn promote_container(&mut self) -> eyre::Result<()> { - let resize = self.resize_dimensions.remove(0); + let focused_idx = self.focused_container_idx(); let container = self - .remove_focused_container() + .containers_mut() + .remove_respecting_locks(focused_idx) .ok_or_eyre("there is no container")?; - let primary_idx = match self.layout { + let primary_idx = match &self.layout { Layout::Default(_) => 0, }; - let insertion_idx = self.insert_container_at_idx(primary_idx, container); - self.resize_dimensions[insertion_idx] = resize; - self.focus_container(primary_idx); + let insertion_idx = self + .containers_mut() + .insert_respecting_locks(primary_idx, container); + self.focus_container(insertion_idx); Ok(()) }