X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=37f1f62ac1d1c473827ba23f5fe5ccc48619cbef;hb=bd0b31b38c8111206ce630dbeac7a6c19bdb8a6e;hp=48ffdbacdb15b18fb079e8a0cc2ecb5799c01634;hpb=399cac566c86141228358a7e7e14b2375fdc3259;p=quassel.git diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 48ffdbac..37f1f62a 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); @@ -54,6 +55,9 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) setLineWrapEnabled(false); reset(); + // Prevent QTextHtmlImporter::appendNodeText from eating whitespace + document()->setDefaultStyleSheet("span { white-space: pre-wrap; }"); + connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged())); _mircColorMap["00"] = "#ffffff"; @@ -551,22 +555,18 @@ QString MultiLineEdit::convertRichtextToMircCodes() cursor.clearSelection(); } - if (color) { - color = false; + + if (color) mircText.append('\x03'); - } - if (underline) { - underline = false; + + if (underline) mircText.append('\x1f'); - } - if (italic) { - italic = false; + + if (italic) mircText.append('\x1d'); - } - if (bold) { - bold = false; + + if (bold) mircText.append('\x02'); - } return mircText; } @@ -671,8 +671,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()) @@ -691,6 +695,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'); @@ -773,3 +779,12 @@ void MultiLineEdit::showHistoryEntry() setTextCursor(cursor); updateScrollBars(); } + + +void MultiLineEdit::addCompletionSpace() +{ + // Inserting the space emits textChanged, which should not disable removal + _completionSpace = 2; + insertPlainText(" "); +} +