Skip to content

Commit

Permalink
Merge pull request #303 from smalik2811/fix-cursor-movement-command-bar
Browse files Browse the repository at this point in the history
fix(command-bar): move cursor to end of input after typing
  • Loading branch information
andrewtavis authored Jan 24, 2025
2 parents eb7240c + 924cd09 commit db94d03
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
38 changes: 33 additions & 5 deletions app/src/main/java/be/scri/services/GeneralKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ abstract class GeneralKeyboardIME(
var nounTypeSuggestion: List<String>? = null
var checkIfPluralWord: Boolean = false
private var currentEnterKeyType: Int? = null
private val commandChar = ""
// abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding

protected var currentState: ScribeState = ScribeState.IDLE
Expand Down Expand Up @@ -816,6 +817,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,
Expand All @@ -827,10 +849,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)) {
Expand Down Expand Up @@ -870,7 +889,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 {
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/res/layout/keyboard_view_keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@
app:layout_constraintStart_toEndOf="@+id/scribe_key"
app:layout_constraintTop_toTopOf="@+id/command_field" />

<View
<TextView
android:id="@+id/prompt_text_border"
android:layout_width="1.5dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/black"
app:layout_constraintTop_toTopOf="@+id/prompt_text"
android:background="@drawable/cmd_bar_prompt_background"
android:text=""
android:textFontWeight="500"
android:textSize="16sp"
app:layout_constraintBaseline_toBaselineOf="@+id/command_bar"
app:layout_constraintBottom_toBottomOf="@+id/prompt_text"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintEnd_toEndOf="@+id/prompt_text"
app:layout_constraintHorizontal_bias="1.0" />
app:layout_constraintEnd_toStartOf="@+id/command_bar"
app:layout_constraintStart_toEndOf="@+id/prompt_text"
app:layout_constraintTop_toTopOf="@+id/prompt_text" />


<Button
Expand Down

0 comments on commit db94d03

Please sign in to comment.