• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Attribute ranges & string ranges
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Attribute ranges & string ranges


  • Subject: Attribute ranges & string ranges
  • From: Jeremy Dronfield <email@hidden>
  • Date: Mon, 2 Sep 2002 17:23:12 +0100

Hello All,
Given an NSAttributedString, what is the difference, if any, between the range of a given substring and the range of its attributes? It seems there must be a difference, because I can't get the following code to work properly. I'm trying to implement a text finder which will pick up style attributes - e.g. the words "find me" underlined but not italic. This is the latest version of the experimental code I'm using (it's an adaptation of TextEdit's TextFinder primitive), which is designed just to test whether a found substring is underlined:

- (IBAction)findAction:(id)sender
{
NSString *textContents = [textView string];
unsigned textLength;
if (textContents && (textLength = [textContents length])) {
NSRange range;
unsigned options = 0;
if ([caseCheckbox state]) options |= NSCaseInsensitiveSearch;
range = [textContents findString:[findField stringValue] selectedRange:[textView selectedRange] options:options wrap:YES];
if (range.length) {
id attributeValue;
NSNumber *underlined = [NSNumber numberWithInt:NSSingleUnderlineStyle];
attributeValue = [[textView textStorage] attribute:NSUnderlineStyleAttributeName atIndex:range.location effectiveRange:nil];
if ([attributeValue isEqualToNumber:underlined]) {
[textView setSelectedRange:range];
[textView scrollRangeToVisible:range];
}
}
}
}
NB: -findString: calls an implementation of NStringTextFinding which relies on -rangeOfString: for finding.

What makes me think there must be a difference between string/attribute ranges is that the method only works if the distance between the start-point of the search and the first match is not too great (say a couple of hundred characters). Help.
-Jeremy

========================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Newbie: two tables on one window, how to talk to them?
  • Next by Date: Re: Newbie: two tables on one window, how to talk to them?
  • Previous by thread: Re: NSTableView : what about "footer" ?
  • Next by thread: NSLocalizedString() doesn't work any more
  • Index(es):
    • Date
    • Thread