garbage text
This commit is contained in:
@@ -404,6 +404,7 @@ private struct FlowText: NSViewRepresentable {
|
|||||||
v.isHorizontallyResizable = false
|
v.isHorizontallyResizable = false
|
||||||
v.textContainerInset = .zero
|
v.textContainerInset = .zero
|
||||||
v.textContainer!.lineFragmentPadding = 0
|
v.textContainer!.lineFragmentPadding = 0
|
||||||
|
v.textContainer!.widthTracksTextView = true
|
||||||
v.linkTextAttributes = [.cursor: NSCursor.pointingHand]
|
v.linkTextAttributes = [.cursor: NSCursor.pointingHand]
|
||||||
v.delegate = context.coordinator
|
v.delegate = context.coordinator
|
||||||
return v
|
return v
|
||||||
@@ -423,10 +424,14 @@ private struct FlowText: NSViewRepresentable {
|
|||||||
|
|
||||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView v: FlowTextView, context: Context) -> CGSize? {
|
func sizeThatFits(_ proposal: ProposedViewSize, nsView v: FlowTextView, context: Context) -> CGSize? {
|
||||||
let width = proposal.width.flatMap { $0.isFinite ? $0 : nil }
|
let width = proposal.width.flatMap { $0.isFinite ? $0 : nil }
|
||||||
let container = v.textContainer!
|
let storage = NSTextStorage(attributedString: text)
|
||||||
container.size = CGSize(width: width ?? .greatestFiniteMagnitude, height: .greatestFiniteMagnitude)
|
let layout = NSLayoutManager()
|
||||||
v.layoutManager!.ensureLayout(for: container)
|
let container = NSTextContainer(size: CGSize(width: width ?? .greatestFiniteMagnitude, height: .greatestFiniteMagnitude))
|
||||||
let used = v.layoutManager!.usedRect(for: container)
|
container.lineFragmentPadding = 0
|
||||||
|
layout.addTextContainer(container)
|
||||||
|
storage.addLayoutManager(layout)
|
||||||
|
layout.ensureLayout(for: container)
|
||||||
|
let used = layout.usedRect(for: container)
|
||||||
return CGSize(width: width ?? ceil(used.width), height: ceil(used.height))
|
return CGSize(width: width ?? ceil(used.width), height: ceil(used.height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user