Skip to content

Commit 6c05378

Browse files
Merge branch 'main' into feat/select-next-occurrence
2 parents 309bacc + 7f6b7b5 commit 6c05378

File tree

14 files changed

+250
-32
lines changed

14 files changed

+250
-32
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
11
{
22
"images" : [
33
{
4+
"size" : "16x16",
45
"idiom" : "mac",
5-
"scale" : "1x",
6-
"size" : "16x16"
6+
"filename" : "CodeEditSourceEditor-Icon-16.png",
7+
"scale" : "1x"
78
},
89
{
10+
"size" : "16x16",
911
"idiom" : "mac",
10-
"scale" : "2x",
11-
"size" : "16x16"
12+
"filename" : "CodeEditSourceEditor-Icon-32.png",
13+
"scale" : "2x"
1214
},
1315
{
16+
"size" : "32x32",
1417
"idiom" : "mac",
15-
"scale" : "1x",
16-
"size" : "32x32"
18+
"filename" : "CodeEditSourceEditor-Icon-32.png",
19+
"scale" : "1x"
1720
},
1821
{
22+
"size" : "32x32",
1923
"idiom" : "mac",
20-
"scale" : "2x",
21-
"size" : "32x32"
24+
"filename" : "CodeEditSourceEditor-Icon-64.png",
25+
"scale" : "2x"
2226
},
2327
{
28+
"size" : "128x128",
2429
"idiom" : "mac",
25-
"scale" : "1x",
26-
"size" : "128x128"
30+
"filename" : "CodeEditSourceEditor-Icon-128.png",
31+
"scale" : "1x"
2732
},
2833
{
34+
"size" : "128x128",
2935
"idiom" : "mac",
30-
"scale" : "2x",
31-
"size" : "128x128"
36+
"filename" : "CodeEditSourceEditor-Icon-256.png",
37+
"scale" : "2x"
3238
},
3339
{
40+
"size" : "256x256",
3441
"idiom" : "mac",
35-
"scale" : "1x",
36-
"size" : "256x256"
42+
"filename" : "CodeEditSourceEditor-Icon-256.png",
43+
"scale" : "1x"
3744
},
3845
{
46+
"size" : "256x256",
3947
"idiom" : "mac",
40-
"scale" : "2x",
41-
"size" : "256x256"
48+
"filename" : "CodeEditSourceEditor-Icon-512.png",
49+
"scale" : "2x"
4250
},
4351
{
52+
"size" : "512x512",
4453
"idiom" : "mac",
45-
"scale" : "1x",
46-
"size" : "512x512"
54+
"filename" : "CodeEditSourceEditor-Icon-512.png",
55+
"scale" : "1x"
4756
},
4857
{
58+
"size" : "512x512",
4959
"idiom" : "mac",
50-
"scale" : "2x",
51-
"size" : "512x512"
60+
"filename" : "CodeEditSourceEditor-Icon-1024.png",
61+
"scale" : "2x"
5262
}
5363
],
5464
"info" : {
55-
"author" : "xcode",
56-
"version" : 1
65+
"version" : 1,
66+
"author" : "xcode"
5767
}
58-
}
68+
}

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import SwiftUI
99
import UniformTypeIdentifiers
1010

11-
struct CodeEditSourceEditorExampleDocument: FileDocument {
12-
var text: String
11+
struct CodeEditSourceEditorExampleDocument: FileDocument, @unchecked Sendable {
12+
enum DocumentError: Error {
13+
case failedToEncode
14+
}
15+
16+
var text: NSTextStorage
1317

14-
init(text: String = "") {
18+
init(text: NSTextStorage = NSTextStorage(string: "")) {
1519
self.text = text
1620
}
1721

@@ -25,11 +29,31 @@ struct CodeEditSourceEditorExampleDocument: FileDocument {
2529
guard let data = configuration.file.regularFileContents else {
2630
throw CocoaError(.fileReadCorruptFile)
2731
}
28-
text = String(decoding: data, as: UTF8.self)
32+
var nsString: NSString?
33+
NSString.stringEncoding(
34+
for: data,
35+
encodingOptions: [
36+
// Fail if using lossy encoding.
37+
.allowLossyKey: false,
38+
// In a real app, you'll want to handle more than just this encoding scheme. Check out CodeEdit's
39+
// implementation for a more involved solution.
40+
.suggestedEncodingsKey: [NSUTF8StringEncoding],
41+
.useOnlySuggestedEncodingsKey: true
42+
],
43+
convertedString: &nsString,
44+
usedLossyConversion: nil
45+
)
46+
if let nsString {
47+
self.text = NSTextStorage(string: nsString as String)
48+
} else {
49+
fatalError("Failed to read file")
50+
}
2951
}
3052

3153
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
32-
let data = Data(text.utf8)
54+
guard let data = (text.string as NSString?)?.data(using: NSUTF8StringEncoding) else {
55+
throw DocumentError.failedToEncode
56+
}
3357
return .init(regularFileWithContents: data)
3458
}
3559
}

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct ContentView: View {
3939
var body: some View {
4040
GeometryReader { proxy in
4141
CodeEditSourceEditor(
42-
$document.text,
42+
document.text,
4343
language: language,
4444
theme: theme,
4545
font: font,

0 commit comments

Comments
 (0)