X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fuisupport%2Fmultilineedit.cpp;h=7e89f499ae35cc0d322271e8aa0bc932f6f5a1c1;hb=169266ea6b484f8876679854998cdd6dac6b9e90;hp=ed0dbb60cc75840287c01c7cfdee72d5cc84c2dc;hpb=695758015a80eb8c158a9ac4c0f1c0b547e70df3;p=quassel.git diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index ed0dbb60..7e89f499 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -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(" "); +} +