Skip to content

Commit

Permalink
Example App
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Feb 24, 2024
1 parent 0816105 commit 7fde1a2
Show file tree
Hide file tree
Showing 18 changed files with 955 additions and 11 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"pins" : [
{
"identity" : "codeeditlanguages",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditLanguages.git",
"state" : {
"revision" : "620b463c88894741e20d4711c9435b33547de5d2",
"version" : "0.1.18"
}
},
{
"identity" : "codeedittextview",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
"state" : {
"revision" : "6653c21a603babf365a12d4d331fadc8f8b52d99",
"version" : "0.7.2"
}
},
{
"identity" : "mainoffender",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattmassicotte/MainOffender",
"state" : {
"revision" : "8de872d9256ff7f9913cbc5dd560568ab164be45",
"version" : "0.2.1"
}
},
{
"identity" : "rearrange",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/Rearrange",
"state" : {
"revision" : "5ff7f3363f7a08f77e0d761e38e6add31c2136e1",
"version" : "1.8.1"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swiftlintplugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
"state" : {
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
"version" : "0.54.0"
}
},
{
"identity" : "swifttreesitter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/SwiftTreeSitter.git",
"state" : {
"revision" : "2599e95310b3159641469d8a21baf2d3d200e61f",
"version" : "0.8.0"
}
},
{
"identity" : "textformation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/TextFormation",
"state" : {
"revision" : "f6faed6abd768ae95b70d10113d4008a7cac57a7",
"version" : "0.8.2"
}
},
{
"identity" : "textstory",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/TextStory",
"state" : {
"revision" : "8883fa739aa213e70e6cb109bfbf0a0b551e4cb5",
"version" : "0.8.0"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CodeEditSourceEditorExampleApp.swift
// CodeEditSourceEditorExample
//
// Created by Khan Winter on 2/24/24.
//

import SwiftUI

@main
struct CodeEditSourceEditorExampleApp: App {
var body: some Scene {
DocumentGroup(newDocument: CodeEditSourceEditorExampleDocument()) { file in
ContentView(document: file.$document, fileURL: file.fileURL)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// CodeEditSourceEditorExampleDocument.swift
// CodeEditSourceEditorExample
//
// Created by Khan Winter on 2/24/24.
//

import SwiftUI
import UniformTypeIdentifiers

struct CodeEditSourceEditorExampleDocument: FileDocument {
var text: String

init(text: String = "") {
self.text = text
}

static var readableContentTypes: [UTType] {
[
.sourceCode,
.plainText,
.delimitedText,
.script
]
}

init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let string = String(data: data, encoding: .utf8)
else {
throw CocoaError(.fileReadCorruptFile)
}
text = string
}

func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let data = text.data(using: .utf8)!
return .init(regularFileWithContents: data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// EditorTheme+Default.swift
// CodeEditSourceEditorExample
//
// Created by Khan Winter on 2/24/24.
//

import Foundation
import AppKit
import CodeEditSourceEditor

extension EditorTheme {
static var standard: EditorTheme {
EditorTheme(
text: .init(hex: "000000"),
insertionPoint: .init(hex: "000000"),
invisibles: .init(hex: "D6D6D6"),
background: .init(hex: "FFFFFF"),
lineHighlight: .init(hex: "ECF5FF"),
selection: .init(hex: "B2D7FF"),
keywords: .init(hex: "9B2393"),
commands: .init(hex: "326D74"),
types: .init(hex: "0B4F79"),
attributes: .init(hex: "815F03"),
variables: .init(hex: "0F68A0"),
values: .init(hex: "6C36A9"),
numbers: .init(hex: "1C00CF"),
strings: .init(hex: "C41A16"),
characters: .init(hex: "1C00CF"),
comments: .init(hex: "267507")
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// NSColor+Hex.swift
// CodeEditSourceEditorExample
//
// Created by Khan Winter on 2/24/24.
//

import AppKit

extension NSColor {

/// Initializes a `NSColor` from a HEX String (e.g.: `#1D2E3F`) and an optional alpha value.
/// - Parameters:
/// - hex: A String of a HEX representation of a color (format: `#1D2E3F`)
/// - alpha: A Double indicating the alpha value from `0.0` to `1.0`
convenience init(hex: String, alpha: Double = 1.0) {
let hex = hex.trimmingCharacters(in: .alphanumerics.inverted)
var int: UInt64 = 0
Scanner(string: hex).scanHexInt64(&int)
self.init(hex: Int(int), alpha: alpha)
}

/// Initializes a `NSColor` from an Int (e.g.: `0x1D2E3F`)and an optional alpha value.
/// - Parameters:
/// - hex: An Int of a HEX representation of a color (format: `0x1D2E3F`)
/// - alpha: A Double indicating the alpha value from `0.0` to `1.0`
convenience init(hex: Int, alpha: Double = 1.0) {
let red = (hex >> 16) & 0xFF
let green = (hex >> 8) & 0xFF
let blue = hex & 0xFF
self.init(srgbRed: Double(red) / 255, green: Double(green) / 255, blue: Double(blue) / 255, alpha: alpha)
}

/// Returns an Int representing the `NSColor` in hex format (e.g.: 0x112233)
var hex: Int {
guard let components = cgColor.components, components.count >= 3 else { return 0 }

let red = lround((Double(components[0]) * 255.0)) << 16
let green = lround((Double(components[1]) * 255.0)) << 8
let blue = lround((Double(components[2]) * 255.0))

return red | green | blue
}

/// Returns a HEX String representing the `NSColor` (e.g.: #112233)
var hexString: String {
let color = self.hex

return "#" + String(format: "%06x", color)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// String+Lines.swift
// CodeEditSourceEditorExample
//
// Created by Khan Winter on 2/24/24.
//

import Foundation

extension String {
/// Calculates the first `n` lines and returns them as a new string.
/// - Parameters:
/// - lines: The number of lines to return.
/// - maxLength: The maximum number of characters to copy.
/// - Returns: A new string containing the lines.
func getFirstLines(_ lines: Int = 1, maxLength: Int = 512) -> String {
var string = ""
var foundLines = 0
var totalLength = 0
for char in self.lazy {
if char.isNewline {
foundLines += 1
}
totalLength += 1
if foundLines >= lines || totalLength >= maxLength {
break
}
string.append(char)
}
return string
}

/// Calculates the last `n` lines and returns them as a new string.
/// - Parameters:
/// - lines: The number of lines to return.
/// - maxLength: The maximum number of characters to copy.
/// - Returns: A new string containing the lines.
func getLastLines(_ lines: Int = 1, maxLength: Int = 512) -> String {
var string = ""
var foundLines = 0
var totalLength = 0
for char in self.lazy.reversed() {
if char.isNewline {
foundLines += 1
}
totalLength += 1
if foundLines >= lines || totalLength >= maxLength {
break
}
string = String(char) + string
}
return string
}
}
Loading

0 comments on commit 7fde1a2

Please sign in to comment.