@@ -20,15 +20,14 @@ import androidx.compose.ui.unit.sp
2020 * Defines how [CodeBlock]s are rendered.
2121 *
2222 * @param textStyle The [TextStyle] to use for the block.
23- * @param background The [Color] of a code block, drawn behind the text .
23+ * @param modifier The [Modifier] to use for the block .
2424 * @param padding The amount of space between the edge of the text and the edge of the background.
2525 * @param wordWrap Whether a code block breaks the lines or scrolls horizontally.
2626 */
2727@Immutable
2828public data class CodeBlockStyle (
2929 val textStyle : TextStyle ? = null ,
30- // TODO Make background just a modifier instead?
31- val background : Color ? = null ,
30+ val modifier : Modifier ? = null ,
3231 val padding : TextUnit ? = null ,
3332 val wordWrap : Boolean? = null
3433) {
@@ -40,13 +39,15 @@ public data class CodeBlockStyle(
4039private val DefaultCodeBlockTextStyle = TextStyle (
4140 fontFamily = FontFamily .Monospace
4241)
43- internal val DefaultCodeBlockBackground : Color = Color .LightGray .copy(alpha = .5f )
42+ internal val DefaultCodeBlockBackgroundColor : Color = Color .LightGray .copy(alpha = .5f )
43+ private val DefaultCodeBlockModifier : Modifier =
44+ Modifier .background(color = DefaultCodeBlockBackgroundColor )
4445private val DefaultCodeBlockPadding : TextUnit = 16 .sp
4546private const val DefaultCodeWordWrap : Boolean = true
4647
4748internal fun CodeBlockStyle.resolveDefaults () = CodeBlockStyle (
4849 textStyle = textStyle ? : DefaultCodeBlockTextStyle ,
49- background = background ? : DefaultCodeBlockBackground ,
50+ modifier = modifier ? : DefaultCodeBlockModifier ,
5051 padding = padding ? : DefaultCodeBlockPadding ,
5152 wordWrap = wordWrap ? : DefaultCodeWordWrap
5253)
@@ -78,17 +79,18 @@ internal fun CodeBlockStyle.resolveDefaults() = CodeBlockStyle(
7879) {
7980 val codeBlockStyle = currentRichTextStyle.resolveDefaults().codeBlockStyle!!
8081 val textStyle = currentTextStyle.merge(codeBlockStyle.textStyle)
82+ val modifier = codeBlockStyle.modifier!!
8183 val blockPadding = with (LocalDensity .current) {
8284 codeBlockStyle.padding!! .toDp()
8385 }
8486 val resolvedWordWrap = wordWrap ? : codeBlockStyle.wordWrap!!
8587
8688 CodeBlockLayout (
8789 wordWrap = resolvedWordWrap
88- ) { modifier ->
90+ ) { layoutModifier ->
8991 Box (
90- modifier = modifier
91- .background(color = codeBlockStyle.background !! )
92+ modifier = layoutModifier
93+ .then(modifier )
9294 .padding(blockPadding)
9395 ) {
9496 ProvideTextStyle (textStyle) {
0 commit comments