diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index 66031e4..75c067d 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -3901,6 +3901,9 @@ }; C9FE53B42A7677E800CACA1A /* PBXTargetDependency */ = { isa = PBXTargetDependency; + platformFilters = ( + macos, + ); productRef = C9FE53B32A7677E800CACA1A /* ScrollViewPlus */; }; C9FE53BB2A77353900CACA1A /* PBXTargetDependency */ = { @@ -4738,7 +4741,7 @@ repositoryURL = "https://github.com/mattmassicotte/nsui.git"; requirement = { kind = revision; - revision = b6c32973b2a9dc16c465f3e3bc44e9abb27d1683; + revision = 8792b2f789bf03be1be9ecb4df43d2bfe0e5d361; }; }; C9BFA1AE2BC0927A00E86487 /* XCRemoteSwiftPackageReference "Glyph" */ = { @@ -4786,7 +4789,7 @@ repositoryURL = "https://github.com/ChimeHQ/ThemePark"; requirement = { kind = revision; - revision = 0843e25fdcfc9e6e197b39d668c29d8892240f1b; + revision = 11b195dd9771226a6be2b032381b1a7fa3569621; }; }; C9FE52E62A75375300CACA1A /* XCRemoteSwiftPackageReference "ContainedDocument" */ = { diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ac455ec..6155d4e 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -135,7 +135,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattmassicotte/nsui.git", "state" : { - "revision" : "b6c32973b2a9dc16c465f3e3bc44e9abb27d1683" + "revision" : "8792b2f789bf03be1be9ecb4df43d2bfe0e5d361" } }, { @@ -228,7 +228,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/ThemePark", "state" : { - "revision" : "0843e25fdcfc9e6e197b39d668c29d8892240f1b" + "revision" : "11b195dd9771226a6be2b032381b1a7fa3569621" } }, { diff --git a/Edit/Modules/TextSystem/NSTextView+Additions.swift b/Edit/Modules/TextSystem/NSTextView+Additions.swift index e667e78..5fd2ea5 100644 --- a/Edit/Modules/TextSystem/NSTextView+Additions.swift +++ b/Edit/Modules/TextSystem/NSTextView+Additions.swift @@ -1,13 +1,13 @@ -import AppKit +import NSUI -extension NSTextView { +extension NSUITextView { func replaceTextStorage(_ newStorage: NSTextStorage) { - if let contentStorage = textContentStorage { + if let contentStorage = nsuiTextContentStorage { contentStorage.textStorage = newStorage return } - if let layoutManager = layoutManager { + if let layoutManager = nsuiLayoutManager { layoutManager.replaceTextStorage(newStorage) return } diff --git a/Edit/Modules/TextSystem/NSTextView+Mutations.swift b/Edit/Modules/TextSystem/NSTextView+Mutations.swift index 282652a..739fc3c 100644 --- a/Edit/Modules/TextSystem/NSTextView+Mutations.swift +++ b/Edit/Modules/TextSystem/NSTextView+Mutations.swift @@ -1,12 +1,14 @@ -import AppKit +import NSUI import DocumentContent -extension NSTextView { +extension NSUITextView { func applyMutations(_ mutations: [TextStorageMutation]) { + guard let storage = nsuiTextStorage else { fatalError() } + for mutation in mutations { for rangedString in mutation.stringMutations { - replaceCharacters(in: rangedString.range, with: rangedString.string) + storage.replaceCharacters(in: rangedString.range, with: rangedString.string) } } } diff --git a/Edit/Modules/TextSystem/TextLayout.swift b/Edit/Modules/TextSystem/TextLayout.swift index ecab94d..72cf3bd 100644 --- a/Edit/Modules/TextSystem/TextLayout.swift +++ b/Edit/Modules/TextSystem/TextLayout.swift @@ -7,29 +7,29 @@ import Rearrange public struct TextLayout { public struct LineFragment { public let range: NSRange - public let bounds: NSRect + public let bounds: CGRect } - public let visibleRect: () -> NSRect + public let visibleRect: () -> CGRect public let visibleSet: () -> IndexSet - public let lineFragmentsInRect: (NSRect) -> [LineFragment] + public let lineFragmentsInRect: (CGRect) -> [LineFragment] public let lineFragmentsInRange: (NSRange) -> [LineFragment] } extension TextLayout { @MainActor public init(textView: NSUITextView) { - self.init(container: textView.textContainer!) + self.init(container: textView.nsuiTextContainer!, textView: textView) } @MainActor - public init(container: NSTextContainer) { + public init(container: NSTextContainer, textView: NSUITextView) { self.init( visibleRect: { - container.textView!.visibleRect + textView.visibleRect }, visibleSet: { - container.textView!.visibleCharacterIndexes + textView.visibleCharacterIndexes }, lineFragmentsInRect: { rect in var fragments = [LineFragment]() diff --git a/Edit/Modules/TextSystem/TextPresentation.swift b/Edit/Modules/TextSystem/TextPresentation.swift index 268bc94..03cbff5 100644 --- a/Edit/Modules/TextSystem/TextPresentation.swift +++ b/Edit/Modules/TextSystem/TextPresentation.swift @@ -1,6 +1,6 @@ -import AppKit import Foundation +import NSUI import Rearrange public struct TextPresentation { @@ -9,16 +9,16 @@ public struct TextPresentation { extension TextPresentation { @MainActor - public init(textView: NSTextView) { + public init(textView: NSUITextView) { if let textLayoutManager = textView.textLayoutManager { - self.init(textLayoutManager: textLayoutManager) + self.init(textLayoutManager: textLayoutManager, textView: textView) } else { - self.init(layoutManager: textView.layoutManager!) + self.init(layoutManager: textView.nsuiLayoutManager!) } } @MainActor - public init(textLayoutManager: NSTextLayoutManager) { + public init(textLayoutManager: NSTextLayoutManager, textView: NSUITextView) { self.init( applyRenderingStyle: { attrs, range in guard @@ -28,17 +28,13 @@ extension TextPresentation { return } - let textView = textLayoutManager.textContainer?.textView - - let selection = textView?.selectedRanges + let selection = textView.selectedRanges textLayoutManager.setRenderingAttributes(attrs, for: textRange) - textView?.selectedRanges = [NSValue(range: range)] + textView.selectedRanges = [NSValue(range: range)] - if let selection { - textView?.selectedRanges = selection - } + textView.selectedRanges = selection } ) } @@ -47,7 +43,11 @@ extension TextPresentation { public init(layoutManager: NSLayoutManager) { self.init( applyRenderingStyle: { attrs, range in +#if os(macOS) layoutManager.setTemporaryAttributes(attrs, forCharacterRange: range) +#else + print("unsupported rendering style") +#endif } ) } diff --git a/Edit/Modules/TextSystem/TextViewSystem.swift b/Edit/Modules/TextSystem/TextViewSystem.swift index 6880df9..e6d72ef 100644 --- a/Edit/Modules/TextSystem/TextViewSystem.swift +++ b/Edit/Modules/TextSystem/TextViewSystem.swift @@ -1,8 +1,8 @@ -import AppKit import Foundation import ChimeKit import DocumentContent +import NSUI import TextStory import Theme @@ -17,10 +17,10 @@ public final class TextViewSystem: NSObject { private var contentVersion = 0 public private(set) var contentIdentity = DocumentContentIdentity() - let textView: NSTextView + let textView: NSUITextView public private(set) var textMetrics: TextMetrics - public init(textView: NSTextView) { + public init(textView: NSUITextView) { self.textView = textView self.textMetrics = TextMetrics(storage: Storage.null()) @@ -67,15 +67,17 @@ extension TextViewSystem { } private func beginEditing() { - textView.textStorage?.beginEditing() + textView.nsuiTextStorage?.beginEditing() } private func endEditing() { - textView.textStorage?.endEditing() + textView.nsuiTextStorage?.endEditing() contentVersion += 1 +#if os(macOS) textView.didChangeText() +#endif } private func length(for version: Version) -> Int? { @@ -83,11 +85,11 @@ extension TextViewSystem { return nil } - return textView.textStorage?.length + return textView.nsuiTextStorage?.length } private func substring(range: NSRange, version: Version) throws -> String { - guard let storage = textView.textStorage else { + guard let storage = textView.nsuiTextStorage else { throw TextStorageError.underlyingStorageInvalid } @@ -186,7 +188,7 @@ extension TextViewSystem { } public func themeChanged(attributes: [NSAttributedString.Key: Any]) { - guard let storage = textView.textStorage else { + guard let storage = textView.nsuiTextStorage else { fatalError("") } @@ -209,6 +211,7 @@ extension TextViewSystem { //} extension TextViewSystem: TSYTextStorageDelegate { +#if os(macOS) public nonisolated func textStorage(_ textStorage: TSYTextStorage, doubleClickRangeForLocation location: UInt) -> NSRange { textStorage.internalStorage.doubleClick(at: Int(location)) } @@ -216,4 +219,5 @@ extension TextViewSystem: TSYTextStorageDelegate { public nonisolated func textStorage(_ textStorage: TSYTextStorage, nextWordIndexFromLocation location: UInt, direction forward: Bool) -> UInt { UInt(textStorage.internalStorage.nextWord(from: Int(location), forward: forward)) } +#endif } diff --git a/Edit/Modules/Theme/ThemeStore.swift b/Edit/Modules/Theme/ThemeStore.swift index 287d1c2..8e80c14 100644 --- a/Edit/Modules/Theme/ThemeStore.swift +++ b/Edit/Modules/Theme/ThemeStore.swift @@ -46,19 +46,23 @@ public final class ThemeStore { } private func loadXcodeThemes() { +#if os(macOS) for (name, theme) in XcodeTheme.all { let identity = Theme.Identity(source: .xcode, name: name) cacheStyler(theme, with: identity) } +#endif } private func loadTextMateThemes() { +#if os(macOS) for theme in TextMateTheme.all { let identity = Theme.Identity(source: .textmate, name: theme.name) cacheStyler(theme, with: identity) } +#endif } private func cacheStyler(_ styler: any Styling, with identity: Theme.Identity) { diff --git a/Edit/Modules/UIUtility/RoundedCorners.swift b/Edit/Modules/UIUtility/RoundedCorners.swift index 9c940ea..a0934bc 100644 --- a/Edit/Modules/UIUtility/RoundedCorners.swift +++ b/Edit/Modules/UIUtility/RoundedCorners.swift @@ -67,5 +67,3 @@ extension View { clipShape(RoundedCornersShape(radius: radius, corners: corners) ) } } - -