fixed backspace issue
This commit is contained in:
parent
8120191874
commit
de9592764a
@ -154,10 +154,30 @@ class MyKeyboardService : InputMethodService() {
|
|||||||
private fun onBackspace() {
|
private fun onBackspace() {
|
||||||
Log.d("MyKeyboardService", "onBackspace called")
|
Log.d("MyKeyboardService", "onBackspace called")
|
||||||
val inputConnection = currentInputConnection ?: return
|
val inputConnection = currentInputConnection ?: return
|
||||||
inputConnection.deleteSurroundingText(1, 0)
|
|
||||||
|
|
||||||
|
// Only make API request if we still have text
|
||||||
if (currentInput.isNotEmpty()) {
|
if (currentInput.isNotEmpty()) {
|
||||||
currentInput = currentInput.substring(0, currentInput.length - 1)
|
currentInput = currentInput.substring(0, currentInput.length - 1)
|
||||||
|
coroutineScope.launch {
|
||||||
|
try {
|
||||||
|
val response = withContext(Dispatchers.IO) {
|
||||||
|
RetrofitClient.googleInputToolsApiService.getInputSuggestions(currentInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
val parsedResponse = parseResponse(response)
|
||||||
|
val options = parsedResponse.results.flatMap { it.options }
|
||||||
|
|
||||||
|
Log.d("MyKeyboardService", "Parsed options after backspace: $options")
|
||||||
|
displaySuggestions(options)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("MyKeyboardService", "Error in API call after backspace", e)
|
||||||
|
displaySuggestions(listOf("Error: ${e.message}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputConnection.deleteSurroundingText(1, 0)
|
||||||
|
// Clear suggestions if we've deleted all text
|
||||||
|
suggestionsContainer.removeAllViews()
|
||||||
}
|
}
|
||||||
Log.d("MyKeyboardService", "Current input after backspace: $currentInput")
|
Log.d("MyKeyboardService", "Current input after backspace: $currentInput")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user