From c30fcf9691bb967fff665c53fe7117fcbfd4a6c7 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Sun, 29 Oct 2023 16:15:57 +0100 Subject: [PATCH] Fix LayoutCommand --- docs/commands.md | 4 ++-- src/command/LayoutCommand.swift | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index c7ee9cfc..d7d31fd7 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -89,8 +89,8 @@ layout (h_list|v_list|h_accordion|v_accordion|list|accordion|horizontal|vertical Changes layout of the focused window to the given layout. -If several arguments are supplied then the first layout that describes the currently active is found. The layout specified after -the found one will be applied. If the currently active layout is not in the list, the first layout in the list will be activated. +If several layouts are supplied then finds the first layout that doesn't describe the currently active layout, and applies the +found layout. `layout tiling` is the only command that makes the focused floating window tiled. diff --git a/src/command/LayoutCommand.swift b/src/command/LayoutCommand.swift index dc14dbd5..c8102ff3 100644 --- a/src/command/LayoutCommand.swift +++ b/src/command/LayoutCommand.swift @@ -18,9 +18,8 @@ struct LayoutCommand: Command { func runWithoutLayout() { check(Thread.current.isMainThread) guard let window = focusedWindowOrEffectivelyFocused else { return } - let targetDescription: LayoutDescription = toggleBetween.firstIndex(where: { window.matchesDescription($0) }) - .flatMap { toggleBetween.getOrNil(atIndex: $0 + 1) } - .orElse { toggleBetween.first! } + let targetDescription: LayoutDescription = toggleBetween.first(where: { !window.matchesDescription($0) }) + ?? toggleBetween.first! if window.matchesDescription(targetDescription) { return }