- if (m_textView) {
- NSTextStorage* storage = [m_textView textStorage];
- NSFont* font = [storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL];
+ if (m_textView && position >=0)
+ {
+ NSFont* font = NULL;
+ NSColor* bgcolor = NULL;
+ NSColor* fgcolor = NULL;
+ // NOTE: It appears that other platforms accept GetStyle with the position == length
+ // but that NSTextStorage does not accept length as a valid position.
+ // Therefore we return the default control style in that case.
+ if (position < [[m_textView string] length])
+ {
+ NSTextStorage* storage = [m_textView textStorage];
+ font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease];
+ bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
+ fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
+ }
+ else
+ {
+ NSDictionary* attrs = [m_textView typingAttributes];
+ font = [[attrs objectForKey:NSFontAttributeName] autorelease];
+ bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease];
+ fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease];
+ }
+