rhale1
KU Mac Geek
I've looked over my code but can't seem to find the error. "boldText" is the contents of an NSTextView. I want the contents to be placed in a string so that I can add the string to "theText" and insert it into my main document.
What happens is IB gives me a strange error. I'm attaching an image.
PS: This is an HTML Editor. That may be obvious due to the "b" tags.
What happens is IB gives me a strange error. I'm attaching an image.
Code:
- (IBAction)addBoldText:(id)sender
{
NSMutableString *boldText;
NSString *theText;
NSRange theRange;
NSRange rangeToSelect;
boldText = [theTextView string];
// build the string, trivial
theText = [NSString stringWithFormat:@"<b>%@</b>", boldText];
// Here we force the text view to become the first responder, so that the
// selection is visually displayed properly if there is no selection
[[theTextView window] makeFirstResponder:theTextView];
// insert the string that we've built above
[theTextView insertText:theText];
// get the current selected range (which will be right after
// the just inserted text)
theRange=[theTextView selectedRange];
// calculate the range that will contain the text that is contained within the
// <A></A> construct that we've just built. Odds are that the user may want to edit it.
// you may want to modify this so that holding down different modifier keys will
// provide you with different selection behaviours
rangeToSelect.location=(theRange.location-4)-[boldText length];
rangeToSelect.length=[boldText length];
[theTextView setSelectedRange:rangeToSelect];
// we're done! So we need to return YES
// returnValue=YES;
}
PS: This is an HTML Editor. That may be obvious due to the "b" tags.