Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit ddc1a95398f131b6a6defa903eda21ffad109cdb
Author: anish <apatil(a)redhat.com>
Date: Wed Jul 3 18:12:23 2013 +0530
if you press space key with no preedit string in this case you should not call _update_ui method
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index acb8c3d..61b82ae 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -573,6 +573,8 @@ class tabengine (IBus.Engine):
# editor.get_caret() should also use NFC!
_str = unicodedata.normalize('NFC', self._editor.get_transliterated_string())
_str = self._editor.yokan.get_preedit()
+ print "update preedit"
+ print _str
if _str == u'' or _str == None:
super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
else:
@@ -655,6 +657,7 @@ class tabengine (IBus.Engine):
self._update_aux ()
def commit_string (self, commit_phrase, input_phrase=u''):
+ print "commit_string"
if self._tab_enable:
# After each commit, disable a tab enabled lookup
# table again, i.e. one needs to press tab again
@@ -667,7 +670,7 @@ class tabengine (IBus.Engine):
#commit_phrase = unicodedata.normalize('NFC', commit_phrase)
super(tabengine,self).commit_text(IBus.Text.new_from_string(commit_phrase))
self._editor.clear_input()
- self._update_ui ()
+ #self._update_ui ()
self._commit_happened_after_focus_in = True
if self.client_capabilities & IBus.Capabilite.SURROUNDING_TEXT:
# If a character ending a sentence is committed (possibly
@@ -740,6 +743,8 @@ class tabengine (IBus.Engine):
state = state & (IBus.ModifierType.SHIFT_MASK |IBus.ModifierType.CONTROL_MASK | IBus.ModifierType.MOD1_MASK |IBus.ModifierType.MOD5_MASK | IBus.ModifierType.RELEASE_MASK);
keyevent = libyokan.KeyEvent.from_x_event(keyval,keycode,libyokan.ModifierType(state))
result = self._editor.yokan.process_key_event(keyevent)
+ if result == False:
+ return result
self._update_ui ()
#result = self._process_key_event (key)
return result
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit f117eb4469ab62ce142c00e3b58e9f335c0833d2
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Sat Jul 6 23:41:24 2013 +0200
Commit immediately when certain punctuation characters are typed and transliteration is not used
- Improve committing punctuation immediately when the preëdit is empty
and no transliteration is used: don’t just check ascii punctuation
but check for Unicode categories.
- commit punctuation immediately as well when the preëdit is not empty
anymore and no transliteration is used.
rhbz#981179 - RFE: punctuation marks should commit the preedit buffer
See: https://bugzilla.redhat.com/show_bug.cgi?id=981179
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 47 +++++++++++++++----------
ibus-typing-booster/engine/itb_util.py | 16 +++++++++
2 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index da04927..5f82747 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -746,28 +746,32 @@ class tabengine (IBus.Engine):
# if the first character is a space, just pass it through
# it makes not sense trying to complete:
return False
- if key.code >= 32 and key.code <= 127 and (not (key.mask & (IBus.ModifierType.MOD1_MASK | IBus.ModifierType.CONTROL_MASK))):
- # If the first character typed is punctuation or a digit,
- # we might want to avoid completion and commit something
- # immediately:
- if curses.ascii.ispunct(key.code):
+ if key.code >= 32 and (not (key.mask & (IBus.ModifierType.MOD1_MASK | IBus.ModifierType.CONTROL_MASK))):
+ typed_character = IBus.keyval_to_unicode(key.code).decode('UTF-8')
+ # If the first character typed is a character which is
+ # very unlikely to be part of a word
+ # (e.g. punctuation, a symbol, ..), we might want to
+ # avoid completion and commit something immediately:
+ if typed_character and unicodedata.category(typed_character) in itb_util.categories_to_trigger_immediate_commit:
if not self._editor.trans_m17n_mode:
- # If the first character is punctuation and no
- # transliteration is used, don’t just pass it through.
- # Commit it so it gets added to the remembered context:
- punctuation = IBus.keyval_to_unicode(key.code).decode('UTF-8')
- self.commit_string(punctuation, input_phrase = punctuation)
+ # Do not just pass the character through,
+ # commit it properly. For example if it is a
+ # “.” we might want to remove whitespace
+ # between the “.” and the previous word and this is
+ # done in commit_string().
+ self.commit_string(typed_character, input_phrase = typed_character)
return True
# If transliteration is used, we may need to
- # handle a punctuation character. For example,
- # “.c” is transliterated to “ċ” in the
- # “t-latn-pre” transliteration method, therefore
- # we cannot just pass it through. Just add it to
- # the input so far and see what comes next:
- self._editor.insert_string_at_cursor(IBus.keyval_to_unicode(key.code).decode('UTF-8'))
+ # handle a punctuation or symbol character. For
+ # example, “.c” is transliterated to “ċ” in
+ # the “t-latn-pre” transliteration method,
+ # therefore we cannot just pass it through. Just
+ # add it to the input so far and see what comes
+ # next:
+ self._editor.insert_string_at_cursor(typed_character)
self._update_ui()
return True
- if curses.ascii.isdigit(key.code):
+ if typed_character and unicodedata.digit(typed_character, -1) != -1:
if not self._editor.trans_m17n_mode:
# If a digit has been typed and no transliteration
# is used, we can pass it through
@@ -778,7 +782,7 @@ class tabengine (IBus.Engine):
# want “3” to be converted to “३”. So we try
# to transliterate and commit the result:
transliterated_digit = self._editor.trans.transliterate(
- IBus.keyval_to_unicode(key.code))[0].decode('utf8')
+ typed_character)[0].decode('utf8')
self.commit_string(transliterated_digit, input_phrase=transliterated_digit)
return True
@@ -944,7 +948,12 @@ class tabengine (IBus.Engine):
# first key typed, we will try to complete something now
# get the context if possible
self.get_context()
- self._editor.insert_string_at_cursor(IBus.keyval_to_unicode(key.code).decode('UTF-8'))
+ typed_character = IBus.keyval_to_unicode(key.code).decode('UTF-8')
+ self._editor.insert_string_at_cursor(typed_character)
+ if typed_character and unicodedata.category(typed_character) in itb_util.categories_to_trigger_immediate_commit:
+ input_phrase = self._editor.get_transliterated_string()
+ if input_phrase and input_phrase[-1] == typed_character and not self._editor.trans_m17n_mode:
+ self.commit_string(input_phrase + u' ', input_phrase = input_phrase)
self._update_ui()
return True
diff --git a/ibus-typing-booster/engine/itb_util.py b/ibus-typing-booster/engine/itb_util.py
index 9ea842a..d017fd3 100755
--- a/ibus-typing-booster/engine/itb_util.py
+++ b/ibus-typing-booster/engine/itb_util.py
@@ -19,6 +19,22 @@
import re
import unicodedata
+# If a character of one of these categories is typed and no
+# transliteration is used, the preëdit can be committed immediately.
+# However, if transliteration is used, we may need to handle a
+# punctuation or symbol character. For example, “.c” is
+# transliterated to “ċ” in the “t-latn-pre” transliteration
+# method, therefore we cannot just pass it through, we have to add
+# it to the input and see what comes next.
+#
+# This list is very similar to the list of categories to strip from
+# tokens. But I removed the 'Pd' (Punctuation, Dash) category because
+# of words like “up-to-date”. Triggering a commit at the first “-”
+# prevents learning such words from user input. I.e. the list of
+# categories to trigger immediate commit should contain only categories
+# which are very unlikely to appear as parts of words.
+categories_to_trigger_immediate_commit = ['Po', 'Pi', 'Pf', 'Ps', 'Pe', 'Pc', 'Sm', 'Sc', 'Cf']
+
categories_to_strip_from_tokens = ['Po', 'Pi', 'Pf', 'Ps', 'Pe', 'Pc', 'Pd', 'Sm', 'Sc', 'Cf']
def lstrip_token(token):