@@ -16,6 +16,7 @@ import helium314.keyboard.keyboard.KeyboardSwitcher
1616import helium314.keyboard.keyboard.MainKeyboardView
1717import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
1818import helium314.keyboard.latin.ShadowFacilitator2.Companion.lastAddedWord
19+ import helium314.keyboard.latin.ShadowFacilitator2.Companion.lastNgramContext
1920import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo
2021import helium314.keyboard.latin.common.Constants
2122import helium314.keyboard.latin.common.LocaleUtils.constructLocale
@@ -84,6 +85,15 @@ class InputLogicTest {
8485 assertEquals(" " , composingText)
8586 }
8687
88+ @Test fun `english space-separated typing keeps composing word` () {
89+ reset()
90+ chainInput(" hello" )
91+ assertEquals(" hello" , composingText)
92+ input(' ' )
93+ assertEquals(" hello " , text)
94+ assertEquals(" " , composingText)
95+ }
96+
8797 @Test fun delete () {
8898 reset()
8999 setText(" hello there " )
@@ -160,6 +170,138 @@ class InputLogicTest {
160170 assertEquals(" ㅛ." , text)
161171 }
162172
173+ @Test fun `space after thai composing word inserts space` () {
174+ reset()
175+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
176+ currentScript = ScriptUtils .SCRIPT_THAI
177+ chainInput(" ภาษาไทย" )
178+ assertEquals(" ไทย" , composingText)
179+ input(' ' )
180+ assertEquals(" ภาษาไทย " , text)
181+ assertEquals(" " , composingText)
182+ }
183+
184+ @Test fun `thai composing word follows word boundaries` () {
185+ reset()
186+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
187+ currentScript = ScriptUtils .SCRIPT_THAI
188+ chainInput(" ภาษาไทยดี" )
189+ assertEquals(" ภาษาไทยดี" , text)
190+ assertEquals(" ดี" , composingText)
191+ assertEquals(" ไทย" , lastAddedWord)
192+ assertEquals(" ภาษา" , lastNgramContext)
193+ }
194+
195+ @Test fun `single thai composing segment remains composing` () {
196+ reset()
197+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
198+ currentScript = ScriptUtils .SCRIPT_THAI
199+ chainInput(" ไทย" )
200+ assertEquals(" ไทย" , text)
201+ assertEquals(" ไทย" , composingText)
202+ }
203+
204+ @Test fun `space after segmented thai composing word inserts one space` () {
205+ reset()
206+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
207+ currentScript = ScriptUtils .SCRIPT_THAI
208+ chainInput(" ภาษาไทยดี" )
209+ input(' ' )
210+ assertEquals(" ภาษาไทยดี " , text)
211+ assertEquals(" " , composingText)
212+ }
213+
214+ @Test fun `immediate text expansion uses full segmented thai word` () {
215+ reset()
216+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
217+ currentScript = ScriptUtils .SCRIPT_THAI
218+ latinIME.prefs().edit().apply {
219+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_ENABLED , true )
220+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_IMMEDIATE , true )
221+ }.commit()
222+ val shortcuts = mapOf (" ภาษาไทย" to helium314.keyboard.latin.utils.TextExpanderUtils .ShortcutEntry (" expanded" , " " ))
223+ helium314.keyboard.latin.utils.TextExpanderUtils .saveShortcuts(latinIME, shortcuts)
224+
225+ typeNoAssert(" ภาษาไทย" )
226+
227+ assertEquals(" expanded" , text)
228+ assertEquals(" " , composingText)
229+ assertEquals(" " , lastAddedWord)
230+ }
231+
232+ @Test fun `immediate text expansion uses prefixed segmented thai word` () {
233+ reset()
234+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
235+ currentScript = ScriptUtils .SCRIPT_THAI
236+ latinIME.prefs().edit().apply {
237+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_ENABLED , true )
238+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_IMMEDIATE , true )
239+ }.commit()
240+ val shortcuts = mapOf (" .ภาษาไทย" to helium314.keyboard.latin.utils.TextExpanderUtils .ShortcutEntry (" expanded" , " ." ))
241+ helium314.keyboard.latin.utils.TextExpanderUtils .saveShortcuts(latinIME, shortcuts)
242+
243+ typeNoAssert(" .ภาษาไทย" )
244+
245+ assertEquals(" expanded" , text)
246+ assertEquals(" " , composingText)
247+ assertEquals(" " , lastAddedWord)
248+ }
249+
250+ @Test fun `prefixed immediate text expansion does not defer thai without prefix` () {
251+ reset()
252+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
253+ currentScript = ScriptUtils .SCRIPT_THAI
254+ latinIME.prefs().edit().apply {
255+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_ENABLED , true )
256+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_IMMEDIATE , true )
257+ }.commit()
258+ val shortcuts = mapOf (" .ภาษาไทย" to helium314.keyboard.latin.utils.TextExpanderUtils .ShortcutEntry (" expanded" , " ." ))
259+ helium314.keyboard.latin.utils.TextExpanderUtils .saveShortcuts(latinIME, shortcuts)
260+
261+ typeNoAssert(" ภาษาไทย" )
262+
263+ assertEquals(" ภาษาไทย" , text)
264+ assertEquals(" ไทย" , composingText)
265+ assertEquals(" ภาษา" , lastAddedWord)
266+ }
267+
268+ @Test fun `immediate text expansion still segments thai non-shortcut` () {
269+ reset()
270+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
271+ currentScript = ScriptUtils .SCRIPT_THAI
272+ latinIME.prefs().edit().apply {
273+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_ENABLED , true )
274+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_IMMEDIATE , true )
275+ }.commit()
276+ val shortcuts = mapOf (" อื่น" to helium314.keyboard.latin.utils.TextExpanderUtils .ShortcutEntry (" expanded" , " " ))
277+ helium314.keyboard.latin.utils.TextExpanderUtils .saveShortcuts(latinIME, shortcuts)
278+
279+ chainInput(" ภาษาไทยดี" )
280+
281+ assertEquals(" ภาษาไทยดี" , text)
282+ assertEquals(" ดี" , composingText)
283+ assertEquals(" ไทย" , lastAddedWord)
284+ }
285+
286+ @Test fun `failed immediate expansion commits thai segments separately` () {
287+ reset()
288+ latinIME.switchToSubtype(SubtypeSettings .getResourceSubtypesForLocale(" th" .constructLocale()).first())
289+ currentScript = ScriptUtils .SCRIPT_THAI
290+ latinIME.prefs().edit().apply {
291+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_ENABLED , true )
292+ putBoolean(helium314.keyboard.latin.utils.TextExpanderUtils .PREF_IMMEDIATE , true )
293+ }.commit()
294+ val shortcuts = mapOf (" ภาษาไทยดี" to helium314.keyboard.latin.utils.TextExpanderUtils .ShortcutEntry (" expanded" , " " ))
295+ helium314.keyboard.latin.utils.TextExpanderUtils .saveShortcuts(latinIME, shortcuts)
296+
297+ typeNoAssert(" ภาษาไทยแดง" )
298+
299+ assertEquals(" ภาษาไทยแดง" , text)
300+ assertEquals(" แดง" , composingText)
301+ assertEquals(" ไทย" , lastAddedWord)
302+ assertEquals(" ภาษา" , lastNgramContext)
303+ }
304+
163305 // see issue 1551 (debug only)
164306 @Test fun deleteHangul () {
165307 reset()
@@ -779,6 +921,7 @@ class InputLogicTest {
779921 batchEdit = 0
780922 currentInputType = InputType .TYPE_CLASS_TEXT
781923 lastAddedWord = " "
924+ lastNgramContext = " "
782925
783926 // reset settings
784927 latinIME.prefs().edit { clear() }
@@ -1212,8 +1355,10 @@ class ShadowFacilitator2 {
12121355 ngramContext : NgramContext , timeStampInSeconds : Long ,
12131356 blockPotentiallyOffensive : Boolean ) {
12141357 lastAddedWord = suggestion
1358+ lastNgramContext = ngramContext.extractPrevWordsContext()
12151359 }
12161360 companion object {
12171361 var lastAddedWord = " "
1362+ var lastNgramContext = " "
12181363 }
12191364}
0 commit comments