Bugs related to preedit in Qt6 and Chromium

Sun, Feb 18 2024 08:01:39 KST

Let’s look at another problem I recently discovered.

If the input method sends the same preedit string as the previously sent preedit string to the Chromium(94.0.4606.81), there is a bug that Chromium does not display it. This bug also occurs with version 121.0.6167.160.

So I changed nimf-korean to send an empty preedit and then send a new preedit. And it works fine in Chromium.

    if (korean->clear_preedit_before_new_preedit)
    {
      korean->preedit.text[0] = '\0';
      korean->preedit.attrs[0].n_chars = 0;
      korean->preedit.cursor_pos = 0;
      nimf_service_ic_call_preedit_changed (target, &korean->preedit);
    }

    c_char32_to_utf8_buf (&preedit_char32, korean->preedit.text, 1);
    korean->preedit.attrs[0].n_chars = c_utf8_strlen (korean->preedit.text);
    korean->preedit.cursor_pos = korean->preedit.attrs[0].n_chars;
    nimf_service_ic_call_preedit_changed (target, &korean->preedit);

However, a bug occurred where preedit was not displayed properly in Qt6 applications. So I decided to place the option to send an empty preedit and then a new preedit only in the Gtk input module.

static void cb_preedit_changed (NimfIc*           unused1,
                                const CimPreedit* preedit,
                                NimfGic*          gic)
{
  /*
    After sending the empty preedit string to the application,
    send the new preedit string to the application.

    If the input method sends the same preedit string as the previously sent
    preedit string to the Chromium(94.0.4606.81 or later), there is a bug that Chrome
    does not display it.
   */
  if (gic->clear_preedit_before_new_preedit)
  {
    static const CimPreedit empty = { "", 0, 0, 0 };
    gic->preedit = ∅
    g_signal_emit_by_name (gic, "preedit-changed");
  }

  gic->preedit = preedit;
  g_signal_emit_by_name (gic, "preedit-changed");
}

So both Qt6 and Chromium work fine.