Skip to content

Commit 4a36c64

Browse files
committed
fix crash reported in openboard-team#459 and improve formatting
1 parent 4d071e2 commit 4a36c64

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

app/src/main/java/org/dslul/openboard/inputmethod/event/DeadKeyCombiner.kt

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ class DeadKeyCombiner : Combiner {
5959
}
6060

6161
// Caution! This may only contain chars, not supplementary code points. It's unlikely
62-
// it will ever need to, but if it does we'll have to change this
62+
// it will ever need to, but if it does we'll have to change this
6363
private val sNonstandardDeadCombinations = SparseIntArray()
6464

65-
private fun addNonStandardDeadCombination(deadCodePoint: Int,
66-
spacingCodePoint: Int, result: Int) {
65+
private fun addNonStandardDeadCombination(deadCodePoint: Int, spacingCodePoint: Int, result: Int) {
6766
val combination = deadCodePoint shl 16 or spacingCodePoint
6867
sNonstandardDeadCombinations.put(combination, result)
6968
}
@@ -105,14 +104,14 @@ class DeadKeyCombiner : Combiner {
105104
// U+030D: COMBINING VERTICAL LINE ABOVE
106105
addCombining('\u030D'.code, ACCENT_VERTICAL_LINE_ABOVE)
107106
// U+030E: COMBINING DOUBLE VERTICAL LINE ABOVE
108-
//addCombining('\u030E', ACCENT_DOUBLE_VERTICAL_LINE_ABOVE);
109-
// U+030F: COMBINING DOUBLE GRAVE ACCENT
110-
//addCombining('\u030F', ACCENT_DOUBLE_GRAVE);
111-
// U+0310: COMBINING CANDRABINDU
112-
//addCombining('\u0310', ACCENT_CANDRABINDU);
113-
// U+0311: COMBINING INVERTED BREVE
114-
//addCombining('\u0311', ACCENT_INVERTED_BREVE);
115-
// U+0312: COMBINING TURNED COMMA ABOVE
107+
//addCombining('\u030E', ACCENT_DOUBLE_VERTICAL_LINE_ABOVE);
108+
// U+030F: COMBINING DOUBLE GRAVE ACCENT
109+
//addCombining('\u030F', ACCENT_DOUBLE_GRAVE);
110+
// U+0310: COMBINING CANDRABINDU
111+
//addCombining('\u0310', ACCENT_CANDRABINDU);
112+
// U+0311: COMBINING INVERTED BREVE
113+
//addCombining('\u0311', ACCENT_INVERTED_BREVE);
114+
// U+0312: COMBINING TURNED COMMA ABOVE
116115
addCombining('\u0312'.code, ACCENT_TURNED_COMMA_ABOVE)
117116
// U+0313: COMBINING COMMA ABOVE
118117
addCombining('\u0313'.code, ACCENT_COMMA_ABOVE)
@@ -125,8 +124,8 @@ class DeadKeyCombiner : Combiner {
125124
// U+0323: COMBINING DOT BELOW
126125
addCombining('\u0323'.code, ACCENT_DOT_BELOW)
127126
// U+0326: COMBINING COMMA BELOW
128-
//addCombining('\u0326', ACCENT_COMMA_BELOW);
129-
// U+0327: COMBINING CEDILLA
127+
//addCombining('\u0326', ACCENT_COMMA_BELOW);
128+
// U+0327: COMBINING CEDILLA
130129
addCombining('\u0327'.code, ACCENT_CEDILLA)
131130
// U+0328: COMBINING OGONEK
132131
addCombining('\u0328'.code, ACCENT_OGONEK)
@@ -137,20 +136,20 @@ class DeadKeyCombiner : Combiner {
137136
// U+0335: COMBINING SHORT STROKE OVERLAY
138137
addCombining('\u0335'.code, ACCENT_STROKE)
139138
// U+0342: COMBINING GREEK PERISPOMENI
140-
//addCombining('\u0342', ACCENT_PERISPOMENI);
141-
// U+0344: COMBINING GREEK DIALYTIKA TONOS
142-
//addCombining('\u0344', ACCENT_DIALYTIKA_TONOS);
143-
// U+0345: COMBINING GREEK YPOGEGRAMMENI
144-
//addCombining('\u0345', ACCENT_YPOGEGRAMMENI);
145-
// One-way mappings to equivalent preferred accents.
146-
// U+0340: COMBINING GRAVE TONE MARK
139+
//addCombining('\u0342', ACCENT_PERISPOMENI);
140+
// U+0344: COMBINING GREEK DIALYTIKA TONOS
141+
//addCombining('\u0344', ACCENT_DIALYTIKA_TONOS);
142+
// U+0345: COMBINING GREEK YPOGEGRAMMENI
143+
//addCombining('\u0345', ACCENT_YPOGEGRAMMENI);
144+
// One-way mappings to equivalent preferred accents.
145+
// U+0340: COMBINING GRAVE TONE MARK
147146
sCombiningToAccent.append('\u0340'.code, ACCENT_GRAVE)
148147
// U+0341: COMBINING ACUTE TONE MARK
149148
sCombiningToAccent.append('\u0341'.code, ACCENT_ACUTE)
150149
// U+0343: COMBINING GREEK KORONIS
151150
sCombiningToAccent.append('\u0343'.code, ACCENT_COMMA_ABOVE)
152151
// One-way legacy mappings to preserve compatibility with older applications.
153-
// U+0300: COMBINING GRAVE ACCENT
152+
// U+0300: COMBINING GRAVE ACCENT
154153
sAccentToCombining.append(ACCENT_GRAVE_LEGACY, '\u0300'.code)
155154
// U+0302: COMBINING CIRCUMFLEX ACCENT
156155
sAccentToCombining.append(ACCENT_CIRCUMFLEX_LEGACY, '\u0302'.code)
@@ -159,8 +158,8 @@ class DeadKeyCombiner : Combiner {
159158
}
160159

161160
init { // Non-standard decompositions.
162-
// Stroke modifier for Finnish multilingual keyboard and others.
163-
// U+0110: LATIN CAPITAL LETTER D WITH STROKE
161+
// Stroke modifier for Finnish multilingual keyboard and others.
162+
// U+0110: LATIN CAPITAL LETTER D WITH STROKE
164163
addNonStandardDeadCombination(ACCENT_STROKE, 'D'.code, '\u0110'.code)
165164
// U+01E4: LATIN CAPITAL LETTER G WITH STROKE
166165
addNonStandardDeadCombination(ACCENT_STROKE, 'G'.code, '\u01e4'.code)
@@ -258,14 +257,14 @@ class DeadKeyCombiner : Combiner {
258257
if (index <= 0) {
259258
return originalEvent
260259
}
261-
lateinit var lastEvent: Event
260+
var lastEvent: Event? = null
262261
do {
263262
val codePoint = Character.codePointBefore(text, index)
264-
lastEvent = Event.createHardwareKeypressEvent(codePoint,
265-
originalEvent.mKeyCode, lastEvent, false /* isKeyRepeat */)
263+
lastEvent = Event.createHardwareKeypressEvent(codePoint, originalEvent.mKeyCode, lastEvent, false)
266264
index -= Character.charCount(codePoint)
267265
} while (index > 0)
268-
return lastEvent
266+
// can't be null because
267+
return lastEvent!!
269268
}
270269
}
271270
}

0 commit comments

Comments
 (0)