Skip to content

Commit 59d3916

Browse files
committed
WIP: Chaging approach to how we are modifying thickness and color for dividers
1 parent c286866 commit 59d3916

File tree

4 files changed

+130
-36
lines changed

4 files changed

+130
-36
lines changed

CodeEdit/Features/Editor/Views/EditorLayoutView.swift

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,49 @@ struct EditorLayoutView: View {
4747
}
4848

4949
struct SubEditorLayoutView: View {
50+
@Environment(\.colorScheme)
51+
private var colorScheme
52+
5053
@ObservedObject var data: SplitViewData
5154
@FocusState.Binding var focus: Editor?
5255

56+
@State private var dividerColor: NSColor = .blue
57+
5358
var body: some View {
54-
SplitView(axis: data.axis) {
59+
SplitView(
60+
axis: data.axis,
61+
dividerStyle: .thick(color: dividerColor)
62+
) {
5563
splitView
5664
}
5765
.edgesIgnoringSafeArea([.top, .bottom])
58-
}
59-
60-
func stackContentsView(index: Int, item: EditorLayout) -> some View {
61-
Group {
62-
// Add a divider before the editor if it's not the first
63-
if index != 0 { PanelDivider() }
64-
EditorLayoutView(layout: item, focus: $focus)
65-
.transformEnvironment(\.isAtEdge) { belowToolbar in
66-
calcIsAtEdge(current: &belowToolbar, index: index)
67-
}
68-
.environment(\.splitEditor) { [weak data] edge, newEditor in
69-
data?.split(edge, at: index, new: newEditor)
70-
}
71-
// Add a divider after the editor if it's not the last
72-
if index != data.editorLayouts.count - 1 { PanelDivider() }
66+
.onChange(of: colorScheme) { newValue in
67+
print("ColorScheme changed to: \(newValue == .dark ? "dark" : "light")")
68+
if newValue == .dark {
69+
dividerColor = .red
70+
} else {
71+
dividerColor = .blue
72+
}
73+
}
74+
.onAppear {
75+
print("SubEditorLayoutView appeared with colorScheme: \(colorScheme == .dark ? "dark" : "light")")
76+
if colorScheme == .dark {
77+
dividerColor = .red
78+
} else {
79+
dividerColor = .blue
80+
}
7381
}
7482
}
7583

7684
var splitView: some View {
7785
ForEach(Array(data.editorLayouts.enumerated()), id: \.offset) { index, item in
78-
if data.axis == .horizontal {
79-
HStack(spacing: 0) {
80-
stackContentsView(index: index, item: item)
81-
}
82-
} else {
83-
VStack(spacing: 0) {
84-
stackContentsView(index: index, item: item)
85-
}
86-
}
86+
EditorLayoutView(layout: item, focus: $focus)
87+
.transformEnvironment(\.isAtEdge) { belowToolbar in
88+
calcIsAtEdge(current: &belowToolbar, index: index)
89+
}
90+
.environment(\.splitEditor) { [weak data] edge, newEditor in
91+
data?.split(edge, at: index, new: newEditor)
92+
}
8793
}
8894
}
8995

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// CodeEditDividerStyle.swift
3+
// CodeEdit
4+
//
5+
// Created by Khan Winter on 5/30/25.
6+
//
7+
8+
import AppKit
9+
10+
enum CodeEditDividerStyle: Equatable {
11+
case system(NSSplitView.DividerStyle, color: NSColor? = nil)
12+
case thick(color: NSColor? = nil)
13+
14+
var color: NSColor? {
15+
switch self {
16+
case .system(_, let color):
17+
return color
18+
case .thick(let color):
19+
return color
20+
}
21+
}
22+
}

CodeEdit/Features/SplitView/Views/SplitView.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ import SwiftUI
99

1010
struct SplitView<Content: View>: View {
1111
var axis: Axis
12+
var dividerStyle: CodeEditDividerStyle
1213
var content: Content
1314

14-
init(axis: Axis, @ViewBuilder content: () -> Content) {
15+
init(axis: Axis, dividerStyle: CodeEditDividerStyle = .system(.thin), @ViewBuilder content: () -> Content) {
1516
self.axis = axis
17+
self.dividerStyle = dividerStyle
1618
self.content = content()
1719
}
1820

19-
@State var viewController: () -> SplitViewController? = { nil }
21+
@State private var viewController: () -> SplitViewController? = { nil }
2022

2123
var body: some View {
2224
VStack {
2325
content.variadic { children in
24-
SplitViewControllerView(axis: axis, children: children, viewController: $viewController)
26+
SplitViewControllerView(
27+
axis: axis,
28+
dividerStyle: dividerStyle,
29+
children: children,
30+
viewController: $viewController
31+
)
2532
}
2633
}
2734
._trait(SplitViewControllerLayoutValueKey.self, viewController)

CodeEdit/Features/SplitView/Views/SplitViewControllerView.swift

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ import SwiftUI
1010
struct SplitViewControllerView: NSViewControllerRepresentable {
1111

1212
var axis: Axis
13+
var dividerStyle: CodeEditDividerStyle
1314
var children: _VariadicView.Children
1415
@Binding var viewController: () -> SplitViewController?
1516

1617
func makeNSViewController(context: Context) -> SplitViewController {
17-
context.coordinator
18+
let controller = SplitViewController(axis: axis)
19+
updateItems(controller: controller)
20+
return controller
1821
}
1922

2023
func updateNSViewController(_ controller: SplitViewController, context: Context) {
2124
updateItems(controller: controller)
25+
controller.setDividerStyle(dividerStyle)
2226
}
2327

2428
private func updateItems(controller: SplitViewController) {
@@ -61,40 +65,95 @@ struct SplitViewControllerView: NSViewControllerRepresentable {
6165
}
6266

6367
func makeCoordinator() -> SplitViewController {
64-
SplitViewController(parent: self, axis: axis)
68+
SplitViewController(axis: axis)
6569
}
6670
}
6771

6872
final class SplitViewController: NSSplitViewController {
73+
final class CustomSplitView: NSSplitView {
74+
@Invalidating(.display)
75+
var customDividerStyle: CodeEditDividerStyle = .system(.thin) {
76+
didSet {
77+
switch customDividerStyle {
78+
case .system(let dividerStyle, _):
79+
self.dividerStyle = dividerStyle
80+
case .thick:
81+
return
82+
}
83+
}
84+
}
85+
86+
init() {
87+
super.init(frame: .zero)
88+
dividerStyle = .thin
89+
}
90+
91+
required init?(coder: NSCoder) {
92+
fatalError("init(coder:) has not been implemented")
93+
}
94+
95+
override var dividerColor: NSColor {
96+
if let customColor = customDividerStyle.color {
97+
return customColor
98+
}
99+
100+
switch customDividerStyle {
101+
case .system:
102+
return super.dividerColor
103+
case .thick:
104+
return NSColor.separatorColor
105+
}
106+
}
107+
108+
override var dividerThickness: CGFloat {
109+
switch customDividerStyle {
110+
case .system:
111+
return super.dividerThickness
112+
case .thick:
113+
return 3.0
114+
}
115+
}
116+
}
69117

70118
var items: [SplitViewItem] = []
71119
var axis: Axis
72-
var parentView: SplitViewControllerView
120+
var parentView: SplitViewControllerView?
73121

74-
init(parent: SplitViewControllerView, axis: Axis = .horizontal) {
122+
init(axis: Axis) {
75123
self.axis = axis
76-
self.parentView = parent
77124
super.init(nibName: nil, bundle: nil)
78125
}
79126

80127
required init?(coder: NSCoder) {
81128
fatalError("init(coder:) has not been implemented")
82129
}
83130

131+
override func loadView() {
132+
splitView = CustomSplitView()
133+
super.loadView()
134+
}
135+
84136
override func viewDidLoad() {
137+
super.viewDidLoad()
85138
splitView.isVertical = axis != .vertical
86-
splitView.dividerStyle = .thin
87139
DispatchQueue.main.async { [weak self] in
88-
self?.parentView.viewController = { [weak self] in
140+
self?.parentView?.viewController = { [weak self] in
89141
self
90142
}
91143
}
92144
}
93145

94-
override func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
146+
override func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
95147
false
96148
}
97149

150+
func setDividerStyle(_ dividerStyle: CodeEditDividerStyle) {
151+
guard let splitView = splitView as? CustomSplitView else {
152+
return
153+
}
154+
splitView.customDividerStyle = dividerStyle
155+
}
156+
98157
func collapse(for id: AnyHashable, enabled: Bool) {
99158
items.first { $0.id == id }?.item.animator().isCollapsed = enabled
100159
}

0 commit comments

Comments
 (0)