Text attachment not deleted from NSTextView

  • Hi all,

    I'm having a problem with NSTextView: I programmatically insert an
    image attachment into an NSTextView. However, when I delete the text
    from my GUI the image didn't go away, even though from the code, I can
    see that NSAttachmentCharacter is removed from my attributed string.

    Here's the code I'm using:

    NSFileWrapper * fw = [[NSFileWrapper alloc]
    initWithPath:@"somefile.gif"];
    NSTextAttachment * attachment = [[NSTextAttachment alloc]
    initWithFileWrapper:fw];
    NSAttributedString * string = [NSAttributedString
    attributedStringWithAttachment:attachment];

    [[textView textStorage] appendAttributedString: string];

    Some additional info if they help:
    * The image is an animated gif file
    * I use automatic garbage collection - could it be that GC is not
    finalizing my objects in time?

    Thanks,
    Luong.
  • On May 1, 2008, at 4:51 PM, Luong Dang wrote:
    > Hi all,
    >
    > I'm having a problem with NSTextView: I programmatically insert an
    > image attachment into an NSTextView. However, when I delete the
    > text from my GUI the image didn't go away, even though from the
    > code, I can see that NSAttachmentCharacter is removed from my
    > attributed string.
    >
    > Here's the code I'm using:
    >
    > NSFileWrapper * fw = [[NSFileWrapper alloc]
    > initWithPath:@"somefile.gif"];
    > NSTextAttachment * attachment = [[NSTextAttachment alloc]
    > initWithFileWrapper:fw];
    > NSAttributedString * string = [NSAttributedString
    > attributedStringWithAttachment:attachment];
    >
    > [[textView textStorage] appendAttributedString: string];
    >
    > Some additional info if they help:
    > * The image is an animated gif file
    > * I use automatic garbage collection - could it be that GC is not
    > finalizing my objects in time?

    How do you delete the text? Code or keyboard?

    Couldn't it just be a refresh missing?
  • I added a button to manually refresh the NSTextView, but things don't
    change at all.

    On 2-May-08, at 4:24 AM, St├ęphane Sudre wrote:

    >
    > On May 1, 2008, at 11:19 PM, Luong Dang wrote:
    >> It's from the keyboard. Basically, I just hit the Delete key.
    >>
    >> I also noticed that in Interface Builder's test mode, I can drag
    >> the file into the NSTextView and it will delete the image just fine.
    >
    > If you then force a refresh of the text view with
    > setNeedsDisplay:YES for instance, is the image still visible?
    >
    >
previous month may 2008 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today