Abstracted the syntax highlighter from text edit. #17923
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR abstracts out the syntax highlighting from the draw section of
TextEdit
allowing custom highlighters to be used.There is a new class called
SyntaxHighlighter
of which all syntax highlighters must extend. AllTextEdits
andSyntaxHighlighters
have a 1 to 1 relationship, so aSyntaxHighlighter
cannot serve multipleTextEdits
and vice versa.If the
TextEdit
is not given aSyntaxHighlighter
or is set toNULL
it will go ahead a use a modified version of the current system.The
SyntaxHighlighter::_get_line_syntax_highlighting
will get called for every line that we are drawing. ReturningMap<int, HighlighterInfo>
where the key is the column start of the section andHighlighterInfo
a new struct directing how this section should be drawn. Currently it can only change the colour. The section ends when the end of line is reached or a new section is found.There is also a new function in
ScriptEditorPlugin
to registerSyntaxHighlighter
creation functions. Now when a newScriptEditor
is created theSyntaxHighlighters
will also be created and added.When adding
SyntaxHighlighters
it will check if it supports the scripts language, if a match is found that highlighter will be automatically selected.The
ScriptTextEditor
has gained a new drop down menu itemSyntax Highlighter
listing all the addedSyntaxHighlighters
giving you the ability to change the current highlighter on the fly.I've also included a
GDSyntaxHighlighter
that is currently identical to the default one, ready for adding GDScript specific use cases.Lastly, in the process I've had to remove the encapsulation around some of the internal
TextEdit
implementation and hopefully made calculatingColorRegion(s)
slightly more performance friendly.closes #15691