Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PlatformTextInputService2 #1853

Open
wants to merge 1 commit into
base: jb-main
Choose a base branch
from

Conversation

m-sasha
Copy link
Member

@m-sasha m-sasha commented Feb 18, 2025

This is a WIP PR for transitioning the implementation of BTF2 away from using PlatformTextInputService and TextFieldValue.

@m-sasha m-sasha force-pushed the m-sasha/text-input-service-2 branch from a22af3e to d303828 Compare February 18, 2025 10:22
updateTextFieldValue(newValue.toTextFieldValue())
val outputValueFlow = callbackFlow {
state.collectImeNotifications { oldValue, newValue, restartIme ->
println("IME Notification: oldValue=$oldValue, newValue=$newValue, restartIme=$restartIme")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove or wrap into some private debug flag

* If there aren't enough codepoints in the correct direction, returns 0 (if [offset] is negative)
* or the length of the char sequence (if [offset] is positive).
*/
private fun CharSequence.indexOfCodePointAtOffset(index: Int, offset: Int): Int {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not obvious logic, it's better to cover this function with tests separately

fun setComposingText(text: CharSequence, newCursorPosition: Int)
}

interface PlatformTextInputService2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All public APIs should be covered by KDocs

//
// continuation.invokeOnCancellation {
// textInputService.stopInput()
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code before the merge

import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.text.TextRange

interface TextEditorState : CharSequence {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make it stable from the start?

Base automatically changed from m-sasha/pass-focusedRectInRoot-as-flow to jb-main February 21, 2025 22:23
@m-sasha m-sasha force-pushed the m-sasha/text-input-service-2 branch from d303828 to 56c4edb Compare February 21, 2025 22:28
private fun TextFieldCharSequence.asTextEditorState() = object : TextEditorState {

override val length: Int
get() = this@asTextEditorState.length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to override this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole wrapper is because TextFieldCharSequence is in foundation, but PlatformTextInputService(2) is in ui. So foundation needs to wrap it in an interface that's available in ui.

override val composition: TextRange?
get() = this@asTextEditorState.composition

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same question about all overrides - I miss the context - for me this looks like redundant delegation - why we are doing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants