Skip to content

Commit 57151aa

Browse files
authored
Fixing enter action. Fixes dessalines#136 (dessalines#506)
1 parent aeb01d8 commit 57151aa

File tree

1 file changed

+26
-17
lines changed
  • app/src/main/java/com/dessalines/thumbkey/utils

1 file changed

+26
-17
lines changed

app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import kotlin.math.sqrt
4545
const val TAG = "com.thumbkey"
4646

4747
const val THUMBKEY_IME_NAME = "com.dessalines.thumbkey/.IMEService"
48+
const val IME_ACTION_CUSTOM_LABEL = EditorInfo.IME_MASK_ACTION + 1
4849

4950
@Composable
5051
fun colorVariantToColor(colorVariant: ColorVariant): Color {
@@ -226,18 +227,23 @@ fun performKeyAction(
226227
}
227228

228229
KeyAction.IMECompleteAction -> {
229-
val imeAction = getImeActionCode(ime)
230230
// A lot of apps like discord and slack use weird IME actions,
231231
// so its best to only check the none case
232-
if (imeAction == EditorInfo.IME_FLAG_NO_ENTER_ACTION) {
233-
ime.currentInputConnection.sendKeyEvent(
234-
KeyEvent(
235-
KeyEvent.ACTION_DOWN,
236-
KeyEvent.KEYCODE_ENTER,
237-
),
238-
)
239-
} else {
240-
ime.currentInputConnection.performEditorAction(imeAction)
232+
when (val imeAction = getImeActionCode(ime)) {
233+
IME_ACTION_CUSTOM_LABEL -> {
234+
ime.currentInputConnection.performEditorAction(ime.currentInputEditorInfo.actionId)
235+
}
236+
EditorInfo.IME_ACTION_NONE -> {
237+
ime.currentInputConnection.sendKeyEvent(
238+
KeyEvent(
239+
KeyEvent.ACTION_DOWN,
240+
KeyEvent.KEYCODE_ENTER,
241+
),
242+
)
243+
}
244+
else -> {
245+
ime.currentInputConnection.performEditorAction(imeAction)
246+
}
241247
}
242248
}
243249

@@ -302,13 +308,16 @@ fun performKeyAction(
302308
* Returns the current IME action, or IME_FLAG_NO_ENTER_ACTION if there is none.
303309
*/
304310
fun getImeActionCode(ime: IMEService): Int {
305-
return (
306-
ime.currentInputEditorInfo.imeOptions and (
307-
EditorInfo
308-
.IME_MASK_ACTION or
309-
EditorInfo.IME_FLAG_NO_ENTER_ACTION
310-
)
311-
)
311+
val ei = ime.currentInputEditorInfo
312+
313+
return if ((ei.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
314+
EditorInfo.IME_ACTION_NONE
315+
} else if (ei.actionLabel != null) {
316+
IME_ACTION_CUSTOM_LABEL
317+
} else {
318+
// Note: this is different from editorInfo.actionId, hence "ImeOptionsActionId"
319+
ei.imeOptions and EditorInfo.IME_MASK_ACTION
320+
}
312321
}
313322

314323
/**

0 commit comments

Comments
 (0)