Create new TextAttributesKey by inheriting from existing one


For the syntax highlighter in my custom language plugin, I want to create a new TextAttributesKey by inheriting from `DefaultLanguageHighlighterColors.KEYWORD` and changing the font type to italic.

Please note that I find the answers in unsatisfactory, as I don't want to deal with themes -- I'd like a solution that works for any theme.

Comment actions Permalink

Inheritance here always means inheriting all attributes. User should modify "Defaults" only and all inheritors will change accordingly. This will not work if you inherit AND modify some attributes. You'll need to define custom attributes as detailed in the linked thread to have full control.

Comment actions Permalink

I must admit I don't really understand that concept.  Is this also the reason why createTextAttributesKey with externalName and defaultAttributes is deprecated in favor of using externalName and fallbackAttributeKey?

Anyway, in the example above, I want to copy the KEYWORD attribute to make an italic version of it.  Why can't I do this programmatically at run time instead of configuring it with explicit knowledge of themes?  I'd like to do this specifically to keep consistency across themes.  If I did this the way described this would absolutely fail for new themes, but not if I can do it my way.

Comment actions Permalink

There's a


but that doesn't work for the Syntax Highlighter.

Comment actions Permalink

I did it, but it is not pretty as the other definitions:

public MySyntaxHighlighter() {
TextAttributes myAttr = new TextAttributes();
XINSTRUCTION = createTextAttributesKey("MY_XINSTR", myAttr);

But I really wouldn't know how to do this if the deprecated method went away.


Please sign in to leave a comment.