Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 2, 2023
1 parent 152ba47 commit 5a0cd65
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/command/FocusCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct FocusCommand: Command { // todo speed up. Now it's slightly slow (probabl
guard let index = topMostChild.ownIndexOrNil else { return }
let mruIndexMap = currentWindow.workspace.mruWindows.mruIndexMap
let windowToFocus: Window? = parent.children
.getOrNil(atIndex: index + direction.offset)?
.getOrNil(atIndex: index + direction.focusOffset)?
.allLeafWindowsRecursive(snappedTo: direction.opposite)
.minBy { mruIndexMap[$0] ?? Int.max }
windowToFocus?.focus()
Expand Down
8 changes: 4 additions & 4 deletions src/command/MoveThroughCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct MoveThroughCommand: Command {
guard let currentWindow = focusedWindowOrEffectivelyFocused else { return }
if let parent = currentWindow.parent as? TilingContainer {
let indexOfCurrent = currentWindow.ownIndex
let indexOfSiblingTarget = indexOfCurrent + direction.offset
let indexOfSiblingTarget = indexOfCurrent + direction.focusOffset
if parent.orientation == direction.orientation && parent.children.indices.contains(indexOfSiblingTarget) {
switch parent.children[indexOfSiblingTarget].kind {
case .tilingContainer(let topLevelSiblingTargetContainer):
Expand Down Expand Up @@ -68,7 +68,7 @@ private func deepMoveIn(window: Window, into container: TilingContainer, moveDir
.drop(while: { $0 != container })
.dropFirst()
.toArray()
let deepTarget = container.findContainerWithOrientOrPreferredPath(moveDirection.orientation, preferredPath)
let deepTarget = container.findDeepMoveInTargetRecursive(moveDirection.orientation, preferredPath)
switch deepTarget.kind {
case .tilingContainer:
window.unbindFromParent()
Expand All @@ -86,7 +86,7 @@ private func deepMoveIn(window: Window, into container: TilingContainer, moveDir
}

private extension TreeNode {
func findContainerWithOrientOrPreferredPath(_ orientation: Orientation, _ preferredPath: [TreeNode]) -> TreeNode {
func findDeepMoveInTargetRecursive(_ orientation: Orientation, _ preferredPath: [TreeNode]) -> TreeNode {
switch kind {
case .window:
return self
Expand All @@ -96,7 +96,7 @@ private extension TreeNode {
} else {
assert(children.contains(preferredPath.first!))
return preferredPath.first!
.findContainerWithOrientOrPreferredPath(orientation, Array(preferredPath.dropFirst()))
.findDeepMoveInTargetRecursive(orientation, Array(preferredPath.dropFirst()))
}
case .workspace:
error("Impossible")
Expand Down
7 changes: 4 additions & 3 deletions src/tree/TreeNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TreeNode: Equatable {
if let window = self as? Window {
let newParentWorkspace = newParent.workspace
newParentWorkspace.mruWindows.pushOrRaise(window)
newParentWorkspace.assignedMonitor = window.getCenter()?.monitorApproximation
newParentWorkspace.assignedMonitor = window.getCenter()?.monitorApproximation // todo here we may write nil
// Update currentEmptyWorkspace since it's no longer effectively empty
if newParentWorkspace == currentEmptyWorkspace {
currentEmptyWorkspace = getOrCreateNextEmptyWorkspace()
Expand All @@ -106,8 +106,9 @@ class TreeNode: Equatable {
guard let _parent else { return nil }
let workspace = workspace
if let window = self as? Window {
precondition(workspace.mruWindows.remove(window)) /* todo lock screen -> false assert (for some reasons
all windows are placed into current active workspace) */
// todo lock screen -> false assert (for some reasons all windows are placed into current active workspace)
// todo chrome close "cmd F" window with esc -> false assert
precondition(workspace.mruWindows.remove(window), "mru.remove \(window.title)")
}

let index = _parent._children.remove(element: self) ?? errorT("Can't find child in its parent")
Expand Down
2 changes: 1 addition & 1 deletion src/util/CardinalDirection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ extension CardinalDirection {
return .left
}
}
var offset: Int { isPositive ? 1 : -1 }
var focusOffset: Int { isPositive ? 1 : -1 }
var insertionOffset: Int { isPositive ? 1 : 0 }
}

0 comments on commit 5a0cd65

Please sign in to comment.