Attachment is displayed incorrectly

In the recent MacOS Sequoia Beta 3 NSTextAttachment initialized with custom data and an Image cell as attachmentCell are shown as a file icon istead of the image cell.

I am creating a NSAttributedString and showing it in NSTextView like this:

NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:[text dataUsingEncoding:NSUTF8StringEncoding] ofType:nil];
    attachment.attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:img];
    
    NSMutableAttributedString *res = [[NSMutableAttributedString alloc] initWithAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
...

I'm seeing the same issue with the release candidate. Did you ever find a solution or workaround?

In my case this is happening with a custom subclass of NSSearchField.

I've tested various options for custom attachment drawing, and the only one I can get to work consistently on macOS 15.0 Release Candidate is setting the image property of the text attachment. I'm using NSImage.init(size:flipped:drawingHandler:) to do custom drawing, similar to what I was previously doing in NSTextAttachmentCell.draw(withFrame:in:characterIndex:). I also set the bounds of the text attachment to adjust the position of the attachment, which I was previously doing with NSTextAttachmentCell.cellBaselineOffset(). The one thing I haven't been able to accomplish with this approach is changing the appearance of the attachment when it's selected.

I also experimented with view-based text attachments, using NSTextAttachmentViewProvider. This worked well in an NSTextView, but in an NSTextField or NSSearchField, the custom view would only show when the text field was first responder. I can't find any clear documentation on how view-based text attachments are meant to be used, so I'm not sure if there's any way to work around that problem.

I've filed a bug report on this issue, FB15109146.

Attachment is displayed incorrectly
 
 
Q