Skip to content

Commit 7ce5990

Browse files
committed
fixed terminal behavior
1 parent 4393b88 commit 7ce5990

File tree

5 files changed

+69
-42
lines changed

5 files changed

+69
-42
lines changed

CodeEdit/Documents/WorkspaceCodeFileView.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ struct WorkspaceCodeFileView: View {
1414
var windowController: NSWindowController
1515
@ObservedObject var workspace: WorkspaceDocument
1616

17-
@ViewBuilder var codeView: some View {
17+
@ViewBuilder
18+
var codeView: some View {
1819
if let item = workspace.selectionState.openFileItems.first(where: { file in
1920
if file.id == workspace.selectionState.selectedId {
2021
print("Item loaded is: ", file.url)
@@ -30,11 +31,6 @@ struct WorkspaceCodeFileView: View {
3031
BreadcrumbsView(item, workspace: workspace)
3132
}
3233
}
33-
.safeAreaInset(edge: .bottom) {
34-
if let url = workspace.fileURL {
35-
StatusBarView(workspaceURL: url)
36-
}
37-
}
3834
} else {
3935
Text("CodeEdit cannot open this file because its file type is not supported.")
4036
}
@@ -44,12 +40,7 @@ struct WorkspaceCodeFileView: View {
4440
}
4541

4642
var body: some View {
47-
HSplitView {
48-
codeView
49-
.frame(maxWidth: .infinity, maxHeight: .infinity)
50-
51-
InspectorSidebar(workspace: workspace, windowController: windowController)
52-
.frame(minWidth: 250, maxWidth: 250, maxHeight: .infinity)
53-
}
43+
codeView
44+
.frame(maxWidth: .infinity, maxHeight: .infinity)
5445
}
5546
}

CodeEdit/WorkspaceView.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import SwiftUI
99
import WorkspaceClient
10+
import StatusBar
1011

1112
struct WorkspaceView: View {
1213
init(windowController: NSWindowController, workspace: WorkspaceDocument) {
@@ -28,10 +29,7 @@ struct WorkspaceView: View {
2829
var body: some View {
2930
NavigationView {
3031
if workspace.workspaceClient != nil {
31-
LeadingSidebar(workspace: workspace, windowController: windowController)
32-
.frame(minWidth: 250)
33-
WorkspaceCodeFileView(windowController: windowController,
34-
workspace: workspace)
32+
content
3533
} else {
3634
EmptyView()
3735
}
@@ -49,6 +47,25 @@ struct WorkspaceView: View {
4947
}
5048
}
5149
}
50+
51+
@ViewBuilder
52+
private var content: some View {
53+
LeadingSidebar(workspace: workspace, windowController: windowController)
54+
.frame(minWidth: 250)
55+
HSplitView {
56+
ZStack {
57+
WorkspaceCodeFileView(windowController: windowController,
58+
workspace: workspace)
59+
}
60+
.safeAreaInset(edge: .bottom) {
61+
if let url = workspace.fileURL {
62+
StatusBarView(workspaceURL: url)
63+
}
64+
}
65+
InspectorSidebar(workspace: workspace, windowController: windowController)
66+
.frame(minWidth: 250, maxWidth: 250, maxHeight: .infinity)
67+
}
68+
}
5269
}
5370

5471
struct WorkspaceView_Previews: PreviewProvider {

CodeEditModules/Modules/StatusBar/src/StatusBar.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public struct StatusBarView: View {
3131
public var body: some View {
3232
VStack(spacing: 0) {
3333
bar
34-
StatusBarDrawer(model: model)
34+
if model.isExpanded {
35+
StatusBarDrawer(model: model)
36+
.transition(.move(edge: .bottom))
37+
}
3538
}
3639
// removes weird light gray bar above when in light mode
3740
.padding(.top, -8) // (comment out to make it look normal in preview)
@@ -63,6 +66,11 @@ public struct StatusBarView: View {
6366
.overlay(alignment: .top) {
6467
Divider()
6568
}
69+
.overlay(alignment: .bottom) {
70+
if model.isExpanded {
71+
Divider()
72+
}
73+
}
6674
.frame(height: 32)
6775
.gesture(dragGesture)
6876
.onHover { isHovering($0, isDragging: model.isDragging, cursor: .resizeUpDown) }

CodeEditModules/Modules/TerminalEmulator/src/TerminalEmulatorView+Coordinator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public extension TerminalEmulatorView {
2525
}
2626
source.feed(text: "Exit code: \(exitCode)\n\r\n")
2727
source.feed(text: "To restart please close and reopen this file")
28+
TerminalEmulatorView.lastTerminal = nil
2829
}
2930
}
3031
}

CodeEditModules/Modules/TerminalEmulator/src/TerminalEmulatorView.swift

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct TerminalEmulatorView: NSViewRepresentable {
2525
@StateObject private var ansiColors: AnsiColors = .shared
2626

2727
// TODO: Persist this to not get a new terminal each time you switch file
28-
private static var lastTerminal: LocalProcessTerminalView?
28+
internal static var lastTerminal: LocalProcessTerminalView?
2929
@State internal var terminal: LocalProcessTerminalView
3030

3131
private let systemFont: NSFont = .monospacedSystemFont(ofSize: 11, weight: .medium)
@@ -104,36 +104,46 @@ public struct TerminalEmulatorView: NSViewRepresentable {
104104
/// Inherited from NSViewRepresentable.makeNSView(context:).
105105
public func makeNSView(context: Context) -> LocalProcessTerminalView {
106106
terminal.processDelegate = context.coordinator
107+
setupSession()
108+
return terminal
109+
}
107110

108-
let shell = getShell()
109-
let shellIdiom = "-" + NSString(string: shell).lastPathComponent
110-
111-
// changes working directory to project root
112-
// TODO: Get rid of FileManager shared instance to prevent problems
113-
// using shared instance of FileManager might lead to problems when using
114-
// multiple workspaces. This works for now but most probably will need
115-
// to be changed later on
116-
FileManager.default.changeCurrentDirectoryPath(url.path)
117-
terminal.startProcess(executable: shell, execName: shellIdiom)
118-
terminal.font = font
119-
terminal.configureNativeColors()
120-
terminal.installColors(self.appearanceColors)
111+
public func setupSession() {
112+
if TerminalEmulatorView.lastTerminal == nil {
113+
let shell = getShell()
114+
let shellIdiom = "-" + NSString(string: shell).lastPathComponent
115+
116+
// changes working directory to project root
117+
// TODO: Get rid of FileManager shared instance to prevent problems
118+
// using shared instance of FileManager might lead to problems when using
119+
// multiple workspaces. This works for now but most probably will need
120+
// to be changed later on
121+
FileManager.default.changeCurrentDirectoryPath(url.path)
122+
terminal.startProcess(executable: shell, execName: shellIdiom)
123+
terminal.font = font
124+
terminal.configureNativeColors()
125+
terminal.installColors(self.appearanceColors)
126+
}
121127
TerminalEmulatorView.lastTerminal = terminal
122-
return terminal
123128
}
124129

125130
public func updateNSView(_ view: LocalProcessTerminalView, context: Context) {
126131
print("Update view")
127-
// if view.font != font { // Fixes Memory leak
128-
// TODO: Fix memory leak
129-
// for some reason setting the font here causes a memory leak.
130-
// I'll leave it for now since the colors won't change
131-
// without setting the font which is weird
132-
view.font = font
133-
// }
134-
// view.configureNativeColors()
132+
// if exited {
133+
// setupSession()
134+
// }
135+
// // if view.font != font { // Fixes Memory leak
136+
// // TODO: Fix memory leak
137+
// // for some reason setting the font here causes a memory leak.
138+
// // I'll leave it for now since the colors won't change
139+
// // without setting the font which is weird
140+
// view.font = font
141+
// // }
142+
view.configureNativeColors()
135143
view.installColors(self.appearanceColors)
136-
TerminalEmulatorView.lastTerminal = view
144+
if TerminalEmulatorView.lastTerminal != nil {
145+
TerminalEmulatorView.lastTerminal = view
146+
}
137147
}
138148

139149
public func makeCoordinator() -> Coordinator {

0 commit comments

Comments
 (0)