@@ -45,7 +45,6 @@ import com.dessalines.thumbkey.db.LayoutsUpdate
45
45
import kotlinx.coroutines.CoroutineScope
46
46
import kotlinx.coroutines.delay
47
47
import kotlinx.coroutines.launch
48
- import java.text.BreakIterator
49
48
import java.text.NumberFormat
50
49
import kotlin.math.PI
51
50
import kotlin.math.abs
@@ -362,20 +361,11 @@ fun performKeyAction(
362
361
ime.currentInputConnection.sendKeyEvent(ev)
363
362
}
364
363
364
+ // Some apps are having problems with delete key events, and issues need to be opened up
365
+ // on their repos.
365
366
is KeyAction .DeleteKeyAction -> {
366
- if (ime.currentInputConnection.getSelectedText(0 )?.isEmpty() != false ) {
367
- val textBeforeCursor = ime.currentInputConnection.getTextBeforeCursor(20 , 0 )?.toString()
368
- if (textBeforeCursor.isNullOrEmpty()) {
369
- return
370
- }
371
-
372
- val lastClusterBoundary = findLastGraphemeClusterBoundary(textBeforeCursor)
373
- if (lastClusterBoundary != - 1 ) {
374
- ime.currentInputConnection.deleteSurroundingText(textBeforeCursor.length - lastClusterBoundary, 0 )
375
- }
376
- } else {
377
- ime.currentInputConnection.commitText(" " , 0 )
378
- }
367
+ val ev = KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_DEL )
368
+ ime.currentInputConnection.sendKeyEvent(ev)
379
369
}
380
370
381
371
is KeyAction .DeleteWordBeforeCursor -> {
@@ -1375,33 +1365,3 @@ fun updateLayouts(
1375
1365
),
1376
1366
)
1377
1367
}
1378
-
1379
- fun findLastGraphemeClusterBoundary (text : String ): Int {
1380
- val boundary = BreakIterator .getCharacterInstance()
1381
- boundary.setText(text)
1382
-
1383
- val end = text.length
1384
- var lastBoundary = boundary.preceding(end) // Find the previous grapheme boundary
1385
-
1386
- // Check if this boundary is part of a ZWJ sequence
1387
- while (lastBoundary > 0 && isPartOfZWJSequence(text, lastBoundary)) {
1388
- lastBoundary = boundary.preceding(lastBoundary)
1389
- }
1390
-
1391
- return lastBoundary
1392
- }
1393
-
1394
- fun isPartOfZWJSequence (
1395
- text : String ,
1396
- index : Int ,
1397
- ): Boolean {
1398
- if (index <= 0 || index >= text.length) return false
1399
-
1400
- // Check if the character before this boundary is a ZWJ
1401
- val previousChar = text[index - 1 ]
1402
- if (previousChar.code == 0x200D ) { // Zero-Width Joiner
1403
- return true
1404
- }
1405
-
1406
- return false
1407
- }
0 commit comments