Reputation:
Clarification: First, cursor = the insertion point cursor, not the mouse cursor.
Ok, I would like to return the font / font size / font color wherever the cursor is in the NSTextView. I tried using attribute:atIndex:effectiveRange:
, but I failed because I got my variables all mixed up. I think it is what I need. Some example code would just be appreciated, return
ing the font. I think it will work the same for font size/color, I'll just have to substitute NSFontAttributeName
for something else, right? Thanks in advance!
Upvotes: 1
Views: 444
Reputation: 381
NSFont *font = [textView.textStorage attribute:NSFontAttributeName atIndex:textView.selectedRange.location effectiveRange:nil];
Should work for all getting the name.
Upvotes: 1
Reputation: 53000
What have you tried?
NSTextView
has a method selectedRanges
which returns the current selection(s) - just one of zero-length if there is just an insertion point.
NSTextView
also has a property textStorage
which returns back the instance of NSTextStorage
which holds the text. An NSTextStorage
inherits from NSMutableAttributedString
, which inherits from NSAttributedString
, and that has methods to obtain the attributes of the text.
Combined those two and you have your answer.
HTH
Upvotes: 0