Remove the tabcompletion space at end of text
authorBas Pape <baspape@gmail.com>
Thu, 24 Sep 2015 18:11:48 +0000 (20:11 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Jan 2016 16:34:55 +0000 (17:34 +0100)
The "add space after nick when completing mid-sentence" option
introduced by 84381d6 left the space even if it turned out to be at
the end. Remove it again if the text hasn't changed when sending the
text.

src/uisupport/multilineedit.cpp
src/uisupport/multilineedit.h
src/uisupport/tabcompleter.cpp

index ed0dbb6..7e89f49 100644 (file)
@@ -41,6 +41,7 @@ MultiLineEdit::MultiLineEdit(QWidget *parent)
     _scrollBarsEnabled(true),
     _pasteProtectionEnabled(true),
     _emacsMode(false),
+    _completionSpace(0),
     _lastDocumentHeight(-1)
 {
     document()->setDocumentMargin(0);
@@ -667,8 +668,12 @@ void MultiLineEdit::on_returnPressed()
 }
 
 
-void MultiLineEdit::on_returnPressed(const QString &text)
+void MultiLineEdit::on_returnPressed(QString text)
 {
+    if (_completionSpace && text.endsWith(" ")) {
+        text.chop(1);
+    }
+
     if (!text.isEmpty()) {
         foreach(const QString &line, text.split('\n', QString::SkipEmptyParts)) {
             if (line.isEmpty())
@@ -687,6 +692,8 @@ void MultiLineEdit::on_returnPressed(const QString &text)
 
 void MultiLineEdit::on_textChanged()
 {
+    _completionSpace = qMax(_completionSpace - 1, 0);
+
     QString newText = text();
     newText.replace("\r\n", "\n");
     newText.replace('\r', '\n');
@@ -769,3 +776,12 @@ void MultiLineEdit::showHistoryEntry()
     setTextCursor(cursor);
     updateScrollBars();
 }
+
+
+void MultiLineEdit::addCompletionSpace()
+{
+    // Inserting the space emits textChanged, which should not disable removal
+    _completionSpace = 2;
+    insertPlainText(" ");
+}
+
index 7591a51..c041013 100644 (file)
@@ -76,6 +76,8 @@ public:
     inline qint32 idx() const { return _idx; }
     inline bool emacsMode() const { return _emacsMode; }
 
+    void addCompletionSpace();
+
 public slots:
     void setMode(Mode mode);
     void setMinHeight(int numLines);
@@ -101,7 +103,7 @@ protected:
 
 private slots:
     void on_returnPressed();
-    void on_returnPressed(const QString &text);
+    void on_returnPressed(QString text);
     void on_textChanged();
     void on_documentHeightChanged(qreal height);
 
@@ -124,6 +126,7 @@ private:
     bool _scrollBarsEnabled;
     bool _pasteProtectionEnabled;
     bool _emacsMode;
+    int _completionSpace;
 
     QSize _sizeHint;
     qreal _lastDocumentHeight;
index 130095d..b0e61fd 100644 (file)
@@ -152,7 +152,7 @@ void TabCompleter::complete()
             _lastCompletionLength += _nickSuffix.length();
         }
         else if (s.addSpaceMidSentence()) {
-            _lineEdit->insert(" ");
+            _lineEdit->addCompletionSpace();
             _lastCompletionLength++;
         }