editor-fixes #94
1 changed files with 32 additions and 45 deletions
|
@ -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,45 +64,38 @@ fun MarkdownTextField(
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
)
|
)
|
||||||
Column(
|
CompositionLocalProvider(LocalTextSelectionColors provides colors.textSelectionColors) {
|
||||||
modifier = modifier
|
BasicTextField(
|
||||||
.fillMaxSize()
|
value = textFieldValue,
|
||||||
.imePadding()
|
modifier = modifier.imePadding(),
|
||||||
.verticalScroll(rememberScrollState())
|
onValueChange = setTextFieldAndViewModelValues,
|
||||||
) {
|
enabled = true,
|
||||||
CompositionLocalProvider(LocalTextSelectionColors provides colors.textSelectionColors) {
|
readOnly = false,
|
||||||
BasicTextField(
|
textStyle = textStyle,
|
||||||
value = textFieldValue,
|
cursorBrush = SolidColor(colors.cursorColor),
|
||||||
modifier = Modifier.fillMaxSize(),
|
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Sentences),
|
||||||
onValueChange = setTextFieldAndViewModelValues,
|
keyboardActions = KeyboardActions.Default,
|
||||||
enabled = true,
|
interactionSource = interactionSource,
|
||||||
readOnly = false,
|
singleLine = false,
|
||||||
textStyle = textStyle,
|
maxLines = Int.MAX_VALUE,
|
||||||
cursorBrush = SolidColor(colors.cursorColor),
|
minLines = 1,
|
||||||
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Sentences),
|
decorationBox = @Composable { innerTextField ->
|
||||||
keyboardActions = KeyboardActions.Default,
|
// places leading icon, text field with label and placeholder, trailing icon
|
||||||
interactionSource = interactionSource,
|
TextFieldDefaults.DecorationBox(
|
||||||
singleLine = false,
|
value = textFieldValue.text,
|
||||||
maxLines = Int.MAX_VALUE,
|
visualTransformation = VisualTransformation.None,
|
||||||
minLines = 1,
|
innerTextField = innerTextField,
|
||||||
decorationBox = @Composable { innerTextField ->
|
placeholder = {
|
||||||
// places leading icon, text field with label and placeholder, trailing icon
|
Text(stringResource(R.string.markdown_here))
|
||||||
TextFieldDefaults.DecorationBox(
|
},
|
||||||
value = textFieldValue.text,
|
singleLine = false,
|
||||||
visualTransformation = VisualTransformation.None,
|
enabled = true,
|
||||||
innerTextField = innerTextField,
|
interactionSource = interactionSource,
|
||||||
placeholder = {
|
colors = colors,
|
||||||
Text(stringResource(R.string.markdown_here))
|
contentPadding = PaddingValues(8.dp)
|
||||||
},
|
)
|
||||||
singleLine = false,
|
},
|
||||||
enabled = true,
|
)
|
||||||
interactionSource = interactionSource,
|
|
||||||
colors = colors,
|
|
||||||
contentPadding = PaddingValues(8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue