src/gui/widgets/qlinecontrol.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
--- a/src/gui/widgets/qlinecontrol.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/widgets/qlinecontrol.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -138,7 +138,12 @@
 */
 void QLineControl::paste()
 {
-    insert(QApplication::clipboard()->text(QClipboard::Clipboard));
+    QString clip = QApplication::clipboard()->text(QClipboard::Clipboard);
+    if (!clip.isEmpty() || hasSelectedText()) {
+        separate(); //make it a separate undo/redo command
+        insert(clip);
+        separate();
+    }
 }
 
 #endif // !QT_NO_CLIPBOARD
@@ -401,7 +406,8 @@
 void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
 {
     int priorState = 0;
-    bool isGettingInput = !event->commitString().isEmpty() || !event->preeditString().isEmpty()
+    bool isGettingInput = !event->commitString().isEmpty()
+            || event->preeditString() != preeditAreaText()
             || event->replacementLength() > 0;
     bool cursorPositionChanged = false;
 
@@ -413,7 +419,7 @@
 
 
     int c = m_cursor; // cursor position after insertion of commit string
-    if (event->replacementStart() <= 0)
+    if (event->replacementStart() == 0)
         c += event->commitString().length() + qMin(-event->replacementStart(), event->replacementLength());
 
     m_cursor += event->replacementStart();
@@ -447,8 +453,9 @@
             cursorPositionChanged = true;
         }
     }
-
+#ifndef QT_NO_IM
     setPreeditArea(m_cursor, event->preeditString());
+#endif //QT_NO_IM
     m_preeditCursor = event->preeditString().length();
     m_hideCursor = false;
     QList<QTextLayout::FormatRange> formats;
@@ -1509,6 +1516,18 @@
     }
 #endif // QT_NO_COMPLETER
 
+    if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
+        if (hasAcceptableInput() || fixup()) {
+            emit accepted();
+            emit editingFinished();
+        }
+        if (inlineCompletionAccepted)
+            event->accept();
+        else
+            event->ignore();
+        return;
+    }
+
     if (echoMode() == QLineEdit::PasswordEchoOnEdit
         && !passwordEchoEditing()
         && !isReadOnly()
@@ -1529,17 +1548,6 @@
         clear();
     }
 
-    if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
-        if (hasAcceptableInput() || fixup()) {
-            emit accepted();
-            emit editingFinished();
-        }
-        if (inlineCompletionAccepted)
-            event->accept();
-        else
-            event->ignore();
-        return;
-    }
     bool unknown = false;
 
     if (false) {
@@ -1578,16 +1586,16 @@
         }
     }
 #endif //QT_NO_CLIPBOARD
-    else if (event == QKeySequence::MoveToStartOfLine) {
+    else if (event == QKeySequence::MoveToStartOfLine || event == QKeySequence::MoveToStartOfBlock) {
         home(0);
     }
-    else if (event == QKeySequence::MoveToEndOfLine) {
+    else if (event == QKeySequence::MoveToEndOfLine || event == QKeySequence::MoveToEndOfBlock) {
         end(0);
     }
-    else if (event == QKeySequence::SelectStartOfLine) {
+    else if (event == QKeySequence::SelectStartOfLine || event == QKeySequence::SelectStartOfBlock) {
         home(1);
     }
-    else if (event == QKeySequence::SelectEndOfLine) {
+    else if (event == QKeySequence::SelectEndOfLine || event == QKeySequence::SelectEndOfBlock) {
         end(1);
     }
     else if (event == QKeySequence::MoveToNextChar) {
@@ -1663,6 +1671,7 @@
     }
 #endif // QT_NO_SHORTCUT
     else {
+        bool handled = false;
 #ifdef Q_WS_MAC
         if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
             Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier);
@@ -1680,6 +1689,7 @@
                     event->key() == Qt::Key_Up ? home(0) : end(0);
                 }
             }
+            handled = true;
         }
 #endif
         if (event->modifiers() & Qt::ControlModifier) {
@@ -1712,7 +1722,8 @@
             break;
 #endif
             default:
-                unknown = true;
+                if (!handled)
+                    unknown = true;
             }
         } else { // ### check for *no* modifier
             switch (event->key()) {
@@ -1745,7 +1756,8 @@
 #endif
 
             default:
-                unknown = true;
+                if (!handled)
+                    unknown = true;
             }
         }
     }