On 4, Jul, 2012, at 07:32 PM, Marco Tabini wrote:

> 
> On 2012-07-04, at 1:01 PM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:
> 
>> 
>> On 4, Jul, 2012, at 03:22 PM, Marco Tabini wrote:
>> 
>>>> Does anyone have any good suggestions as to how to update my search 
>>>> results when the underlying source text changes? Do I have to listen for 
>>>> all changes from the underlying text objects and try to adapt, or is there 
>>>> a better pattern for doing this? Xcode does this nicely: no matter what 
>>>> changes you make in the editor, the search results seem to be updated on 
>>>> the fly.
>>> 
>>> Couple of random suggestions:
>>> 
>>> * If you're using NSAttributedString, you can mark your search results by 
>>> assigning custom attributes to specific ranges of text; as the text 
>>> changes, those attributes will stick around and you can later find them 
>>> using the attribute retrieval methods (I believe that's what Xcode does).
>> 
>> Just a follow up on this. I guess I would have to clear all text 
>> attachements of a particular class from all files at the start of a search, 
>> right? Otherwise the attachments will build up over time. I don't actually 
>> save attributed text to disk (these are plain text files) but even so.  Does 
>> that make sense? I wondering how computationally expensive this will turn 
>> out to be.
> 
> That's correct. My experience has been that NSMutableAttributedString's 
> performance is pretty good, but YMMV depending on platform, complexity, and 
> size of the data. In my case, I wrote a Markdown syntax highlighter that 
> could handily manage multi-MB text files on a run-of-the-mill Macbook. I 
> guess there's no way to tell until you try :-)

At the risk of pushing my luck too far, I would like to ask one more thing on 
this topic. It turns out to be pretty easy for me to add my 'match' objects to 
the the text storages. I just needed to make the match class (TPDocumentMatch) 
a subclass of NSTextAttachment. Then once I've collected all my matches for a 
given file, I do

  [storage beginEditing];
  for (TPDocumentMatch *match in resultDoc.matches) {
    // attach the resultDoc to the text
    [storage addAttribute:NSAttachmentAttributeName value:match 
range:match.range];    
    NSLog(@"%@", [doc textStorage]);
  }  
  [storage endEditing];
  NSLog(@"%@", [doc textStorage]);

The problem I have is that the attachment is present according to the NSLog 
within the loop, but by the time we get to the NSLog outside the loop, the 
attachment has vanished. NSTextStorage is mutable, right? So adding my 
attributes like this should work, shouldn't it?

Any further clues are very welcome and much appreciated!

Martin


> 
> 
> —Mt.






_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to