Skip to content

Commit

Permalink
Use Glyph for text presentation attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Dec 6, 2024
1 parent 8f6b88d commit 8f4d588
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5440,7 +5440,7 @@
repositoryURL = "https://github.com/ChimeHQ/Glyph";
requirement = {
kind = revision;
revision = 28adcfc8585d119fac720dcb0c9123ee2148efec;
revision = 3c8095830e9b682f22bdaa866a1f2061998e40cc;
};
};
C9C568562B7418B60093C068 /* XCRemoteSwiftPackageReference "Lowlight" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/Glyph",
"state" : {
"revision" : "28adcfc8585d119fac720dcb0c9123ee2148efec"
"revision" : "3c8095830e9b682f22bdaa866a1f2061998e40cc"
}
},
{
Expand Down
39 changes: 2 additions & 37 deletions Edit/Modules/TextSystem/TextPresentation.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

import Glyph
import NSUI
import Rearrange

public struct TextPresentation {
public let applyRenderingStyle: ([NSAttributedString.Key : Any], NSRange) -> Void
Expand All @@ -10,44 +10,9 @@ public struct TextPresentation {
extension TextPresentation {
@MainActor
public init(textView: NSUITextView) {
if let textLayoutManager = textView.textLayoutManager {
self.init(textLayoutManager: textLayoutManager, textView: textView)
} else {
self.init(layoutManager: textView.nsuiLayoutManager!)
}
}

@MainActor
public init(textLayoutManager: NSTextLayoutManager, textView: NSUITextView) {
self.init(
applyRenderingStyle: { attrs, range in
guard
let contentManager = textLayoutManager.textContentManager,
let textRange = NSTextRange(range, provider: contentManager)
else {
return
}

let selection = textView.selectedRanges

textLayoutManager.setRenderingAttributes(attrs, for: textRange)

textView.selectedRanges = [NSValue(range: range)]

textView.selectedRanges = selection
}
)
}

@MainActor
public init(layoutManager: NSLayoutManager) {
self.init(
applyRenderingStyle: { attrs, range in
#if os(macOS)
layoutManager.setTemporaryAttributes(attrs, forCharacterRange: range)
#else
print("unsupported rendering style")
#endif
textView.setRenderingAttributes(attrs, for: range)
}
)
}
Expand Down

0 comments on commit 8f4d588

Please sign in to comment.