  quartz_reset (GtkIMContext *context)
  {
    GTK_NOTE (MISC, g_print ("quartz_reset\n"));
-+  discard_preedit (context, TRUE);
++  discard_preedit (context);
  }
  
  static void
-@@ -242,6 +270,9 @@ quartz_focus_out (GtkIMContext *context)
+@@ -242,6 +273,9 @@ quartz_focus_out (GtkIMContext *context)
  
    GtkIMContextQuartz *qc = GTK_IM_CONTEXT_QUARTZ (context);
    qc->focused = FALSE;
 +
-+  /* Clear any partially built strings or it'll mess up other GTK+ widgets in the window */
-+  discard_preedit (context, FALSE);
++  /* Commit any partially built strings or it'll mess up other GTK+ widgets in the window */
++  discard_preedit (context);
  }
  
  static void

+  if (!nsview)
+    return;
+
+  /* reset any partial input for this NSView */
+  NSInputManager *currentInputManager = [NSInputManager currentInputManager];
+  [currentInputManager markedTextAbandoned:nsview];
+
+  if (qc->preedit_str)
+    {
+      if (commit)
+        g_signal_emit_by_name (context, "commit", qc->preedit_str);
+
+      g_free (qc->preedit_str);
+      qc->preedit_str = NULL;

diff --git a/modules/input/imquartz.c b/modules/input/imquartz.c
index 61ad914..9e42d8f 100644
--- a/modules/input/imquartz.c
+++ b/modules/input/imquartz.c
@@ -211,9 +211,40 @@ quartz_filter_keypress (GtkIMContext *context,
 }
 
 static void
+discard_preedit (GtkIMContext *context)
+{
+  GtkIMContextQuartz *qc = GTK_IM_CONTEXT_QUARTZ (context);
+
