Skip to content

Use coroutine to offload code highlighting to background thread#419

Merged
mikepenz merged 8 commits intomikepenz:developfrom
keta1:feat/code
Jul 4, 2025
Merged

Use coroutine to offload code highlighting to background thread#419
mikepenz merged 8 commits intomikepenz:developfrom
keta1:feat/code

Conversation

@keta1
Copy link
Contributor

@keta1 keta1 commented Jun 30, 2025

Description

  • Introduce "rememberHighlightsBuilder" function to provide default Highlights builder
  • Rename parameter highlights to  highlightsBuilder
  • Use coroutine to offload code highlighting to background thread

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build configuration change
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Test A
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@keta1 keta1 changed the title Feat/code Use coroutine to offload code highlighting to background thread Jun 30, 2025
@keta1 keta1 marked this pull request as ready for review June 30, 2025 09:17
@mikepenz
Copy link
Owner

mikepenz commented Jul 4, 2025

can you please rebase?

@keta1
Copy link
Contributor Author

keta1 commented Jul 4, 2025

Rebased and force-pushed

@mikepenz
Copy link
Owner

mikepenz commented Jul 4, 2025

Thank you very much for your contribution @keta1

keta1 and others added 7 commits July 4, 2025 12:52
…ighlights builder

This change
It defaults to using the `SyntaxThemes.atom` theme and respects the system dark mode setting.
The `highlights` parameter in `MarkdownHighlightedCodeFence`, `MarkdownIndentedCodeBlock`, and `MarkdownHighlightedCode` has been renamed to `highlightsBuilder` for clarity. This change ensures consistency in naming and better reflects the parameter's purpose.
This commit introduces the use of coroutines to perform code highlighting in the background. This improves performance by preventing the UI thread from being blocked during the highlighting process.

The `produceHighlightsState` composable function now launches a coroutine to calculate the highlights and updates the `AnnotatedString` state accordingly. This ensures that the UI remains responsive while the highlighting is in progress.
@mikepenz mikepenz merged commit 8343d17 into mikepenz:develop Jul 4, 2025
2 checks passed
@keta1 keta1 deleted the feat/code branch July 5, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants