feat(editor): add support for static span colors #485
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 adds support for static color spans in the editor.
Static color spans
Static color spans are spans whose background and foreground colors are pre-defined during the source code analysis. Two new color IDs have been added to
EditorColorScheme
:STATIC_SPAN_BACKGROUND
-> for the backgroundSTATIC_SPAN_FOREGROUND
-> for the foregroundHere is a demo implementation of the feature (the color is same for all string tokens) :
![](https://private-user-images.githubusercontent.com/46931079/268348068-d254b8e2-434b-407f-84b8-36c3860c24e8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNDUxMzgsIm5iZiI6MTcyMDI0NDgzOCwicGF0aCI6Ii80NjkzMTA3OS8yNjgzNDgwNjgtZDI1NGI4ZTItNDM0Yi00MDdmLTg0YjgtMzZjMzg2MGMyNGU4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA2VDA1NDcxOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjNGQ0NmNjNTMwN2FjMzU0NTIyN2FkY2Y5YjVkMDIzN2UxNDUzMzI3ZTFlZjJiMjYxMmU1ZDM3YTlkNjQ5ZmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.sGySSzbMpLd99dMsnsS5n6eCfPh8N4OvWD5lSEKxNkY)
Known issues
There is only one issue that I have noticed and it is not specifically related to this feature addition :
If a span has a custom background color and if that span is in the selection region, the span background color hides the selected text background color. This happens because the selection is drawn before the span (i.e. the span color overlaps the selection color).
This can be resolved by either :
The last two approaches should also handle the case where the span is partially in the selection region. These two approaches should be preferred in my opinion.
Additional changes
A new class (
SpanPool
) has been added to recycle and reuse theSpan
objects (and its subclasses by creating multiple pools). The implementation of the pool is same as what was being used earlier for caching. However, multiple pools can now be created with different capacities.