Fix handling of invalid trailing input
Fix handling of invalid trailing input

- Improve documentation of _table_mode_process_key_event()

- If invalid input characters came after some valid input characters,
  the old code committed the valid input and then the invalid
  character only if the key code of the invalid input was <= 127.
  Consider for example, for the cns11643 table, the valid input is
  “0123456789abcdef”.  The Chinese character “一” has the table
  key “14421” in cns11643, it is the first character in that table
  with a key starting with “1442”.

  Both “A” and “☺” are invalid input for the cns11643 table. But
  as “A” has a key code <= 127, it would be committed after
  committing pending input whereas “☺” which has a key code > 127
  would be passed through to the application.
  Therefore, typing “1442A” would commit “一A” but
  typing “1442☺” would pass “☹” to the application and keep
  “1442” in preedit, so the user sees “☺1442”.

  This makes no sense at all, instead of checking for <= 127, *all*
  typed keys where “IBus.keyval_to_unicode(key.code)”
  returns a result should be treated the same way here. Then
  typing “1442☺” commits “一☺”.

- The added lines:

      if type(keychar) != type(u''):
          keychar = keychar.decode('UTF-8')

  are only for Python2 compatibility, they do nothing for Python3.
  (Maybe I should give up trying to keep Python2 compatibility?)

mike-fabian/ibus-table,kaio/ibus-table,mike-fabian/ibus-table,kaio/ibus-table