Skip to content

Commit

Permalink
When a key triggers a commit while no candidate is selected, the curs…
Browse files Browse the repository at this point in the history
…or should **always** be corrected leftwards #227

Resolves: #227
  • Loading branch information
mike-fabian committed Aug 22, 2021
1 parent 410d4ce commit 7a6679e
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions engine/hunspell_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def __init__(self, bus, obj_path, database, unit_test=False) -> None:
self._update_preedit_ime_menu_dicts()
self._init_properties()

self._keys_which_select_with_shift = (
keys_which_select_with_shift = (
IBus.KEY_Right, IBus.KEY_KP_Right,
IBus.KEY_Left, IBus.KEY_KP_Left,
IBus.KEY_End, IBus.KEY_KP_End,
Expand All @@ -647,7 +647,7 @@ def __init__(self, bus, obj_path, database, unit_test=False) -> None:
IBus.KEY_Up, IBus.KEY_KP_Up,
IBus.KEY_Page_Down, IBus.KEY_KP_Page_Down, IBus.KEY_KP_Next,
IBus.KEY_Page_Up, IBus.KEY_KP_Page_Up, IBus.KEY_KP_Prior)
self._commit_trigger_keys = self._keys_which_select_with_shift + (
self._commit_trigger_keys = keys_which_select_with_shift + (
IBus.KEY_space, IBus.KEY_Tab,
IBus.KEY_Return, IBus.KEY_KP_Enter,
IBus.KEY_Delete, IBus.KEY_KP_Delete,
Expand Down Expand Up @@ -5898,28 +5898,8 @@ def _process_key_event(self, key: itb_util.KeyEvent) -> bool:
self._commit_string(commit_string, input_phrase=input_phrase)
if not candidate_was_selected:
# cursor needs to be corrected leftwards:
if key.shift and key.val in self._keys_which_select_with_shift:
for dummy_char in commit_string[caret_was:]:
self._forward_generated_key_event(IBus.KEY_Left)
elif (key.val in (IBus.KEY_Left, IBus.KEY_KP_Left,
IBus.KEY_BackSpace)):
# After committing, the cursor is at the right
# side of the committed string. When the string
# has been committed because arrow-left or
# control-arrow-left or backspace reached the left
# side of the preëdit, the cursor has to be moved
# to the left side of the string. We can do it by
# forwarding as many arrow-left events to the
# application as the committed string has
# characters.
#
# Note that when a candidate is selected, the cursor
# is the selected candidated is committed and the then
# it is correct that the cursor is at the right side
# of the committed candidate, so no left key events
# are necessary in that case.
for dummy_char in commit_string:
self._forward_generated_key_event(IBus.KEY_Left)
for dummy_char in commit_string[caret_was:]:
self._forward_generated_key_event(IBus.KEY_Left)
# Forward the key event which triggered the commit here
# and return True instead of trying to pass that key event
# to the application by returning False.
Expand Down

0 comments on commit 7a6679e

Please sign in to comment.