Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(domain): insert moving container at correct index in `MoveFocusedWindowHandler`

Lars Berger7b01fdc246f1
diff --git a/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs b/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
index b82da349..ebcdd1ac 100644
--- a/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
+++ b/LarsWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs
@@ -64,14 +64,16 @@ namespace LarsWM.Domain.Windows.CommandHandlers
return CommandResponse.Ok;
}
- // Insert container into `ancestorWithLayout` at start or end.
- // TODO: Should actually traverse up from `focusedWindow` to find container where the parent
- // is `ancestorWithLayout`. Then, depending on direction, insert before or after that container.
- // TODO: Consider changing `InsertPosition` to an int, and set the default to `Siblings.Count - 1`.
+ // Traverse up from `focusedWindow` to find container where the parent is `ancestorWithLayout`. Then,
+ // depending on the direction, insert before or after that container.
+ var insertionIndex = focusedWindow.TraverseUpEnumeration()
+ .FirstOrDefault(container => container.Parent == ancestorWithLayout)
+ .Index;
+
if (direction == Direction.UP || direction == Direction.LEFT)
- _bus.Invoke(new AttachContainerCommand(ancestorWithLayout, focusedWindow));
+ _bus.Invoke(new AttachContainerCommand(ancestorWithLayout, focusedWindow, insertionIndex));
else
- _bus.Invoke(new AttachContainerCommand(ancestorWithLayout, focusedWindow, InsertPosition.START));
+ _bus.Invoke(new AttachContainerCommand(ancestorWithLayout, focusedWindow, insertionIndex + 1));
_bus.Invoke(new RedrawContainersCommand());