Skip to content

Commit 5e83a75

Browse files
Add Example App (#237)
1 parent 0816105 commit 5e83a75

File tree

20 files changed

+972
-13
lines changed

20 files changed

+972
-13
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj

+410
Large diffs are not rendered by default.

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "codeeditlanguages",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/CodeEditApp/CodeEditLanguages.git",
7+
"state" : {
8+
"revision" : "620b463c88894741e20d4711c9435b33547de5d2",
9+
"version" : "0.1.18"
10+
}
11+
},
12+
{
13+
"identity" : "codeedittextview",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
16+
"state" : {
17+
"revision" : "6653c21a603babf365a12d4d331fadc8f8b52d99",
18+
"version" : "0.7.2"
19+
}
20+
},
21+
{
22+
"identity" : "mainoffender",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/mattmassicotte/MainOffender",
25+
"state" : {
26+
"revision" : "8de872d9256ff7f9913cbc5dd560568ab164be45",
27+
"version" : "0.2.1"
28+
}
29+
},
30+
{
31+
"identity" : "rearrange",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/ChimeHQ/Rearrange",
34+
"state" : {
35+
"revision" : "5ff7f3363f7a08f77e0d761e38e6add31c2136e1",
36+
"version" : "1.8.1"
37+
}
38+
},
39+
{
40+
"identity" : "swift-collections",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/apple/swift-collections.git",
43+
"state" : {
44+
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
45+
"version" : "1.1.0"
46+
}
47+
},
48+
{
49+
"identity" : "swiftlintplugin",
50+
"kind" : "remoteSourceControl",
51+
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
52+
"state" : {
53+
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
54+
"version" : "0.54.0"
55+
}
56+
},
57+
{
58+
"identity" : "swifttreesitter",
59+
"kind" : "remoteSourceControl",
60+
"location" : "https://github.com/ChimeHQ/SwiftTreeSitter.git",
61+
"state" : {
62+
"revision" : "2599e95310b3159641469d8a21baf2d3d200e61f",
63+
"version" : "0.8.0"
64+
}
65+
},
66+
{
67+
"identity" : "textformation",
68+
"kind" : "remoteSourceControl",
69+
"location" : "https://github.com/ChimeHQ/TextFormation",
70+
"state" : {
71+
"revision" : "f6faed6abd768ae95b70d10113d4008a7cac57a7",
72+
"version" : "0.8.2"
73+
}
74+
},
75+
{
76+
"identity" : "textstory",
77+
"kind" : "remoteSourceControl",
78+
"location" : "https://github.com/ChimeHQ/TextStory",
79+
"state" : {
80+
"revision" : "8883fa739aa213e70e6cb109bfbf0a0b551e4cb5",
81+
"version" : "0.8.0"
82+
}
83+
}
84+
],
85+
"version" : 2
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"scale" : "1x",
6+
"size" : "16x16"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"scale" : "2x",
11+
"size" : "16x16"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"scale" : "1x",
16+
"size" : "32x32"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"scale" : "2x",
21+
"size" : "32x32"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"scale" : "1x",
26+
"size" : "128x128"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"scale" : "2x",
31+
"size" : "128x128"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"scale" : "1x",
36+
"size" : "256x256"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"scale" : "2x",
41+
"size" : "256x256"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"scale" : "1x",
46+
"size" : "512x512"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"scale" : "2x",
51+
"size" : "512x512"
52+
}
53+
],
54+
"info" : {
55+
"author" : "xcode",
56+
"version" : 1
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.files.user-selected.read-write</key>
8+
<true/>
9+
</dict>
10+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CodeEditSourceEditorExampleApp.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import SwiftUI
9+
10+
@main
11+
struct CodeEditSourceEditorExampleApp: App {
12+
var body: some Scene {
13+
DocumentGroup(newDocument: CodeEditSourceEditorExampleDocument()) { file in
14+
ContentView(document: file.$document, fileURL: file.fileURL)
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// CodeEditSourceEditorExampleDocument.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import SwiftUI
9+
import UniformTypeIdentifiers
10+
11+
struct CodeEditSourceEditorExampleDocument: FileDocument {
12+
var text: String
13+
14+
init(text: String = "") {
15+
self.text = text
16+
}
17+
18+
static var readableContentTypes: [UTType] {
19+
[
20+
.sourceCode,
21+
.plainText,
22+
.delimitedText,
23+
.script
24+
]
25+
}
26+
27+
init(configuration: ReadConfiguration) throws {
28+
guard let data = configuration.file.regularFileContents,
29+
let string = String(data: data, encoding: .utf8)
30+
else {
31+
throw CocoaError(.fileReadCorruptFile)
32+
}
33+
text = string
34+
}
35+
36+
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
37+
let data = text.data(using: .utf8)!
38+
return .init(regularFileWithContents: data)
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// EditorTheme+Default.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import Foundation
9+
import AppKit
10+
import CodeEditSourceEditor
11+
12+
extension EditorTheme {
13+
static var standard: EditorTheme {
14+
EditorTheme(
15+
text: .init(hex: "000000"),
16+
insertionPoint: .init(hex: "000000"),
17+
invisibles: .init(hex: "D6D6D6"),
18+
background: .init(hex: "FFFFFF"),
19+
lineHighlight: .init(hex: "ECF5FF"),
20+
selection: .init(hex: "B2D7FF"),
21+
keywords: .init(hex: "9B2393"),
22+
commands: .init(hex: "326D74"),
23+
types: .init(hex: "0B4F79"),
24+
attributes: .init(hex: "815F03"),
25+
variables: .init(hex: "0F68A0"),
26+
values: .init(hex: "6C36A9"),
27+
numbers: .init(hex: "1C00CF"),
28+
strings: .init(hex: "C41A16"),
29+
characters: .init(hex: "1C00CF"),
30+
comments: .init(hex: "267507")
31+
)
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// NSColor+Hex.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import AppKit
9+
10+
extension NSColor {
11+
12+
/// Initializes a `NSColor` from a HEX String (e.g.: `#1D2E3F`) and an optional alpha value.
13+
/// - Parameters:
14+
/// - hex: A String of a HEX representation of a color (format: `#1D2E3F`)
15+
/// - alpha: A Double indicating the alpha value from `0.0` to `1.0`
16+
convenience init(hex: String, alpha: Double = 1.0) {
17+
let hex = hex.trimmingCharacters(in: .alphanumerics.inverted)
18+
var int: UInt64 = 0
19+
Scanner(string: hex).scanHexInt64(&int)
20+
self.init(hex: Int(int), alpha: alpha)
21+
}
22+
23+
/// Initializes a `NSColor` from an Int (e.g.: `0x1D2E3F`)and an optional alpha value.
24+
/// - Parameters:
25+
/// - hex: An Int of a HEX representation of a color (format: `0x1D2E3F`)
26+
/// - alpha: A Double indicating the alpha value from `0.0` to `1.0`
27+
convenience init(hex: Int, alpha: Double = 1.0) {
28+
let red = (hex >> 16) & 0xFF
29+
let green = (hex >> 8) & 0xFF
30+
let blue = hex & 0xFF
31+
self.init(srgbRed: Double(red) / 255, green: Double(green) / 255, blue: Double(blue) / 255, alpha: alpha)
32+
}
33+
34+
/// Returns an Int representing the `NSColor` in hex format (e.g.: 0x112233)
35+
var hex: Int {
36+
guard let components = cgColor.components, components.count >= 3 else { return 0 }
37+
38+
let red = lround((Double(components[0]) * 255.0)) << 16
39+
let green = lround((Double(components[1]) * 255.0)) << 8
40+
let blue = lround((Double(components[2]) * 255.0))
41+
42+
return red | green | blue
43+
}
44+
45+
/// Returns a HEX String representing the `NSColor` (e.g.: #112233)
46+
var hexString: String {
47+
let color = self.hex
48+
49+
return "#" + String(format: "%06x", color)
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// String+Lines.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import Foundation
9+
10+
extension String {
11+
/// Calculates the first `n` lines and returns them as a new string.
12+
/// - Parameters:
13+
/// - lines: The number of lines to return.
14+
/// - maxLength: The maximum number of characters to copy.
15+
/// - Returns: A new string containing the lines.
16+
func getFirstLines(_ lines: Int = 1, maxLength: Int = 512) -> String {
17+
var string = ""
18+
var foundLines = 0
19+
var totalLength = 0
20+
for char in self.lazy {
21+
if char.isNewline {
22+
foundLines += 1
23+
}
24+
totalLength += 1
25+
if foundLines >= lines || totalLength >= maxLength {
26+
break
27+
}
28+
string.append(char)
29+
}
30+
return string
31+
}
32+
33+
/// Calculates the last `n` lines and returns them as a new string.
34+
/// - Parameters:
35+
/// - lines: The number of lines to return.
36+
/// - maxLength: The maximum number of characters to copy.
37+
/// - Returns: A new string containing the lines.
38+
func getLastLines(_ lines: Int = 1, maxLength: Int = 512) -> String {
39+
var string = ""
40+
var foundLines = 0
41+
var totalLength = 0
42+
for char in self.lazy.reversed() {
43+
if char.isNewline {
44+
foundLines += 1
45+
}
46+
totalLength += 1
47+
if foundLines >= lines || totalLength >= maxLength {
48+
break
49+
}
50+
string = String(char) + string
51+
}
52+
return string
53+
}
54+
}

0 commit comments

Comments
 (0)