Skip to content

Commit

Permalink
Fix AppKit
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikBucher12 committed Mar 8, 2024
1 parent 5d7f5d4 commit 2c17847
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Editor/RichTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct RichTextEditor: ViewRepresentable {
public let scrollView = RichTextView.scrollableTextView()

public var textView: RichTextView {
scrollView.documentView as? RichTextView ?? RichTextView()
scrollView.documentView as? RichTextView ?? RichTextView(frame: .zero, textContainer: nil)
}
#endif

Expand Down
24 changes: 24 additions & 0 deletions Sources/RichTextKit/Editor/RichTextView_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ open class RichTextView: NSTextView, RichTextViewComponent {
super.paste(sender)
}

override public convenience init(frame: CGRect) {
let textLayoutManager = NSTextLayoutManager()
let textkit2Container = NSTextContainer()
textLayoutManager.textContainer = textkit2Container
let textContentStorage = NSTextContentStorage()
textContentStorage.addTextLayoutManager(textLayoutManager)

self.init(frame: frame, textContainer: textkit2Container)
}

override public init(frame: CGRect, textContainer: NSTextContainer?) {
let textLayoutManager = NSTextLayoutManager()
let textkit2Container = NSTextContainer()
textLayoutManager.textContainer = textkit2Container
let textContentStorage = NSTextContentStorage()
textContentStorage.addTextLayoutManager(textLayoutManager)

super.init(frame: frame, textContainer: textkit2Container)
}

required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

/**
Try to perform a certain drag operation, which will get
and paste images from the drag info into the text.
Expand Down

0 comments on commit 2c17847

Please sign in to comment.