diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index fa590d838..68cb4ccbf 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -3240,17 +3240,9 @@ void KMComposeWin::slotPasteAsQuotation() { if( mEditor->hasFocus() && msg() ) { - QString quotePrefix = quotePrefixName(); QString s = QApplication::clipboard()->text(); - if (!s.isEmpty()) { - for (int i=0; (uint)iinsert(s); - } + if (!s.isEmpty()) + mEditor->insert(addQuotesToText(s)); } } @@ -3284,11 +3276,9 @@ void KMComposeWin::slotAddQuotes() if( mEditor->hasFocus() && msg() ) { if ( mEditor->hasMarkedText()) { - QString s = mEditor->markedText(); - QString quotePrefix = quotePrefixName(); - s.prepend(quotePrefix); - s.replace("\n", "\n"+quotePrefix); - mEditor->insert(s); + QString s = mEditor->markedText(); + if(!s.isEmpty()) + mEditor->insert(addQuotesToText(s)); } else { int l = mEditor->currentLine(); int c = mEditor->currentColumn(); @@ -3301,6 +3291,39 @@ void KMComposeWin::slotAddQuotes() } } +QString KMComposeWin::addQuotesToText(const QString &inputText) +{ + QString answer = QString(quotePrefixName()); + int sentenceLength = 0; + for (unsigned int i=0; (uint)i 0 && inputText[i-1] == ' ') + continue; + sentenceLength = 1; + answer.append('\n'); + if(i < inputText.length()) + answer.append(quotePrefixName()); + continue; + } + else if(sentenceLength > GlobalSettings::lineWrapWidth()) { + unsigned int back = answer.length(); + while(answer[back] != ' ' && back > 0) + back--; + if(back != 0) { + answer.insert(back+1, quotePrefixName()); + answer.insert(back+1, "\n"); + } + sentenceLength = 0; + } + + if ( inputText[i] < ' ' && inputText[i] != '\t' ) + answer.append(' '); + else + answer.append(inputText[i]); + sentenceLength++; + } + return answer; +} void KMComposeWin::slotRemoveQuotes() { diff --git a/kmcomposewin.h b/kmcomposewin.h index 51733c11c..84af1bb48 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -905,6 +905,8 @@ private: bool mSubjectTextWasSpellChecked; + QString addQuotesToText(const QString &inputText); + private slots: void slotCompletionModeChanged( KGlobalSettings::Completion ); void slotConfigChanged();