Skip to content

Commit ee47bab

Browse files
Fix #1158 Using Delayed Appearance and Focus (#1175)
Fix #1158 using delayed focus
1 parent a667ab8 commit ee47bab

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
6C5228B529A868BD00AC48F6 /* Environment+ContentInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C5228B429A868BD00AC48F6 /* Environment+ContentInsets.swift */; };
325325
6C53AAD829A6C4FD00EE9ED6 /* SplitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C53AAD729A6C4FD00EE9ED6 /* SplitView.swift */; };
326326
6C5AB9D729C1496E003B5F96 /* SceneID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C5AB9D629C1496E003B5F96 /* SceneID.swift */; };
327+
6C5B63DE29C76213005454BA /* WindowCodeFileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C5B63DD29C76213005454BA /* WindowCodeFileView.swift */; };
327328
6C7256D729A3D7D000C2D3E0 /* SplitViewControllerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C7256D629A3D7D000C2D3E0 /* SplitViewControllerView.swift */; };
328329
6C81916729B3E80700B75C92 /* ModifierKeysObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C81916629B3E80700B75C92 /* ModifierKeysObserver.swift */; };
329330
6C81916B29B41DD300B75C92 /* DequeModule in Frameworks */ = {isa = PBXBuildFile; productRef = 6C81916A29B41DD300B75C92 /* DequeModule */; };
@@ -742,6 +743,7 @@
742743
6C5228B429A868BD00AC48F6 /* Environment+ContentInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Environment+ContentInsets.swift"; sourceTree = "<group>"; };
743744
6C53AAD729A6C4FD00EE9ED6 /* SplitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitView.swift; sourceTree = "<group>"; };
744745
6C5AB9D629C1496E003B5F96 /* SceneID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneID.swift; sourceTree = "<group>"; };
746+
6C5B63DD29C76213005454BA /* WindowCodeFileView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowCodeFileView.swift; sourceTree = "<group>"; };
745747
6C7256D629A3D7D000C2D3E0 /* SplitViewControllerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewControllerView.swift; sourceTree = "<group>"; };
746748
6C81916629B3E80700B75C92 /* ModifierKeysObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModifierKeysObserver.swift; sourceTree = "<group>"; };
747749
6C82D6B229BFD88700495C54 /* NavigateCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigateCommands.swift; sourceTree = "<group>"; };
@@ -1422,6 +1424,7 @@
14221424
5879824A292E78D80085B254 /* Other */,
14231425
58798249292E78D80085B254 /* CodeFile.swift */,
14241426
58798248292E78D80085B254 /* CodeFileView.swift */,
1427+
6C5B63DD29C76213005454BA /* WindowCodeFileView.swift */,
14251428
);
14261429
path = CodeFile;
14271430
sourceTree = "<group>";
@@ -2714,6 +2717,7 @@
27142717
201169D92837B31200F92B46 /* SourceControlSearchToolbar.swift in Sources */,
27152718
0483E35027FDB17700354AC0 /* ExtensionNavigatorView.swift in Sources */,
27162719
587B9DA729300ABD00AC7927 /* HelpButton.swift in Sources */,
2720+
6C5B63DE29C76213005454BA /* WindowCodeFileView.swift in Sources */,
27172721
58F2EB08292FB2B0004A9BDE /* TextEditingPreferences.swift in Sources */,
27182722
201169DB2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift in Sources */,
27192723
5882252E292C280D00E83CDE /* StatusBarMaximizeButton.swift in Sources */,

CodeEdit/Features/CodeFile/CodeFile.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,18 @@ final class CodeFileDocument: NSDocument, ObservableObject, QLPreviewItem {
7272
}
7373

7474
override func makeWindowControllers() {
75-
// Returns the Storyboard that contains your Document window.
76-
let contentView = CodeFileView(codeFile: self)
7775
let window = NSWindow(
7876
contentRect: NSRect(x: 0, y: 0, width: 1400, height: 600),
7977
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
8078
backing: .buffered, defer: false
8179
)
82-
window.center()
83-
window.contentView = NSHostingView(rootView: contentView)
8480
let windowController = NSWindowController(window: window)
8581
addWindowController(windowController)
82+
83+
window.contentView = NSHostingView(rootView: WindowCodeFileView(codeFile: self))
84+
85+
window.makeKeyAndOrderFront(nil)
86+
window.center()
8687
}
8788

8889
override func data(ofType _: String) throws -> Data {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// WindowCodeFileView.swift
3+
// CodeEdit
4+
//
5+
// Created by Khan Winter on 3/19/23.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
/// View that fixes [#1158](https://github.com/CodeEditApp/CodeEdit/issues/1158)
12+
/// # Should **not** be used other than in a single file window.
13+
struct WindowCodeFileView: View {
14+
var codeFile: CodeFileDocument
15+
16+
@State var hasAppeared = false
17+
@FocusState var focused: Bool
18+
19+
var body: some View {
20+
Group {
21+
if !hasAppeared {
22+
Color.clear.onAppear {
23+
hasAppeared = true
24+
focused = true
25+
}
26+
} else {
27+
CodeFileView(codeFile: codeFile)
28+
.focused($focused)
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)