Skip to content

Commit 702e9be

Browse files
committed
Reverting delete key hacks.
- Context #1178
1 parent 6bc5d9a commit 702e9be

File tree

1 file changed

+4
-44
lines changed
  • app/src/main/java/com/dessalines/thumbkey/utils

1 file changed

+4
-44
lines changed

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

+4-44
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import com.dessalines.thumbkey.db.LayoutsUpdate
4545
import kotlinx.coroutines.CoroutineScope
4646
import kotlinx.coroutines.delay
4747
import kotlinx.coroutines.launch
48-
import java.text.BreakIterator
4948
import java.text.NumberFormat
5049
import kotlin.math.PI
5150
import kotlin.math.abs
@@ -362,20 +361,11 @@ fun performKeyAction(
362361
ime.currentInputConnection.sendKeyEvent(ev)
363362
}
364363

364+
// Some apps are having problems with delete key events, and issues need to be opened up
365+
// on their repos.
365366
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)
379369
}
380370

381371
is KeyAction.DeleteWordBeforeCursor -> {
@@ -1375,33 +1365,3 @@ fun updateLayouts(
13751365
),
13761366
)
13771367
}
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

Comments
 (0)