From f78037f9273a2bd13900c9a6796ba39f42119015 Mon Sep 17 00:00:00 2001 From: SONU SINGH Date: Thu, 23 Jan 2025 17:50:25 +0530 Subject: [PATCH] fix(command-bar): move cursor to end of input after typing This commit addresses issue #286 by improving the cursor behavior within the command bar. Previously, the cursor remained fixed after the command prompt, even as the user typed input. This has been corrected so that the cursor now dynamically moves to the end of the input text as the user types, providing a more intuitive and user-friendly experience. Closes #286 --- .../be/scri/services/GeneralKeyboardIME.kt | 38 ++++++++++++++++--- .../res/layout/keyboard_view_keyboard.xml | 17 +++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/main/java/be/scri/services/GeneralKeyboardIME.kt index 0ea42e73..8bab7da6 100644 --- a/app/src/main/java/be/scri/services/GeneralKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/GeneralKeyboardIME.kt @@ -82,6 +82,7 @@ abstract class GeneralKeyboardIME( var autosuggestEmojis: MutableList? = null var nounTypeSuggestion: MutableList? = null private var currentEnterKeyType: Int? = null + private val commandChar = "⎜" // abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding protected var currentState: ScribeState = ScribeState.IDLE @@ -689,6 +690,27 @@ abstract class GeneralKeyboardIME( } } + private fun handleCommandBarDelete(binding: KeyboardViewKeyboardBinding?) { + binding?.commandBar?.let { commandBar -> + var newText = "" + if (commandBar.text.length <= 2) { + binding.promptTextBorder?.visibility = View.VISIBLE + binding.commandBar.setPadding( + binding.commandBar.paddingRight, + binding.commandBar.paddingTop, + binding.commandBar.paddingRight, + binding.commandBar.paddingBottom, + ) + if (language == "German" && this.currentState == ScribeState.PLURAL) { + keyboard?.mShiftState = SHIFT_ON_ONE_CHAR + } + } else { + newText = "${commandBar.text.trim().dropLast(2)}$commandChar" + } + commandBar.text = newText + } + } + fun handleDelete( currentState: Boolean? = false, binding: KeyboardViewKeyboardBinding? = null, @@ -700,10 +722,7 @@ abstract class GeneralKeyboardIME( } if (currentState == true) { - binding?.commandBar?.let { commandBar -> - val newText = "${commandBar.text.trim().dropLast(1)}" - commandBar.text = newText - } + handleCommandBarDelete(binding) } else { val selectedText = inputConnection.getSelectedText(0) if (TextUtils.isEmpty(selectedText)) { @@ -743,7 +762,16 @@ abstract class GeneralKeyboardIME( if (commandBarState) { binding?.commandBar?.let { commandBar -> - val newText = "${commandBar.text}$codeChar" + if (commandBar.text.isEmpty()) { + binding.promptTextBorder?.visibility = View.GONE + binding.commandBar.setPadding( + 0, + binding.commandBar.paddingTop, + binding.commandBar.paddingRight, + binding.commandBar.paddingBottom, + ) + } + val newText = "${commandBar.text.trim().dropLast(1)}$codeChar$commandChar" commandBar.text = newText } } else { diff --git a/app/src/main/res/layout/keyboard_view_keyboard.xml b/app/src/main/res/layout/keyboard_view_keyboard.xml index c8c51cdb..b672541b 100644 --- a/app/src/main/res/layout/keyboard_view_keyboard.xml +++ b/app/src/main/res/layout/keyboard_view_keyboard.xml @@ -53,16 +53,19 @@ app:layout_constraintStart_toEndOf="@+id/scribe_key" app:layout_constraintTop_toTopOf="@+id/command_field" /> - + app:layout_constraintEnd_toStartOf="@+id/command_bar" + app:layout_constraintStart_toEndOf="@+id/prompt_text" + app:layout_constraintTop_toTopOf="@+id/prompt_text" />