Reset the input prior to processing it in order to prevent issues with per-chat histo...
[quassel.git] / src / uisupport / multilineedit.cpp
index 871f47a..874dce8 100644 (file)
@@ -40,6 +40,7 @@ MultiLineEdit::MultiLineEdit(QWidget *parent)
     _maxHeight(5),
     _scrollBarsEnabled(true),
     _pasteProtectionEnabled(true),
+    _emacsMode(false),
     _lastDocumentHeight(-1)
 {
 #if QT_VERSION >= 0x040500
@@ -338,12 +339,6 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) {
       case Qt::Key_B:
         moveCursor(QTextCursor::Left);
         return;
-      case Qt::Key_Right:
-        moveCursor(QTextCursor::WordRight);
-        return;
-      case Qt::Key_Left:
-        moveCursor(QTextCursor::WordLeft);
-        return;
 
         // modify
       case Qt::Key_Y:
@@ -353,9 +348,14 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) {
         moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
         cut();
         return;
+
+      default:
+        break;
       }
     }
-    else if(event->modifiers() & Qt::MetaModifier) {
+    else if(event->modifiers() & Qt::MetaModifier ||
+            event->modifiers() & Qt::AltModifier)
+    {
       switch(event->key()) {
       case Qt::Key_Right:
         moveCursor(QTextCursor::WordRight);
@@ -375,6 +375,52 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) {
       case Qt::Key_Greater:
         moveCursor(QTextCursor::End);
         return;
+
+        // modify
+      case Qt::Key_D:
+        moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor);
+        cut();
+        return;
+
+      case Qt::Key_U: // uppercase word
+        moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor);
+        textCursor().insertText(textCursor().selectedText().toUpper());
+        return;
+
+      case Qt::Key_L: // lowercase word
+        moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor);
+        textCursor().insertText(textCursor().selectedText().toLower());
+        return;
+
+      case Qt::Key_C: { // capitalize word
+        moveCursor(QTextCursor::WordRight, QTextCursor::KeepAnchor);
+        QString const text = textCursor().selectedText();
+        textCursor().insertText(text.left(1).toUpper() + text.mid(1).toLower());
+        return;
+      }
+
+      case Qt::Key_T: { // transpose words
+        moveCursor(QTextCursor::StartOfWord);
+        moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+        QString const word1 = textCursor().selectedText();
+        textCursor().clearSelection();
+        moveCursor(QTextCursor::WordRight);
+        moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+        QString const word2 = textCursor().selectedText();
+        if(!word2.isEmpty() && !word1.isEmpty()) {
+          textCursor().insertText(word1);
+          moveCursor(QTextCursor::WordLeft);
+          moveCursor(QTextCursor::WordLeft);
+          moveCursor(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+          textCursor().insertText(word2);
+          moveCursor(QTextCursor::WordRight);
+          moveCursor(QTextCursor::EndOfWord);
+        }
+        return;
+      }
+
+      default:
+        break;
       }
     }
   }
@@ -591,9 +637,11 @@ void MultiLineEdit::on_returnPressed(const QString & text) {
       if(line.isEmpty())
         continue;
       addToHistory(line);
-      emit textEntered(line);
     }
     reset();
+    foreach(const QString &line, text.split('\n', QString::SkipEmptyParts)) {
+      emit textEntered(line);
+    }
     _tempHistory.clear();
   } else {
     emit noTextEntered();