Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): add support for static span colors #485

Merged
merged 4 commits into from
Sep 22, 2023

Conversation

itsaky
Copy link
Contributor

@itsaky itsaky commented Sep 16, 2023

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 background
  • STATIC_SPAN_FOREGROUND -> for the foreground

Here is a demo implementation of the feature (the color is same for all string tokens) :

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 :

  • Draw the selection region after the span background is drawn.
  • Skip drawing the span background if it is in the selection region.
  • Invert the span background color by if it is in the selection region.

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 the Span 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.

@itsaky itsaky marked this pull request as draft September 16, 2023 03:42
@itsaky itsaky marked this pull request as ready for review September 19, 2023 08:43
@Rosemoe Rosemoe merged commit 3e42482 into Rosemoe:main Sep 22, 2023
2 checks passed
@Rosemoe
Copy link
Owner

Rosemoe commented Sep 22, 2023

Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants