Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(command-bar): move cursor to end of input after typing #303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading