2010-11-24 Kristian Amlie <kristian.amlie@nokia.com>
[WebKit.git] / WebKit / qt / Api / qwebpage.cpp
index e00b4c64d4a5174a415ab9533229d4c6afe9ba3f..94ed62aa78af419924243d8fb128f999f20b9d1a 100644 (file)
@@ -1080,7 +1080,13 @@ void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
         }
     }
 
-    if (!ev->commitString().isEmpty())
+    if (node && ev->replacementLength() > 0) {
+        int cursorPos = frame->selection()->extent().offsetInContainerNode();
+        int start = cursorPos + ev->replacementStart();
+        setSelectionRange(node, start, start + ev->replacementLength());
+        // Commit regardless of whether commitString is empty, to get rid of selection.
+        editor->confirmComposition(ev->commitString());
+    } else if (!ev->commitString().isEmpty())
         editor->confirmComposition(ev->commitString());
     else if (!hasSelection && !ev->preeditString().isEmpty())
         editor->setComposition(ev->preeditString(), underlines, 0, 0);