Finding the active Text View.
Finding the active Text View.
- Subject: Finding the active Text View.
- From: Lloyd Thompson <email@hidden>
- Date: Tue, 5 Oct 2004 17:47:13 -0500
Hey everybody,
I'm developing an app that has multiple NSTextViews and I need to find a way to return the currently active Text View. So, for example, a function that adds a trait to a font, will work between multiple text views and not just in one text field. Here's some code I'm working with - an action that grabs selected text from a textView, puts that into a MutableAttributedString, and applies a new font to that selected area.
- (id)sender
{
NSFont *font;
NSTextStorage *storage = [textView textStorage];
NSMutableAttributedString *attributedString = storage;
[storage beginEditing];
NSRange range = [textView selectedRange];
NSRange fontRange;
unsigned idx = range.location;
while (NSLocationInRange(idx, range)) {
font = [attributedString attribute:NSFontAttributeName atIndex:idx
longestEffectiveRange:&fontRange inRange:range];
fontRange = NSIntersectionRange(fontRange, range);
font = [[NSFontManager sharedFontManager] convertFont:font
toHaveTrait:NSBoldFontMask];
[attributedString addAttribute:NSFontAttributeName value:font range:fontRange];
idx = NSMaxRange(fontRange);
}
[storage endEditing];
}
Thanks!
Lloyd _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden