Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add smart-opposite resize option #742

Closed
wants to merge 6 commits into from
Closed

Conversation

wesbos
Copy link
Contributor

@wesbos wesbos commented Nov 22, 2024

Fixes #741

I've never worked on a swift app, but it seems like a small add so hopefully this is OK.

Copy link
Owner

@nikitabobko nikitabobko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ping me back when you fix the CI

Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift Outdated Show resolved Hide resolved
Sources/AppBundleTests/command/ResizeCommandTest.swift Outdated Show resolved Hide resolved
Sources/AppBundle/command/impl/ResizeCommand.swift Outdated Show resolved Hide resolved
@nikitabobko
Copy link
Owner

@wesbos
Copy link
Contributor Author

wesbos commented Nov 22, 2024

@nikitabobko Thanks for your help on this - have the CI passing now

@nikitabobko
Copy link
Owner

Thanks, merged with the following patch:

diff --git a/Sources/AppBundle/command/impl/ResizeCommand.swift b/Sources/AppBundle/command/impl/ResizeCommand.swift
index 0bd64498..cd7e5905 100644
--- a/Sources/AppBundle/command/impl/ResizeCommand.swift
+++ b/Sources/AppBundle/command/impl/ResizeCommand.swift
@@ -32,10 +32,11 @@ struct ResizeCommand: Command { // todo cover with tests
                 parent = first.parent as! TilingContainer
                 orientation = parent.orientation
             case .smartOpposite:
-                guard let first = candidates.first else { return false }
+                guard let _orientation = (candidates.first?.parent as? TilingContainer)?.orientation.opposite else { return false }
+                orientation = _orientation
+                guard let first = candidates.first(where: { ($0.parent as! TilingContainer).orientation == orientation }) else { return false }
                 node = first
                 parent = first.parent as! TilingContainer
-                orientation = parent.orientation.opposite
         }
         let diff: CGFloat = switch args.units.val {
             case .set(let unit): CGFloat(unit) - node.getWeight(orientation)

otherwise the code crashes.

Please next time always run your code before submitting it, even if it looks trivial

@nikitabobko nikitabobko added the pr-accepted Pull Request is accepted label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-accepted Pull Request is accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resize: Opposite of Smart
2 participants