Skip to content

Commit 56dd09e

Browse files
committed
Correctly Sync the Active File
1 parent 68abe9e commit 56dd09e

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

CodeEdit/Features/Editor/JumpBar/Views/EditorJumpBarView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ struct EditorJumpBarView: View {
2121
@Environment(\.controlActiveState)
2222
private var activeState
2323

24+
@Binding var codeFile: CodeFileDocument?
25+
2426
static let height = 28.0
2527

2628
init(
2729
file: CEWorkspaceFile?,
2830
shouldShowTabBar: Bool,
31+
codeFile: Binding<CodeFileDocument?>,
2932
tappedOpenFile: @escaping (CEWorkspaceFile) -> Void
3033
) {
3134
self.file = file ?? nil
3235
self.shouldShowTabBar = shouldShowTabBar
36+
self._codeFile = codeFile
3337
self.tappedOpenFile = tappedOpenFile
3438
}
3539

@@ -75,7 +79,7 @@ struct EditorJumpBarView: View {
7579
}
7680
.safeAreaInset(edge: .trailing, spacing: 0) {
7781
if !shouldShowTabBar {
78-
EditorTabBarTrailingAccessories()
82+
EditorTabBarTrailingAccessories(codeFile: $codeFile)
7983
}
8084
}
8185
.frame(height: Self.height, alignment: .center)

CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ struct EditorTabBarTrailingAccessories: View {
2626

2727
@EnvironmentObject private var editor: Editor
2828

29-
/// Because this view isn't invalidated with the `editor.selectedTab?.file.fileDocument` changes, this allows us
30-
/// to refresh relevant views when settings change.
31-
@State private var refreshToggleBool: Bool = false
29+
@Binding var codeFile: CodeFileDocument?
3230

3331
var body: some View {
3432
HStack(spacing: 6) {
3533
// Once more options are implemented that are available for non-code documents, remove this if statement
36-
if let codeFile = editor.selectedTab?.file.fileDocument {
34+
if let codeFile {
3735
editorOptionsMenu(codeFile: codeFile)
3836
Divider()
3937
.padding(.vertical, 10)
@@ -62,18 +60,13 @@ struct EditorTabBarTrailingAccessories: View {
6260
get: { codeFile.wrapLines ?? wrapLinesToEditorWidth },
6361
set: {
6462
codeFile.wrapLines = $0
65-
refreshToggleBool.toggle()
6663
}
6764
)
6865
)
69-
.tag(refreshToggleBool)
7066
} label: {}
7167
.menuStyle(.borderlessButton)
7268
.menuIndicator(.hidden)
7369
}
74-
.onReceive(codeFile.$wrapLines) { _ in // This is annoying but it works
75-
refreshToggleBool.toggle()
76-
}
7770
}
7871

7972
var splitviewButton: some View {
@@ -116,6 +109,6 @@ struct EditorTabBarTrailingAccessories: View {
116109

117110
struct TabBarTrailingAccessories_Previews: PreviewProvider {
118111
static var previews: some View {
119-
EditorTabBarTrailingAccessories()
112+
EditorTabBarTrailingAccessories(codeFile: .constant(nil))
120113
}
121114
}

CodeEdit/Features/Editor/TabBar/Views/EditorTabBarView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99

1010
struct EditorTabBarView: View {
1111
let hasTopInsets: Bool
12+
@Binding var codeFile: CodeFileDocument?
1213
/// The height of tab bar.
1314
/// I am not making it a private variable because it may need to be used in outside views.
1415
static let height = 28.0
@@ -21,7 +22,7 @@ struct EditorTabBarView: View {
2122
.accessibilityElement(children: .contain)
2223
.accessibilityLabel("Tab Bar")
2324
.accessibilityIdentifier("TabBar")
24-
EditorTabBarTrailingAccessories()
25+
EditorTabBarTrailingAccessories(codeFile: $codeFile)
2526
.padding(.top, hasTopInsets ? -1 : 0)
2627
}
2728
.frame(height: EditorTabBarView.height - (hasTopInsets ? 1 : 0))

CodeEdit/Features/Editor/Views/EditorAreaView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ struct EditorAreaView: View {
104104
.background(.clear)
105105
}
106106
if shouldShowTabBar {
107-
EditorTabBarView(hasTopInsets: topSafeArea > 0)
107+
EditorTabBarView(hasTopInsets: topSafeArea > 0, codeFile: $codeFile)
108108
.id("TabBarView" + editor.id.uuidString)
109109
.environmentObject(editor)
110110
Divider()
111111
}
112112
if showEditorJumpBar {
113113
EditorJumpBarView(
114114
file: editor.selectedTab?.file,
115-
shouldShowTabBar: shouldShowTabBar
115+
shouldShowTabBar: shouldShowTabBar,
116+
codeFile: $codeFile
116117
) { [weak editor] newFile in
117118
if let file = editor?.selectedTab, let index = editor?.tabs.firstIndex(of: file) {
118119
editor?.openTab(file: newFile, at: index)

0 commit comments

Comments
 (0)