Skip to content

Commit f78037f

Browse files
committed
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
1 parent 0493e1b commit f78037f

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

app/src/main/java/be/scri/services/GeneralKeyboardIME.kt

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ abstract class GeneralKeyboardIME(
8282
var autosuggestEmojis: MutableList<String>? = null
8383
var nounTypeSuggestion: MutableList<String>? = null
8484
private var currentEnterKeyType: Int? = null
85+
private val commandChar = ""
8586
// abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding
8687

8788
protected var currentState: ScribeState = ScribeState.IDLE
@@ -689,6 +690,27 @@ abstract class GeneralKeyboardIME(
689690
}
690691
}
691692

693+
private fun handleCommandBarDelete(binding: KeyboardViewKeyboardBinding?) {
694+
binding?.commandBar?.let { commandBar ->
695+
var newText = ""
696+
if (commandBar.text.length <= 2) {
697+
binding.promptTextBorder?.visibility = View.VISIBLE
698+
binding.commandBar.setPadding(
699+
binding.commandBar.paddingRight,
700+
binding.commandBar.paddingTop,
701+
binding.commandBar.paddingRight,
702+
binding.commandBar.paddingBottom,
703+
)
704+
if (language == "German" && this.currentState == ScribeState.PLURAL) {
705+
keyboard?.mShiftState = SHIFT_ON_ONE_CHAR
706+
}
707+
} else {
708+
newText = "${commandBar.text.trim().dropLast(2)}$commandChar"
709+
}
710+
commandBar.text = newText
711+
}
712+
}
713+
692714
fun handleDelete(
693715
currentState: Boolean? = false,
694716
binding: KeyboardViewKeyboardBinding? = null,
@@ -700,10 +722,7 @@ abstract class GeneralKeyboardIME(
700722
}
701723

702724
if (currentState == true) {
703-
binding?.commandBar?.let { commandBar ->
704-
val newText = "${commandBar.text.trim().dropLast(1)}"
705-
commandBar.text = newText
706-
}
725+
handleCommandBarDelete(binding)
707726
} else {
708727
val selectedText = inputConnection.getSelectedText(0)
709728
if (TextUtils.isEmpty(selectedText)) {
@@ -743,7 +762,16 @@ abstract class GeneralKeyboardIME(
743762

744763
if (commandBarState) {
745764
binding?.commandBar?.let { commandBar ->
746-
val newText = "${commandBar.text}$codeChar"
765+
if (commandBar.text.isEmpty()) {
766+
binding.promptTextBorder?.visibility = View.GONE
767+
binding.commandBar.setPadding(
768+
0,
769+
binding.commandBar.paddingTop,
770+
binding.commandBar.paddingRight,
771+
binding.commandBar.paddingBottom,
772+
)
773+
}
774+
val newText = "${commandBar.text.trim().dropLast(1)}$codeChar$commandChar"
747775
commandBar.text = newText
748776
}
749777
} else {

app/src/main/res/layout/keyboard_view_keyboard.xml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@
5353
app:layout_constraintStart_toEndOf="@+id/scribe_key"
5454
app:layout_constraintTop_toTopOf="@+id/command_field" />
5555

56-
<View
56+
<TextView
5757
android:id="@+id/prompt_text_border"
58-
android:layout_width="1.5dp"
58+
android:layout_width="wrap_content"
5959
android:layout_height="0dp"
60-
android:background="@android:color/black"
61-
app:layout_constraintTop_toTopOf="@+id/prompt_text"
60+
android:background="@drawable/cmd_bar_prompt_background"
61+
android:text=""
62+
android:textFontWeight="500"
63+
android:textSize="16sp"
64+
app:layout_constraintBaseline_toBaselineOf="@+id/command_bar"
6265
app:layout_constraintBottom_toBottomOf="@+id/prompt_text"
63-
app:layout_constraintHeight_percent="0.5"
64-
app:layout_constraintEnd_toEndOf="@+id/prompt_text"
65-
app:layout_constraintHorizontal_bias="1.0" />
66+
app:layout_constraintEnd_toStartOf="@+id/command_bar"
67+
app:layout_constraintStart_toEndOf="@+id/prompt_text"
68+
app:layout_constraintTop_toTopOf="@+id/prompt_text" />
6669

6770

6871
<Button

0 commit comments

Comments
 (0)