Fix scroll position not updating while typing in edit pane

This commit is contained in:
William Brawner 2024-11-06 21:39:22 -07:00
parent 2f5ebb28f6
commit 3b7a6fd57c
Signed by: wbrawner
GPG key ID: 8FF12381C6C90D35

View file

@ -1,21 +1,16 @@
package com.wbrawner.simplemarkdown.ui package com.wbrawner.simplemarkdown.ui
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.LocalTextSelectionColors import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -23,7 +18,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.SpanStyle
@ -70,16 +64,10 @@ fun MarkdownTextField(
fontFamily = FontFamily.Monospace, fontFamily = FontFamily.Monospace,
color = MaterialTheme.colorScheme.onSurface color = MaterialTheme.colorScheme.onSurface
) )
Column(
modifier = modifier
.fillMaxSize()
.imePadding()
.verticalScroll(rememberScrollState())
) {
CompositionLocalProvider(LocalTextSelectionColors provides colors.textSelectionColors) { CompositionLocalProvider(LocalTextSelectionColors provides colors.textSelectionColors) {
BasicTextField( BasicTextField(
value = textFieldValue, value = textFieldValue,
modifier = Modifier.fillMaxSize(), modifier = modifier.imePadding(),
onValueChange = setTextFieldAndViewModelValues, onValueChange = setTextFieldAndViewModelValues,
enabled = true, enabled = true,
readOnly = false, readOnly = false,
@ -106,10 +94,9 @@ fun MarkdownTextField(
colors = colors, colors = colors,
contentPadding = PaddingValues(8.dp) contentPadding = PaddingValues(8.dp)
) )
} },
) )
} }
}
} }
private fun String.annotate(enableReadability: Boolean): AnnotatedString { private fun String.annotate(enableReadability: Boolean): AnnotatedString {