Open ptorngren opened 5 months ago
I just created a Pull Request with the desired changes.
@ptorngren Could you do something like this? I think this was my original idea, updating the TokenMakerFactory
:
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory)TokenMakerFactory.getDfeaultInstance();
atmf.putMapping("text/myLanguage", "com.ptorngeren.MyTokenMaker");
Or, if you don't feel great about the casting, create a custom TokenMakerFactory that delegates to the original default if its set of keys don't match the input.
@ptorngren Could you do something like this? I think this was my original idea, updating the
TokenMakerFactory
:AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory)TokenMakerFactory.getDfeaultInstance(); atmf.putMapping("text/myLanguage", "com.ptorngeren.MyTokenMaker");
Sorry for late answer ....
Not sure, but I don't think it will do the trick. Don't remember the exact details, but we ended up calling the method I referenced for some reason. Still, even if the ATMF approach you suggest would work for us, it would still render the referenced method more or less unusable since I can never assign a style with the TokenMaker I set. It might also be the case that you need different TokenMakers for the same style, eg to handle different dialects of the same language (eg SQL).
PS: I also found a glitch in the PR I created:
RSyntaxTextArea.setSyntaxEditingStyle(TokenMaker, String)
only checks if the style key has changed and suppresses syntax highlighting updates if the key is unchanged. It should also check if the TokenMaker
is changed; if we assign a new TokenMaker
using the same style key, we still want the syntax highlighting to be updated, which the current code won't do.
Describe the solution you'd like I'd like to set the syntax based on a custom
TokenMaker
with a specific syntax style key that is assigned both to theRSyntaxTextArea
and theRSyntaxDocument
.Are there any workarounds? Not really.
RSyntaxDocument.setSyntaxStyle(TokenMaker)
always assigns the style keytext/unknown
andRSyntaxDocument.setSyntaxStyle(String)
always assigns aTokenMaker
that is fetched from thetokenMakerFactory
using the style key only.Additional context As stated in the javadoc for
RSyntaxDocument.setSyntaxStyle(TokenMaker)
, this is the recommended method to call if you've created a custom token maker for a language not normally supported by RSyntaxTextArea.Alas, there is no way to call the recommended method AND register a style key on the document, and there is no way to set the style key on the editor without also calling
RSyntaxDocument.setSyntaxStyle(styleKey)
and consequently setting a registeredTokenMaker
on the document. There is no way to call the recommended method without making the text area and the document hold different style keys, which effectively invalidates any items registered for a specific style in the editor (eg theFoldParserManager
).A simple fix would be to add a method that sets a
TokenMaker
and a style key to both theRSyntaxTextArea
andRSyntaxDocument
Sample code
RSyntaxDocument
RSyntaxTextArea