diff --git a/modules/input/imwayland.c b/modules/input/imwayland.c
index 12d18a0f64..b91534838a 100644
--- a/modules/input/imwayland.c
+++ b/modules/input/imwayland.c
@@ -58,6 +58,7 @@ struct preedit {
   gchar *text;
   gint cursor_begin;
   gint cursor_end;
+  guint mode;
 };
 
 struct surrounding_delete {
@@ -121,6 +122,15 @@ static const GtkIMContextInfo *info_list[] =
 #define MODULE_ENTRY(type, function) type _gtk_immodule_wayland_ ## function
 #endif
 
+static void
+notify_surrounding_text (GtkIMContextWayland *context);
+static void
+commit_state (GtkIMContextWayland *context);
+static void
+clear_preedit_text (GtkIMContextWayland *context);
+static void
+gtk_im_context_wayland_reset (GtkIMContext *context);
+
 static void
 notify_external_change (GtkIMContextWayland *context)
 {
@@ -157,6 +167,22 @@ text_input_preedit (void                     *data,
   context->pending_preedit.cursor_end = cursor_end;
 }
 
+static void
+text_input_preedit_commit_mode (void                     *data,
+                                struct zwp_text_input_v3 *text_input,
+                                guint                     mode)
+{
+  GtkIMContextWayland *context;
+  GtkIMContextWaylandGlobal *global = data;
+
+  if (!global->current)
+    return;
+
+  context = GTK_IM_CONTEXT_WAYLAND (global->current);
+
+  context->pending_preedit.mode = mode;
+}
+
 static void
 text_input_preedit_apply (GtkIMContextWaylandGlobal *global)
 {
@@ -270,6 +296,37 @@ text_input_done (void                     *data,
   text_input_preedit_apply(global);
 }
 
+static void
+clear_preedit_text (GtkIMContextWayland *context)
+{
+  gchar *preedit_string = NULL;
+
+  if (!global || !global->text_input)
+    return;
+  if (global->current != GTK_IM_CONTEXT (context))
+    return;
+
+  if (context->current_preedit.text &&
+      context->current_preedit.mode == ZWP_TEXT_INPUT_V3_COMMIT_MODE_COMMIT)
+    {
+      preedit_string = g_strdup (context->current_preedit.text);
+    }
+
+  text_input_preedit (global, global->text_input, NULL, 0, 0);
+  text_input_preedit_commit_mode (global, global->text_input, ZWP_TEXT_INPUT_V3_COMMIT_MODE_CLEAR);
+  text_input_preedit_apply (global);
+
+  if (preedit_string)
+    {
+      text_input_commit (global, global->text_input, preedit_string);
+      text_input_preedit_commit_mode (global, global->text_input, ZWP_TEXT_INPUT_V3_COMMIT_MODE_CLEAR);
+      text_input_commit_apply (global, TRUE);
+      g_free (preedit_string);
+      notify_surrounding_text (context);
+      commit_state (context);
+    }
+}
+
 static void
 notify_surrounding_text (GtkIMContextWayland *context)
 {
@@ -539,6 +596,16 @@ gtk_im_context_wayland_filter_keypress (GtkIMContext *context,
   return GTK_IM_CONTEXT_CLASS (parent_class)->filter_keypress (context, key);
 }
 
+static void
+notify_reset (GtkIMContextWayland *context_wayland)
+{
+  if (global->current !=  GTK_IM_CONTEXT (context_wayland))
+    return;
+
+  zwp_text_input_v3_disable (global->text_input);
+  zwp_text_input_v3_enable (global->text_input);
+}
+
 static void
 enable (GtkIMContextWayland *context_wayland)
 {
@@ -565,11 +632,11 @@ disable (GtkIMContextWayland *context_wayland)
   if (context_wayland->current_preedit.text)
     {
       text_input_preedit (global, global->text_input, NULL, 0, 0);
+      text_input_preedit_commit_mode (global, global->text_input, ZWP_TEXT_INPUT_V3_COMMIT_MODE_CLEAR);
       text_input_preedit_apply (global);
     }
 }
 
-
 static void
 pressed_cb (GtkGestureMultiPress *gesture,
             gint                  n_press,
@@ -581,6 +648,13 @@ pressed_cb (GtkGestureMultiPress *gesture,
     {
       context->press_x = x;
       context->press_y = y;
+
+      /* clear the preedit text before the client commit. */
+      if (global->current == GTK_IM_CONTEXT (context))
+        {
+          clear_preedit_text (context);
+          gtk_im_context_wayland_reset (GTK_IM_CONTEXT (context));
+        }
     }
 }
 
@@ -667,7 +741,12 @@ text_input_leave (void                     *data,
   global->focused = FALSE;
 
   if (global->current)
-    disable (GTK_IM_CONTEXT_WAYLAND (global->current));
+    {
+      GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (global->current);
+
+      clear_preedit_text (context_wayland);
+      disable (context_wayland);
+    }
 }
 
 
@@ -678,6 +757,7 @@ static const struct zwp_text_input_v3_listener text_input_listener = {
   text_input_commit,
   text_input_delete_surrounding_text,
   text_input_done,
+  text_input_preedit_commit_mode,
 };
 
 static void
@@ -763,7 +843,10 @@ gtk_im_context_wayland_focus_out (GtkIMContext *context)
     return;
 
   if (global->focused)
-    disable (context_wayland);
+    {
+      clear_preedit_text (context_wayland);
+      disable (context_wayland);
+    }
 
   global->current = NULL;
 }
@@ -771,6 +854,13 @@ gtk_im_context_wayland_focus_out (GtkIMContext *context)
 static void
 gtk_im_context_wayland_reset (GtkIMContext *context)
 {
+  GtkIMContextWayland *context_wayland;
+
+  context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
+
+  notify_reset (context_wayland);
+  commit_state (context_wayland);
+
   notify_external_change (GTK_IM_CONTEXT_WAYLAND (context));
 
   GTK_IM_CONTEXT_CLASS (parent_class)->reset (context);
diff --git a/modules/input/text-input-unstable-v3.xml b/modules/input/text-input-unstable-v3.xml
index 8b710fd68b..978bd0eea9 100644
--- a/modules/input/text-input-unstable-v3.xml
+++ b/modules/input/text-input-unstable-v3.xml
@@ -417,6 +417,26 @@
       </description>
       <arg name="serial" type="uint"/>
     </event>
+
+    <enum name="commit_mode">
+      <description summary="focus commit mode">
+        Pre-edit commit mode when the focus is lost.
+      </description>
+      <entry name="clear" value="0" summary="pre-edit text is cleared."/>
+      <entry name="commit" value="1" summary="pre-edit text is committed."/>
+    </enum>
+
+    <event name="preedit_commit_mode">
+      <description summary="pre-edit commit mode">
+        Specify how the visible preedit should be handled
+        when mouse click happens, whether commit the preedit text or
+        clear the preedit text.
+
+        The parameter mode is the commit mode to specify the behavior
+        on focus out when the pre-edit buffer is visible.
+      </description>
+      <arg name="mode" type="uint" enum="commit_mode"/>
+    </event>
   </interface>
 
   <interface name="zwp_text_input_manager_v3" version="1">
