Skip to content

Commit

Permalink
Do the retransliteration of the input_phrase currently only when the …
Browse files Browse the repository at this point in the history
…cursor is at the end of the typed string

The retransliteration of the input_phrase is done because of
https://bugzilla.redhat.com/show_bug.cgi?id=1353672 because adding a
comit key to the input might influence the transliteration.

Examples:

When using hi-itrans, “. ” translates to “। ”

When using unicode.mim, typing `C-u1f607` shows `U+1F607` in the
preedit, typing a space after that it must be retransliterated to
`😇`.

The way this is currently implemented works only if the cursor is at
the end of the preedit when the character triggering the commit is
typed. Therefore, it should be done only when

   self._typed_string_cursor == len(self._typed_string)

is True.

Maybe it makes sense to do such a retransliteration also when the
cursor is somewhere in the middle of the preedit. Adding a space, Tab,
or Return in the middle of the preedit has its own `elif` in the key
event handling where it might be necessary to do something similar:

            elif (key.val in (IBus.KEY_space, IBus.KEY_Tab,
                              IBus.KEY_Return, IBus.KEY_KP_Enter)
                  and (self._typed_string_cursor
                       < len(self._typed_string))):

So maybe I should change the implementation in that `elif` and
consider the key which triggered the commit in the retransliteration
of input_phrase_left. I am not sure yet whether that would be useful.

And I am not sure either whether anything special should be done when
keys other than space, Tab, or Return trigger a commit while the cursor
is not at the end of the preedit.

So I might improve this a bit in future.

But currently this commit only fixes the error that a
retransliteration of the input_phrase was done by adding the key which
triggered the commit to the end of the input_phrase even when the
cursor was not at the end.

I am not aware of any problems caused by this, it is quite likely that
it does not cause any problems at all.

Nevertheless it clearly looks wrong and it is better to make the
intention clearer in the code.
  • Loading branch information
mike-fabian committed Jul 9, 2024
1 parent 1d07383 commit 7da5c41
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions engine/hunspell_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7105,30 +7105,36 @@ def _process_key_event(self, key: itb_util.KeyEvent) -> bool:
# the input might influence the transliteration. For example
# When using hi-itrans, “. ” translates to “। ”
# (See: https://bugzilla.redhat.com/show_bug.cgi?id=1353672)
input_phrase = self._transliterators[
preedit_ime].transliterate(
self._typed_string + [key.msymbol],
ascii_digits=self._ascii_digits)
input_phrase = self._transliterated_strings[preedit_ime]
input_phrase = self._case_modes[
self._current_case_mode]['function'](input_phrase)
if key.msymbol:
if input_phrase.endswith(key.msymbol):
# If the transliteration now ends with the commit
# key, cut it off because the commit key is passed
# to the application later anyway and we do not
# want to pass it twice:
input_phrase = input_phrase[:-len(key.msymbol)]
else:
# The commit key has been absorbed by the
# transliteration. Add the key to the input
# instead of committing:
if DEBUG_LEVEL > 1:
LOGGER.debug(
'Insert instead of commit: key.msymbol=“%s”',
key.msymbol)
self._insert_string_at_cursor([key.msymbol])
self._update_ui()
return True
if self._typed_string_cursor == len(self._typed_string):
LOGGER.debug('FIXME input_phrase=“%s”', input_phrase)
input_phrase = self._transliterators[
preedit_ime].transliterate(
self._typed_string + [key.msymbol],
ascii_digits=self._ascii_digits)
input_phrase = self._case_modes[
self._current_case_mode]['function'](input_phrase)
LOGGER.debug('FIXME input_phrase=“%s”', input_phrase)
if key.msymbol:
if input_phrase.endswith(key.msymbol):
# If the transliteration now ends with the commit
# key, cut it off because the commit key is passed
# to the application later anyway and we do not
# want to pass it twice:
input_phrase = input_phrase[:-len(key.msymbol)]
else:
# The commit key has been absorbed by the
# transliteration. Add the key to the input
# instead of committing:
if DEBUG_LEVEL > 1:
LOGGER.debug(
'Insert instead of commit: key.msymbol=“%s”',
key.msymbol)
self._insert_string_at_cursor([key.msymbol])
self._update_ui()
return True
if (self.get_lookup_table().get_number_of_candidates()
and self.get_lookup_table().cursor_visible):
# something is selected in the lookup table, commit
Expand Down

0 comments on commit 7da5c41

Please sign in to comment.