Skip to content

Commit

Permalink
fix: in ascii_mode and ascii_punct modes, symbols for which mappi…
Browse files Browse the repository at this point in the history
…ng has not been set in the scheme config will cannot be committed
  • Loading branch information
if-can committed Feb 7, 2025
1 parent 39ae3e2 commit ac33e2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
23 changes: 19 additions & 4 deletions app/src/main/java/com/osfans/trime/core/Rime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,26 @@ class Rime :
fun simulateKeySequence(sequence: CharSequence): Boolean {
if (!sequence.first().isAsciiPrintable()) return false
Timber.d("simulateKeySequence: $sequence")
return simulateRimeKeySequence(
sequence.toString().replace("{}", "{braceleft}{braceright}"),
).also {

val simulateResult =
simulateRimeKeySequence(
sequence.toString().replace("{}", "{braceleft}{braceright}"),
)
val commit = getRimeCommit()
val ctx = getRimeContext()

return (simulateResult && (!commit?.text.isNullOrEmpty() || !ctx?.input.isNullOrEmpty())).also {
Timber.d("simulateKeySequence ${if (it) "success" else "failed"}")
if (it) requireResponse()
if (it) {
handleRimeMessage(
4, // RimeMessage.MessageType.Response
arrayOf(
commit ?: RimeProto.Commit(null),
ctx ?: return false,
getRimeStatus() ?: return false,
),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class CommonKeyboardActionListener(
/** Pattern for braced key event like `{Left}`, `{Right}`, etc. */
private val BRACED_KEY_EVENT = """^(\{[^{}]+\}).*$""".toRegex()

/** Pattern for braced key event to capture `{Escape}` as group 2 */
private val BRACED_KEY_EVENT_WITH_ESCAPE = """^((\{Escape\})?[^{}]+).*$""".toRegex()
/** Pattern for unbraced characters (including {Escape}) like `abc`, `{Escape}jk` etc. */
private val UNBRACED_CHAR = """^((\{Escape\})?[^{}]+).*$""".toRegex()

private val PLACEHOLDER_PATTERN = Regex(".*(%([1-4]\\$)?s).*")
}
Expand Down Expand Up @@ -339,20 +339,19 @@ class CommonKeyboardActionListener(
while (sequence.isNotEmpty()) {
val slice =
when {
BRACED_KEY_EVENT_WITH_ESCAPE.matches(sequence) ->
BRACED_KEY_EVENT_WITH_ESCAPE.matchEntire(sequence)?.groupValues?.get(1)
?: ""
UNBRACED_CHAR.matches(sequence) -> UNBRACED_CHAR.matchEntire(sequence)?.groupValues?.get(1) ?: ""
BRACED_KEY_EVENT.matches(sequence) -> BRACED_KEY_EVENT.matchEntire(sequence)?.groupValues?.get(1) ?: ""
else -> sequence.first().toString()
}

service.postRimeJob {
if (slice.startsWith("{") && slice.endsWith("}")) {
onAction(KeyActionManager.getAction(slice))
} else {
if ((!Rime.simulateKeySequence(slice) || Rime.isAsciiMode) && !Rime.isComposing) {
service.commitText(slice.replace("{Escape}", ""))
}
return@postRimeJob
}

if (!Rime.simulateKeySequence(slice)) {
service.commitText(slice.replace("{Escape}", ""))
}
}

Expand Down

0 comments on commit ac33e2c

Please sign in to comment.