Skip to content

Commit

Permalink
Don't handle ctrl+g in non-converting state (Issue#35).
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Jun 17, 2011
1 parent 6f0b126 commit 994ae4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions engine/skk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,14 +1297,18 @@ def __activate_candidate_selector(self, midasi, okuri=False):
self.__current_state().conv_state = CONV_STATE_START
self.__enter_dict_edit()

def __rom_kana_key_is_acceptable(self, key):
def __rom_kana_has_pending(self):
if self.__current_state().rom_kana_state is None:
return False
output, pending, tree = self.__current_state().rom_kana_state
return len(pending) > 0

def __rom_kana_key_is_acceptable(self, key):
if key.is_nicola():
return False
output, pending, tree = self.__current_state().rom_kana_state
if len(pending) == 0:
if not self.__rom_kana_has_pending():
return False
output, pending, tree = self.__current_state().rom_kana_state
if key.letter.lower() not in tree:
return False
arg = tree[key.letter.lower()]
Expand All @@ -1327,11 +1331,18 @@ def press_key(self, keystr):
and OUTPUT is a committable string (if any).'''
key = Key(keystr)
if str(key) == 'ctrl+g':
handled = True
if self.dict_edit_level() > 0 and \
self.__current_state().conv_state == CONV_STATE_NONE:
self.__abort_dict_edit()
elif self.__current_state().conv_state in (CONV_STATE_NONE,
CONV_STATE_START):
# Don't handle ctrl+g here if no rom-kana conversion
# is in progress. This allows Firefox search shortcut
# ctrl+g (Issue#35).
if self.__current_state().conv_state == CONV_STATE_NONE and \
not self.__rom_kana_has_pending():
handled = False
input_mode = self.__current_state().input_mode
self.reset()
self.activate_input_mode(input_mode)
Expand All @@ -1347,7 +1358,7 @@ def press_key(self, keystr):
self.__current_state().midasi = None
self.__candidate_selector.set_candidates(list())
self.__current_state().conv_state = CONV_STATE_START
return (True, u'')
return (handled, u'')

if str(key) in ('ctrl+h', 'backspace'):
return self.delete_char()
Expand Down
10 changes: 10 additions & 0 deletions engine/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ def testromkana(self):
self.__skk.activate_input_mode(skk.INPUT_MODE_HIRAGANA)
self.__skk.press_key(u'z')
self.assertEqual(self.__skk.press_key(u'l'), (True, u'→'))
# cancel rom-kana conversion
self.__skk.reset()
self.__skk.activate_input_mode(skk.INPUT_MODE_HIRAGANA)
self.__skk.press_key(u'm')
self.__skk.press_key(u'y')
self.assertEqual(self.__skk.press_key(u'ctrl+g'), (True, u''))
self.__skk.press_key(u'm')
self.__skk.press_key(u'y')
self.__skk.press_key(u'a')
self.assertEqual(self.__skk.press_key(u'ctrl+g'), (False, u''))

def testhiraganakatakana(self):
self.__skk.reset()
Expand Down

0 comments on commit 994ae4a

Please sign in to comment.