diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index f5d4195ce..16b46d493 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -176,7 +176,8 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) mEncryptWithChiasmus( false ), mComposer( 0 ), mLabelWidth( 0 ), - mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 ) + mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 ), + mPreserveUserCursorPosition( false ) { mClassicalRecipients = GlobalSettings::self()->recipientsEditorType() == GlobalSettings::EnumRecipientsEditorType::Classic; @@ -1973,6 +1974,12 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign, // QTimer::singleShot( 200, this, SLOT(slotAppendSignature()) ); } + + if ( mMsg->getCursorPos() > 0 ) { + // The message has a cursor position explicitly set, so avoid + // changing it when appending the signature. + mPreserveUserCursorPosition = true; + } setModified( isModified ); // do this even for new messages @@ -4049,7 +4056,14 @@ void KMComposeWin::slotAppendSignature() mEditor->append(mOldSigText); mEditor->setModified(mod); // mEditor->setContentsPos( 0, 0 ); - mEditor->setCursorPositionFromStart( (unsigned int) mMsg->getCursorPos() ); + if ( mPreserveUserCursorPosition ) { + mEditor->setCursorPositionFromStart( (unsigned int) mMsg->getCursorPos() ); + // Only keep the cursor from the mMsg *once* based on the + // preserve-cursor-position setting; this handles the case where + // the message comes from a template with a specific cursor + // position set and the signature is appended automatically. + mPreserveUserCursorPosition = false; + } mEditor->sync(); } } diff --git a/kmcomposewin.h b/kmcomposewin.h index 5f06f02d6..a40809b47 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -838,6 +838,15 @@ private: QPopupMenu *mActNowMenu; QPopupMenu *mActLaterMenu; + + /** If the message in this composer has a cursor position set (for + * instance because it comes from a template containing %CURSOR) + * then we need to preserve that cursor position even when auto- + * appending (or prepending) the signature during composer setup. + * Set to true *once* (and only in setMsg() at that) to avoid + * accidentally moving the cursor. + */ + bool mPreserveUserCursorPosition; }; #endif