Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{ "$": "keyboard_state_selector", "emojiKeyEnabled": { "$": "keyboard_state_selector", "alphabet": { "label": "emoji" }}},
{ "$": "keyboard_state_selector", "symbols": { "label": "numpad" }},
{ "label": "space" },
{ "$": "keyboard_state_selector", "alphabet": { "label": ";" }},
{ "$": "keyboard_state_selector", "alphabet": { "label": ";", "popup": { "main": { "label": "\\" } } }},
{ "label": "period" },
{ "label": "action", "width": 0.15 }
]
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/helium314/keyboard/event/BnKhiproCombiner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class BnKhiproCombiner : Combiner {

private val composingText = StringBuilder()

// Blinder mode (Khipro spec): after '\' Latin passes through untransliterated until ';'.
// '?' is not a trigger here, since it ends Bengali questions. ';;' types a literal ';'.
private var blinder = false
private var blinderExitPending = false

enum class State {
INIT,
SHOR_STATE,
Expand Down Expand Up @@ -181,6 +186,27 @@ class BnKhiproCombiner : Combiner {

if (event.keyCode == KeyCode.SHIFT) return event

if (blinder) {
if (blinderExitPending) {
blinderExitPending = false
if (codePoint == ';'.code) return event
blinder = false
} else if (codePoint == ';'.code) {
blinderExitPending = true
return Event.createConsumedEvent(event)
} else {
return event
}
}

if (codePoint == '\\'.code) { // the trigger itself is not typed, as in the spec
blinder = true
if (composingText.isEmpty()) return Event.createConsumedEvent(event)
val text = combiningStateFeedback
reset()
return createEventChainFromSequence(text, Event.createConsumedEvent(event))
}

if (isValidCodePoint && Character.isWhitespace(codePoint)) {
return commitAndReset(event)
} else if (event.isFunctionalKeyEvent) {
Expand All @@ -204,6 +230,15 @@ class BnKhiproCombiner : Combiner {

override fun reset() {
composingText.setLength(0)
if (blinderExitPending) {
blinder = false
blinderExitPending = false
}
}

override fun onStartInput() {
blinder = false
blinderExitPending = false
}

private fun commitAndReset(event: Event): Event {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/helium314/keyboard/event/Combiner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ interface Combiner {
* Reset the state of this combiner, for example when the cursor was moved.
*/
fun reset()

/** Called when input starts in a new field, to clear state that outlives [reset]. */
fun onStartInput() {}
}
6 changes: 6 additions & 0 deletions app/src/main/java/helium314/keyboard/event/CombinerChain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class CombinerChain(initialText: String, combiningSpec: String) {
}
}

fun onStartInput() {
for (c in mCombiners) {
c.onStartInput()
}
}

private fun updateStateFeedback() {
mStateFeedback.clear()
for (i in mCombiners.indices.reversed()) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/helium314/keyboard/latin/WordComposer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class WordComposer {
)
mCombiningSpec = nonNullCombiningSpec
}
mCombinerChain.onStartInput()
}

/**
Expand Down
52 changes: 52 additions & 0 deletions app/src/test/java/helium314/keyboard/event/BnKhiproCombinerTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.event

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class BnKhiproCombinerTest {
private val combiner = BnKhiproCombiner()

private fun type(c: Char): Event =
combiner.processEvent(null, Event.createSoftwareKeypressEvent(c.code, 0, 0, 0, 0, false))

@Test fun backslashEntersBlinderAndLatinPassesThrough() {
assertTrue(type('\\').isConsumed) // trigger is not typed
val e = type('k')
assertFalse(e.isConsumed)
assertEquals('k'.code, e.codePoint)
}

@Test fun semicolonLeavesBlinder() {
type('\\')
assertTrue(type(';').isConsumed)
assertTrue(type('k').isConsumed) // composed by Khipro again
}

@Test fun doubleSemicolonTypesLiteralAndStaysInBlinder() {
type('\\')
type(';')
val e = type(';')
assertFalse(e.isConsumed)
assertEquals(';'.code, e.codePoint)
assertFalse(type('k').isConsumed)
}

@Test fun questionMarkDoesNotEnterBlinder() {
combiner.reset()
type('?')
combiner.reset()
assertTrue(type('k').isConsumed)
}

@Test fun newInputFieldLeavesBlinder() {
type('\\')
combiner.onStartInput()
assertTrue(type('k').isConsumed)
}
}
Loading