package com.suno.android.common_ui.extensions import androidx.compose.ui.text.input.TextFieldValue fun TextFieldValue.xGetCurrentlyEditingWord(): String { if (text.isEmpty() || this.selection.start < 0 || this.selection.start > text.length) { return "" } // Find the start of the word var startIndex = this.selection.start while (startIndex > 0 && (text[startIndex - 1].isLetterOrDigit() || text[startIndex - 1] == '@')) { startIndex-- } // Find the end of the word var endIndex = this.selection.start while (endIndex < text.length && (text[endIndex].isLetterOrDigit())) { endIndex++ } // Return the word if valid return if (startIndex < endIndex) text.substring(startIndex, endIndex) else "" }