OpenBangla-Keyboard
OpenBangla-Keyboard copied to clipboard
Preedit still reappears when the cursor is moved with the mouse in the *same* window
Recently I reported
https://github.com/OpenBangla/OpenBangla-Keyboard/issues/298
and suggested a fix which is now contained in OpenBangla 3.0.0.
I tested the fix and it works partly, i.e. it does the correct thing when moving the focus to a different window.
When moving the cursor in the same window with the mouse, the preedit is committed (Good!)/
But the following problems remain:
- the candidate list does not close
- the text reappears when typing at the new position, the newly typed text is added to the old preedit
See this video:
https://user-images.githubusercontent.com/2330175/179356471-fd72ac63-955a-4167-a2c3-72553c364512.mp4
ibus-typing-booster does not have this problem, see this video:
https://user-images.githubusercontent.com/2330175/179356824-e4591cfd-90ad-4189-9eb3-5ac95ad91c59.mp4
The reason why this works in ibus-typing-booster is this function do_reset():
https://github.com/mike-fabian/ibus-typing-booster/blob/main/engine/hunspell_table.py#L6256
def do_reset(self) -> None:
'''Called when the mouse pointer is used to move to cursor to a
different position in the current window.
Also called when certain keys are pressed:
Return, KP_Enter, ISO_Enter, Up, Down, (and others?)
Even some key sequences like space + Left and space + Right
seem to call this.
'''
if DEBUG_LEVEL > 1:
LOGGER.debug('do_reset()\n')
if self._prev_key is not None and self._prev_key.val in (
IBus.KEY_Return, IBus.KEY_KP_Enter, IBus.KEY_ISO_Enter):
# The “Return” and “KP_Enter” keys trigger a call to
# do_reset(). But I don’t want to clear the context, in
# that case. Usually this just means that one continues to
# write in the next line and the context is still valid.
# This helps if the context is only remembered and not
# from surrounding text.
#
# However, if surrounding text is used to get the context,
# this usually does not help because at least in Gtk
# surrounding text seems to fetch only the current line.
# That means that after typing Return in a Gtk application
# (like Gedit for example), the context determined from
# surrounding text is empty because the surrounding text
# contains nothing from the previous line.
return
# The preëdit, if there was any, has already been committed
# automatically because
# update_preedit_text_with_mode(,,,IBus.PreeditFocusMode.COMMIT)
# has been used. But the contents of the preëdit have not
# been recorded in the user database yet. Do it now:
if not self.is_empty():
self._record_in_database_and_push_context()
self.clear_context()
self._clear_input_and_update_ui()
I use this function do_reset to clear the context and the input and update the ui (which closes the lookup table because now there is no input). And if new input comes, it is not added to the old input anymore.
OpenBangla has an engine_reset function:
https://github.com/OpenBangla/OpenBangla-Keyboard/blob/develop/src/engine/ibus/main.cpp#L82
void engine_reset() {
ibus_lookup_table_clear(table);
ibus_engine_hide_preedit_text(engine);
ibus_engine_hide_auxiliary_text(engine);
ibus_engine_hide_lookup_table(engine);
}
which does similar stuff, but it is not connected to a callback.
In create_engine_cb()
https://github.com/OpenBangla/OpenBangla-Keyboard/blob/develop/src/engine/ibus/main.cpp#L310
only these signals are connected:
g_signal_connect(engine, "process-key-event", G_CALLBACK(engine_process_key_event_cb), NULL);
g_signal_connect(engine, "enable", G_CALLBACK(engine_enable_cb), NULL);
g_signal_connect(engine, "disable", G_CALLBACK(engine_disable_cb), NULL);
g_signal_connect(engine, "focus-out", G_CALLBACK(engine_focus_out_cb), NULL);
g_signal_connect(engine, "candidate-clicked", G_CALLBACK(engine_candidate_clicked_cb), NULL);
engine_focus_out_cb()
https://github.com/OpenBangla/OpenBangla-Keyboard/blob/develop/src/engine/ibus/main.cpp#L295
finishes the input session and calls reset:
void engine_focus_out_cb(IBusEngine *engine) {
LOG_DEBUG("[IM:iBus]: IM Focus out\n");
if(riti_context_ongoing_input_session(ctx)) {
riti_context_finish_input_session(ctx);
engine_reset();
}
}
So I think another connect like
g_signal_connect(engine, "reset", G_CALLBACK(engine_reset_cb), NULL);
is needed.
And
void engine_reset_cb(IBusEngine *engine) {
LOG_DEBUG("[IM:iBus]: IM Reset\n");
if(riti_context_ongoing_input_session(ctx)) {
riti_context_finish_input_session(ctx);
engine_reset();
}
}
I have no time to make a patch and test this right now, so I just quickly wrote what I think the problem is.
Thanks for the detailed writeup! I'll try your suggestions and report back here. 😊
Did it work? I think I could try to make a patch soon. Should I make a patch or did you do it already?
Did it work? I think I could try to make a patch soon. Should I make a patch or did you do it already?
I haven't yet implemented the patch, so it'd be a great contribution! :wink:
I made a pull request:
https://github.com/OpenBangla/OpenBangla-Keyboard/pull/313
According to my testing, it seems to work.
Thanks again! :heart:
Closing this issue as the PR fixing this has been already merged into the develop branch.