Skip to content

Commit

Permalink
fix the text input to 2nd text field would clear the 1st text field i…
Browse files Browse the repository at this point in the history
…n GraphQL and gRPC UX tests
  • Loading branch information
sunny-chung committed Nov 2, 2024
1 parent 4f3358d commit d358b1b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.BigTextSimp
import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.BigTextTransformed
import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.BigTextTransformerImpl
import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.BigTextViewState
import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.abbr
import com.sunnychung.application.multiplatform.hellohttp.ux.bigtext.rememberAnnotatedBigTextFieldState
import com.sunnychung.application.multiplatform.hellohttp.ux.compose.TextFieldColors
import com.sunnychung.application.multiplatform.hellohttp.ux.compose.TextFieldDefaults
Expand Down Expand Up @@ -615,13 +616,14 @@ fun CodeEditorView(

// var bigTextValue by remember(textValue.text.length, textValue.text.hashCode()) { mutableStateOf<BigText>(BigText.createFromLargeString(text)) } // FIXME performance

LaunchedEffect(bigTextFieldState) {
LaunchedEffect(bigTextFieldState, onTextChange) {
bigTextFieldState.valueChangesFlow
.debounce(200.milliseconds().toMilliseconds())
.collect {
log.d { "bigTextFieldState change ${it.changeId}" }
onTextChange?.let { onTextChange ->
val string = it.bigText.buildCharSequence() as AnnotatedString
log.v { "${bigTextFieldState.text} : ${it.bigText} onTextChange(${string.text.abbr()})" }
onTextChange(string.text)
secondCacheKey.value = string.text
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private fun CoreBigMonospaceText(
}

fun onType(textInput: String) {
log.v { "key in '$textInput'" }
log.v { "$text key in '$textInput' ${viewState.hasSelection()}" }
if (viewState.hasSelection()) {
deleteSelection(isSaveUndoSnapshot = false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun rememberAnnotatedBigTextFieldState(initialValue: String = ""): Pair<MutableS
return secondCacheKey to state
}

private fun CharSequence.abbr(): CharSequence {
fun CharSequence.abbr(): CharSequence {
return if (this.length > 20) {
substring(0 .. 19)
} else {
Expand Down

0 comments on commit d358b1b

Please sign in to comment.