Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Sources/Bonsplit/Internal/Controllers/SplitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ final class SplitViewController {
}

/// Split a pane with a specific tab, optionally inserting the new pane first
func splitPaneWithTab(_ paneId: PaneID, orientation: SplitOrientation, tab: TabItem, insertFirst: Bool) {
func splitPaneWithTab(_ paneId: PaneID, orientation: SplitOrientation, tab: TabItem, insertFirst: Bool, animate: Bool = true) {
clearPaneZoom()
rootNode = splitNodeWithTabRecursively(
node: rootNode,
targetPaneId: paneId,
orientation: orientation,
tab: tab,
insertFirst: insertFirst
insertFirst: insertFirst,
animate: animate
)
}

Expand All @@ -197,7 +198,8 @@ final class SplitViewController {
targetPaneId: PaneID,
orientation: SplitOrientation,
tab: TabItem,
insertFirst: Bool
insertFirst: Bool,
animate: Bool
) -> SplitNode {
switch node {
case .pane(let paneState):
Expand All @@ -214,7 +216,7 @@ final class SplitViewController {
first: .pane(newPane),
second: .pane(paneState),
dividerPosition: 0.5,
animationOrigin: .fromFirst
animationOrigin: animate ? .fromFirst : nil
)
} else {
// New pane goes second (right or bottom).
Expand All @@ -223,7 +225,7 @@ final class SplitViewController {
first: .pane(paneState),
second: .pane(newPane),
dividerPosition: 0.5,
animationOrigin: .fromSecond
animationOrigin: animate ? .fromSecond : nil
)
}

Expand All @@ -240,14 +242,16 @@ final class SplitViewController {
targetPaneId: targetPaneId,
orientation: orientation,
tab: tab,
insertFirst: insertFirst
insertFirst: insertFirst,
animate: animate
)
splitState.second = splitNodeWithTabRecursively(
node: splitState.second,
targetPaneId: targetPaneId,
orientation: orientation,
tab: tab,
insertFirst: insertFirst
insertFirst: insertFirst,
animate: animate
)
return .split(splitState)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Bonsplit/Internal/Views/TabBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ struct TabBarView: View {
dlog("tab.close pane=\(pane.id.id.uuidString.prefix(5)) tab=\(tab.id.uuidString.prefix(5)) title=\"\(tab.title)\"")
#endif
withTransaction(Transaction(animation: nil)) {
controller.onTabCloseRequest?(TabID(id: tab.id), pane.id)
_ = controller.closeTab(TabID(id: tab.id), inPane: pane.id)
}
},
Expand Down
11 changes: 9 additions & 2 deletions Sources/Bonsplit/Public/BonsplitController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public final class BonsplitController {
/// Return `true` when the drop has been handled by the host application.
@ObservationIgnored public var onExternalTabDrop: ((ExternalTabDropRequest) -> Bool)?

/// Called when the user explicitly requests to close a tab from the tab strip UI.
/// Internal host-driven closes should not use this hook.
@ObservationIgnored public var onTabCloseRequest: ((_ tabId: TabID, _ paneId: PaneID) -> Void)?

// MARK: - Internal State

internal var internalController: SplitViewController
Expand Down Expand Up @@ -410,13 +414,15 @@ public final class BonsplitController {
/// - orientation: Direction to split (horizontal = side-by-side, vertical = stacked).
/// - tab: The tab to add to the new pane.
/// - insertFirst: If true, insert the new pane first (left/top). Otherwise insert second (right/bottom).
/// - animate: If true (default), the new pane slides in with an entry animation. Pass false to skip animation (e.g. during session restore).
/// - Returns: The new pane ID, or nil if vetoed by delegate.
@discardableResult
public func splitPane(
_ paneId: PaneID? = nil,
orientation: SplitOrientation,
withTab tab: Tab,
insertFirst: Bool
insertFirst: Bool,
animate: Bool = true
) -> PaneID? {
guard configuration.allowSplits else { return nil }

Expand Down Expand Up @@ -446,7 +452,8 @@ public final class BonsplitController {
PaneID(id: targetPaneId.id),
orientation: orientation,
tab: internalTab,
insertFirst: insertFirst
insertFirst: insertFirst,
animate: animate
)

let newPaneId = focusedPaneId!
Expand Down