From 7fde1a28b9f808302df765c4f970874bbb293a95 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:38:07 -0600 Subject: [PATCH 1/4] Example App --- .../project.pbxproj | 410 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/swiftpm/Package.resolved | 86 ++++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 58 +++ .../Assets.xcassets/Contents.json | 6 + .../CodeEditSourceEditorExample.entitlements | 10 + .../CodeEditSourceEditorExampleApp.swift | 17 + .../CodeEditSourceEditorExampleDocument.swift | 40 ++ .../Extensions/EditorTheme+Default.swift | 33 ++ .../Extensions/NSColor+Hex.swift | 51 +++ .../Extensions/String+Lines.swift | 54 +++ .../CodeEditSourceEditorExample/Info.plist | 39 ++ .../Preview Assets.xcassets/Contents.json | 6 + .../Views/ContentView.swift | 87 ++++ .../Views/LanguagePicker.swift | 30 ++ Package.resolved | 13 +- 18 files changed, 955 insertions(+), 11 deletions(-) create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/Contents.json create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExampleApp.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/NSColor+Hex.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/String+Lines.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Info.plist create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift create mode 100644 Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/LanguagePicker.swift diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj new file mode 100644 index 000000000..2eeb62d6f --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj @@ -0,0 +1,410 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 6C13652E2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13652D2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift */; }; + 6C1365302B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13652F2B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift */; }; + 6C1365322B8A7B94004A1D18 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1365312B8A7B94004A1D18 /* ContentView.swift */; }; + 6C1365342B8A7B95004A1D18 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C1365332B8A7B95004A1D18 /* Assets.xcassets */; }; + 6C1365372B8A7B95004A1D18 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C1365362B8A7B95004A1D18 /* Preview Assets.xcassets */; }; + 6C1365412B8A7BC3004A1D18 /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 6C1365402B8A7BC3004A1D18 /* CodeEditSourceEditor */; }; + 6C1365442B8A7EED004A1D18 /* String+Lines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1365432B8A7EED004A1D18 /* String+Lines.swift */; }; + 6C1365462B8A7F2D004A1D18 /* LanguagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1365452B8A7F2D004A1D18 /* LanguagePicker.swift */; }; + 6C1365482B8A7FBF004A1D18 /* EditorTheme+Default.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1365472B8A7FBF004A1D18 /* EditorTheme+Default.swift */; }; + 6C13654D2B8A821E004A1D18 /* NSColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13654C2B8A821E004A1D18 /* NSColor+Hex.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 6C13652A2B8A7B94004A1D18 /* CodeEditSourceEditorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEditSourceEditorExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 6C13652D2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditSourceEditorExampleApp.swift; sourceTree = ""; }; + 6C13652F2B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditSourceEditorExampleDocument.swift; sourceTree = ""; }; + 6C1365312B8A7B94004A1D18 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 6C1365332B8A7B95004A1D18 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 6C1365362B8A7B95004A1D18 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 6C1365382B8A7B95004A1D18 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6C1365392B8A7B95004A1D18 /* CodeEditSourceEditorExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CodeEditSourceEditorExample.entitlements; sourceTree = ""; }; + 6C1365422B8A7BFE004A1D18 /* CodeEditSourceEditor */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = CodeEditSourceEditor; path = ../..; sourceTree = ""; }; + 6C1365432B8A7EED004A1D18 /* String+Lines.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Lines.swift"; sourceTree = ""; }; + 6C1365452B8A7F2D004A1D18 /* LanguagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguagePicker.swift; sourceTree = ""; }; + 6C1365472B8A7FBF004A1D18 /* EditorTheme+Default.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EditorTheme+Default.swift"; sourceTree = ""; }; + 6C13654C2B8A821E004A1D18 /* NSColor+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+Hex.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6C1365272B8A7B94004A1D18 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6C1365412B8A7BC3004A1D18 /* CodeEditSourceEditor in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 6C1365212B8A7B94004A1D18 = { + isa = PBXGroup; + children = ( + 6C1365422B8A7BFE004A1D18 /* CodeEditSourceEditor */, + 6C13652C2B8A7B94004A1D18 /* CodeEditSourceEditorExample */, + 6C13652B2B8A7B94004A1D18 /* Products */, + ); + sourceTree = ""; + }; + 6C13652B2B8A7B94004A1D18 /* Products */ = { + isa = PBXGroup; + children = ( + 6C13652A2B8A7B94004A1D18 /* CodeEditSourceEditorExample.app */, + ); + name = Products; + sourceTree = ""; + }; + 6C13652C2B8A7B94004A1D18 /* CodeEditSourceEditorExample */ = { + isa = PBXGroup; + children = ( + 6C13652D2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift */, + 6C13654B2B8A7FD7004A1D18 /* Documents */, + 6C13654A2B8A7FD2004A1D18 /* Views */, + 6C1365492B8A7FC8004A1D18 /* Extensions */, + 6C1365332B8A7B95004A1D18 /* Assets.xcassets */, + 6C1365382B8A7B95004A1D18 /* Info.plist */, + 6C1365392B8A7B95004A1D18 /* CodeEditSourceEditorExample.entitlements */, + 6C1365352B8A7B95004A1D18 /* Preview Content */, + ); + path = CodeEditSourceEditorExample; + sourceTree = ""; + }; + 6C1365352B8A7B95004A1D18 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 6C1365362B8A7B95004A1D18 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 6C1365492B8A7FC8004A1D18 /* Extensions */ = { + isa = PBXGroup; + children = ( + 6C1365472B8A7FBF004A1D18 /* EditorTheme+Default.swift */, + 6C13654C2B8A821E004A1D18 /* NSColor+Hex.swift */, + 6C1365432B8A7EED004A1D18 /* String+Lines.swift */, + ); + path = Extensions; + sourceTree = ""; + }; + 6C13654A2B8A7FD2004A1D18 /* Views */ = { + isa = PBXGroup; + children = ( + 6C1365312B8A7B94004A1D18 /* ContentView.swift */, + 6C1365452B8A7F2D004A1D18 /* LanguagePicker.swift */, + ); + path = Views; + sourceTree = ""; + }; + 6C13654B2B8A7FD7004A1D18 /* Documents */ = { + isa = PBXGroup; + children = ( + 6C13652F2B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift */, + ); + path = Documents; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6C1365292B8A7B94004A1D18 /* CodeEditSourceEditorExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6C13653C2B8A7B95004A1D18 /* Build configuration list for PBXNativeTarget "CodeEditSourceEditorExample" */; + buildPhases = ( + 6C1365262B8A7B94004A1D18 /* Sources */, + 6C1365272B8A7B94004A1D18 /* Frameworks */, + 6C1365282B8A7B94004A1D18 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CodeEditSourceEditorExample; + packageProductDependencies = ( + 6C1365402B8A7BC3004A1D18 /* CodeEditSourceEditor */, + ); + productName = CodeEditSourceEditorExample; + productReference = 6C13652A2B8A7B94004A1D18 /* CodeEditSourceEditorExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6C1365222B8A7B94004A1D18 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1520; + LastUpgradeCheck = 1520; + TargetAttributes = { + 6C1365292B8A7B94004A1D18 = { + CreatedOnToolsVersion = 15.2; + }; + }; + }; + buildConfigurationList = 6C1365252B8A7B94004A1D18 /* Build configuration list for PBXProject "CodeEditSourceEditorExample" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 6C1365212B8A7B94004A1D18; + packageReferences = ( + ); + productRefGroup = 6C13652B2B8A7B94004A1D18 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6C1365292B8A7B94004A1D18 /* CodeEditSourceEditorExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6C1365282B8A7B94004A1D18 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6C1365372B8A7B95004A1D18 /* Preview Assets.xcassets in Resources */, + 6C1365342B8A7B95004A1D18 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6C1365262B8A7B94004A1D18 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6C1365482B8A7FBF004A1D18 /* EditorTheme+Default.swift in Sources */, + 6C13654D2B8A821E004A1D18 /* NSColor+Hex.swift in Sources */, + 6C1365302B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift in Sources */, + 6C13652E2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift in Sources */, + 6C1365442B8A7EED004A1D18 /* String+Lines.swift in Sources */, + 6C1365322B8A7B94004A1D18 /* ContentView.swift in Sources */, + 6C1365462B8A7F2D004A1D18 /* LanguagePicker.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 6C13653A2B8A7B95004A1D18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 6C13653B2B8A7B95004A1D18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MACOSX_DEPLOYMENT_TARGET = 14.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + }; + name = Release; + }; + 6C13653D2B8A7B95004A1D18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"CodeEditSourceEditorExample/Preview Content\""; + DEVELOPMENT_TEAM = 7DAW426J6S; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = CodeEditSourceEditorExample/Info.plist; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.CodeEdit.CodeEditSourceEditorExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 6C13653E2B8A7B95004A1D18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"CodeEditSourceEditorExample/Preview Content\""; + DEVELOPMENT_TEAM = 7DAW426J6S; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = CodeEditSourceEditorExample/Info.plist; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.CodeEdit.CodeEditSourceEditorExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6C1365252B8A7B94004A1D18 /* Build configuration list for PBXProject "CodeEditSourceEditorExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6C13653A2B8A7B95004A1D18 /* Debug */, + 6C13653B2B8A7B95004A1D18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6C13653C2B8A7B95004A1D18 /* Build configuration list for PBXNativeTarget "CodeEditSourceEditorExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6C13653D2B8A7B95004A1D18 /* Debug */, + 6C13653E2B8A7B95004A1D18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 6C1365402B8A7BC3004A1D18 /* CodeEditSourceEditor */ = { + isa = XCSwiftPackageProductDependency; + productName = CodeEditSourceEditor; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 6C1365222B8A7B94004A1D18 /* Project object */; +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 000000000..cf13c167c --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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 +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AccentColor.colorset/Contents.json b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..3f00db43e --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -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 + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/Contents.json b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements new file mode 100644 index 000000000..6d968edb4 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExample.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-write + + + diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExampleApp.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExampleApp.swift new file mode 100644 index 000000000..ac078e338 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/CodeEditSourceEditorExampleApp.swift @@ -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) + } + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift new file mode 100644 index 000000000..42c53e699 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift @@ -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) + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift new file mode 100644 index 000000000..fceebc8d3 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift @@ -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") + ) + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/NSColor+Hex.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/NSColor+Hex.swift new file mode 100644 index 000000000..cdde5c0eb --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/NSColor+Hex.swift @@ -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) + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/String+Lines.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/String+Lines.swift new file mode 100644 index 000000000..4b3fbfb41 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/String+Lines.swift @@ -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 + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Info.plist b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Info.plist new file mode 100644 index 000000000..730eeb18f --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleDocumentTypes + + + CFBundleTypeRole + Editor + LSItemContentTypes + + com.example.plain-text + + NSUbiquitousDocumentUserActivityType + $(PRODUCT_BUNDLE_IDENTIFIER).example-document + + + UTImportedTypeDeclarations + + + UTTypeConformsTo + + public.plain-text + + UTTypeDescription + Example Text + UTTypeIdentifier + com.example.plain-text + UTTypeTagSpecification + + public.filename-extension + + exampletext + + + + + + diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Preview Content/Preview Assets.xcassets/Contents.json b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift new file mode 100644 index 000000000..280f6449c --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift @@ -0,0 +1,87 @@ +// +// ContentView.swift +// CodeEditSourceEditorExample +// +// Created by Khan Winter on 2/24/24. +// + +import SwiftUI +import CodeEditSourceEditor +import CodeEditLanguages +import CodeEditTextView + +struct ContentView: View { + @Binding var document: CodeEditSourceEditorExampleDocument + let fileURL: URL? + + @State private var language: CodeLanguage = .default + @State private var theme: EditorTheme = .standard + @State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular) + @AppStorage("wrapLines") private var wrapLines: Bool = true + @State private var cursorPositions: [CursorPosition] = [] + + init(document: Binding, fileURL: URL?) { + self._document = document + self.fileURL = fileURL + } + + var body: some View { + VStack(spacing: 0) { + HStack { + Text("Language") + LanguagePicker(language: $language) + .frame(maxWidth: 100) + Toggle("Wrap Lines", isOn: $wrapLines) + Spacer() + Text(getLabel(cursorPositions)) + } + .padding(4) + .zIndex(2) + .background(Color(NSColor.windowBackgroundColor)) + Divider() + CodeEditSourceEditor( + $document.text, + language: language, + theme: theme, + font: font, + tabWidth: 4, + lineHeight: 1.2, + wrapLines: wrapLines, + cursorPositions: $cursorPositions + ) + } + .onAppear { + self.language = detectLanguage(fileURL: fileURL) ?? .default + } + } + + private func detectLanguage(fileURL: URL?) -> CodeLanguage? { + guard let fileURL else { return nil } + return CodeLanguage.detectLanguageFrom( + url: fileURL, + prefixBuffer: document.text.getFirstLines(5), + suffixBuffer: document.text.getLastLines(5) + ) + } + + /// Create a label string for cursor positions. + /// - Parameter cursorPositions: The cursor positions to create the label for. + /// - Returns: A string describing the user's location in a document. + func getLabel(_ cursorPositions: [CursorPosition]) -> String { + if cursorPositions.isEmpty { + return "" + } + + // More than one selection, display the number of selections. + if cursorPositions.count > 1 { + return "\(cursorPositions.count) selected ranges" + } + + // When there's a single cursor, display the line and column. + return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column)" + } +} + +#Preview { + ContentView(document: .constant(CodeEditSourceEditorExampleDocument()), fileURL: nil) +} diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/LanguagePicker.swift b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/LanguagePicker.swift new file mode 100644 index 000000000..f99022d25 --- /dev/null +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/LanguagePicker.swift @@ -0,0 +1,30 @@ +// +// LanguagePicker.swift +// CodeEditSourceEditorExample +// +// Created by Khan Winter on 2/24/24. +// + +import SwiftUI +import CodeEditLanguages + +struct LanguagePicker: View { + @Binding var language: CodeLanguage + + var body: some View { + Picker( + "Language", + selection: $language + ) { + ForEach([.default] + CodeLanguage.allLanguages, id: \.id) { language in + Text(language.id.rawValue) + .tag(language) + } + } + .labelsHidden() + } +} + +#Preview { + LanguagePicker(language: .constant(.swift)) +} diff --git a/Package.resolved b/Package.resolved index 5d97a3e82..41b15fae7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,15 +9,6 @@ "version" : "0.1.18" } }, - { - "identity" : "codeedittextview", - "kind" : "remoteSourceControl", - "location" : "https://github.com/CodeEditApp/CodeEditTextView.git", - "state" : { - "revision" : "6abce20f1827a3665a5159195157f592352e38b4", - "version" : "0.7.1" - } - }, { "identity" : "mainoffender", "kind" : "remoteSourceControl", @@ -41,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "d029d9d39c87bed85b1c50adee7c41795261a192", - "version" : "1.0.6" + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" } }, { From 7df41c46f0c3830099b39557f175d5b99f13a7bd Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:54:53 -0600 Subject: [PATCH 2/4] Remove Personal Team ID --- .../CodeEditSourceEditorExample.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj index 2eeb62d6f..27ea9f902 100644 --- a/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj +++ b/Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj @@ -330,7 +330,7 @@ COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEditSourceEditorExample/Preview Content\""; - DEVELOPMENT_TEAM = 7DAW426J6S; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -358,7 +358,7 @@ COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEditSourceEditorExample/Preview Content\""; - DEVELOPMENT_TEAM = 7DAW426J6S; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; From 2b86c3e90286ee821ad0a57840ab501853eae6ed Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:37:48 -0600 Subject: [PATCH 3/4] Resolve Package Versions --- Package.resolved | 9 +++++++++ Package.swift | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index 41b15fae7..0f28e643e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,6 +9,15 @@ "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", diff --git a/Package.swift b/Package.swift index 2dfe6a02a..62d3537d2 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( // A fast, efficient, text view for code. .package( url: "https://github.com/CodeEditApp/CodeEditTextView.git", - from: "0.7.0" + from: "0.7.2" ), // tree-sitter languages .package( From 987473de9fda768bfdae2dc9c4d17b9e98e7008e Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:52:42 -0600 Subject: [PATCH 4/4] Fix failing tests --- .../TextViewControllerTests.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift index fc5e340fa..df2a5a2e5 100644 --- a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift +++ b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift @@ -173,40 +173,41 @@ final class TextViewControllerTests: XCTestCase { } func test_indentBehavior() { + controller.highlighter = nil + // Insert 1 space controller.indentOption = .spaces(count: 1) - controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") + controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.length), with: "") controller.textView.selectionManager.setSelectedRange(NSRange(location: 0, length: 0)) controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, " ") // Insert 2 spaces controller.indentOption = .spaces(count: 2) - controller.textView.textStorage.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") + controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.length), with: "") controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, " ") // Insert 3 spaces controller.indentOption = .spaces(count: 3) - controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") + controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.length), with: "") controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, " ") // Insert 4 spaces controller.indentOption = .spaces(count: 4) - controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") + controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.length), with: "") controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, " ") // Insert tab controller.indentOption = .tab - controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") + controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.length), with: "") controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, "\t") // Insert lots of spaces controller.indentOption = .spaces(count: 1000) - print(controller.textView.textStorage.length) controller.textView.replaceCharacters(in: NSRange(location: 0, length: controller.textView.textStorage.length), with: "") controller.textView.insertText("\t", replacementRange: .zero) XCTAssertEqual(controller.textView.string, String(repeating: " ", count: 1000)) @@ -236,6 +237,7 @@ final class TextViewControllerTests: XCTestCase { func test_bracketHighlights() { controller.scrollView.setFrameSize(NSSize(width: 500, height: 500)) controller.viewDidLoad() + let _ = controller.textView.becomeFirstResponder() controller.bracketPairHighlight = nil controller.setText("{ Loren Ipsum {} }") controller.setCursorPositions([CursorPosition(line: 1, column: 2)]) // After first opening { @@ -273,6 +275,7 @@ final class TextViewControllerTests: XCTestCase { } func test_findClosingPair() { + let _ = controller.textView.becomeFirstResponder() controller.textView.string = "{ Loren Ipsum {} }" var idx: Int? @@ -308,6 +311,7 @@ final class TextViewControllerTests: XCTestCase { // MARK: Set Text func test_setText() { + let _ = controller.textView.becomeFirstResponder() controller.textView.string = "Hello World" controller.textView.selectionManager.setSelectedRange(NSRange(location: 1, length: 2)) @@ -327,6 +331,7 @@ final class TextViewControllerTests: XCTestCase { // MARK: Cursor Positions func test_cursorPositionRangeInit() { + let _ = controller.textView.becomeFirstResponder() controller.setText("Hello World") // Test adding a position returns a valid one @@ -367,6 +372,7 @@ final class TextViewControllerTests: XCTestCase { } func test_cursorPositionRowColInit() { + let _ = controller.textView.becomeFirstResponder() controller.setText("Hello World") // Test adding a position returns a valid one