imcontext: Tweak Compose sequence handling
authorMatthias Clasen <mclasen@redhat.com>
Thu, 29 Jul 2021 12:24:14 +0000 (08:24 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 29 Jul 2021 12:24:14 +0000 (08:24 -0400)
When we don't have any matches for a Compose sequence
anymore, beep, and keep the preedit as it was for the
last match.

Fixes: #4127
gtk/gtkimcontextsimple.c

index f193eb48e301037fab274af9bffb4e644969a56d..71f9094aee2f50406a0b4db83dd243143019ce18 100644 (file)
@@ -622,7 +622,7 @@ no_sequence_matches (GtkIMContextSimple *context_simple,
   guint keyval;
 
   context = GTK_IM_CONTEXT (context_simple);
-  
+
   priv->in_compose_sequence = FALSE;
 
   /* No compose sequences found, check first if we have a partial
@@ -1071,6 +1071,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
   else /* Then, check for compose sequences */
     {
       gboolean success = FALSE;
+      int prefix = 0;
       GString *output;
 
       output = g_string_new ("");
@@ -1109,6 +1110,16 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
               success = TRUE;
               break;
             }
+          else
+            {
+              int table_prefix;
+
+              gtk_compose_table_get_prefix ((GtkComposeTable *)tmp_list->data,
+                                            priv->compose_buffer, n_compose,
+                                            &table_prefix);
+
+              prefix = MAX (prefix, table_prefix);
+            }
 
           tmp_list = tmp_list->next;
         }
@@ -1135,6 +1146,21 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
 
           return TRUE;
         }
+
+      /* If we get here, no Compose sequence matched.
+       * Only beep if we were in a sequence before.
+       */
+      if (prefix > 0)
+        {
+          for (i = prefix; i < n_compose; i++)
+            priv->compose_buffer[i] = 0;
+
+          beep_surface (gdk_event_get_surface (event));
+
+          g_signal_emit_by_name (context_simple, "preedit-changed");
+
+          return TRUE;
+        }
     }
 
   /* The current compose_buffer doesn't match anything */