Skip to content

fix: RichTextView share/copy produces empty content when textView is nil#369

Merged
kean merged 1 commit into
kean:mainfrom
mehmetozkn:fix/copy-text-storage-fallback
Jun 10, 2026
Merged

fix: RichTextView share/copy produces empty content when textView is nil#369
kean merged 1 commit into
kean:mainfrom
mehmetozkn:fix/copy-text-storage-fallback

Conversation

@mehmetozkn

Copy link
Copy Markdown

Problem:

When using Pulse inside a UIKit app (via UIHostingController), tapping the share button on a detail page (response body, request body, headers etc.) and selecting "Copy as Text", "Copy as HTML", or "Copy as PDF" copies empty content to the clipboard.

The root cause is in RichTextViewModel.textStorage:

// Current
var textStorage: NSTextStorage { textView?.textStorage ?? NSTextStorage(string: "") }

textView is a weak var set by WrappedTextView (a UIViewRepresentable). In UIKit-hosted environments, SwiftUI's view lifecycle differs from a pure SwiftUI app — textView can be nil at the moment the share button closure executes. When that happens, textStorage returns an empty NSTextStorage, resulting in empty clipboard content.

This does not reproduce in pure SwiftUI apps because the view lifecycle keeps textView alive consistently.

Fix:

Fall back to originalText instead of an empty string when textView is nil:

// Fixed
var textStorage: NSTextStorage { textView?.textStorage ?? NSTextStorage(attributedString: originalText) }

originalText is always populated — it holds the fully rendered attributed string set during initialization. This ensures share/copy always produces the correct content regardless of textView's lifecycle state.

@mehmetozkn

Copy link
Copy Markdown
Author

Friendly ping on this PR 👋

Could someone please approve the workflow and review the proposed fix when convenient? I've documented the issue, root cause, and fix details in the PR description.

Thanks!
@kean

@kean

kean commented Jun 10, 2026

Copy link
Copy Markdown
Owner

I appreciate the fix, thank you! 🙇

@kean kean merged commit 94b9273 into kean:main Jun 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants