Commit a111ec23 authored by Mathieu Bridon's avatar Mathieu Bridon

cangjie: Properly handle star as first character

In Cangjie, the asterisk (*) can only be used as a wildcard if it is
**surrounded** by text, that is, it needs **at least** one character
before and one character after.

As such, if the first thing the user types is an asterisk, we shouldn't
consider it as a wildcard, but as a plain character to type directly.

This commit introduces two new unit tests which make sure we will not
regress on this feature.
parent 8343ce83
......@@ -378,9 +378,12 @@ class EngineCangjie(Engine):
def do_star(self):
"""Handle the star key (*)
For Cangjie, this can be a wildcard key.
For Cangjie, this can in some cases be a wildcard key.
"""
return self.do_inputchar("*")
if self.current_input:
return self.do_inputchar("*")
return self.do_other_key(IBus.asterisk)
class EngineQuick(Engine):
......
......@@ -110,6 +110,24 @@ class CangjieTestCase(unittest.TestCase):
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertTrue(self.engine.lookuptable.get_number_of_candidates() > 1)
def test_wildcard_first(self):
self.engine.do_process_key_event(IBus.asterisk, 0, 0)
self.assertEqual(len(self.engine._mock_auxiliary_text), 0)
self.assertEqual(len(self.engine._mock_committed_text), 1)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
def test_wildcard_last(self):
self.engine.do_process_key_event(IBus.d, 0, 0)
self.engine.do_process_key_event(IBus.asterisk, 0, 0)
self.engine.do_process_key_event(IBus.space, 0, 0)
self.assertEqual(len(self.engine._mock_auxiliary_text), 2)
self.assertEqual(len(self.engine._mock_committed_text), 0)
self.assertEqual(self.engine.lookuptable.get_number_of_candidates(), 0)
self.assertEqual(len(self.engine.canberra._mock_played_events), 1)
def test_backspace(self):
self.engine.do_process_key_event(IBus.a, 0, 0)
self.engine.do_process_key_event(IBus.BackSpace, 0, 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment