Maintain the right cursor when undoing "clean whitespace" after saving

Previously it would always jump to the start of the document, since
that's where the newly created text cursor is at the beginEditBlock
call. Avoid this when saving the current editor by starting with the
cursor of the editor.

Reviewed-by: mae
Task-number: QTCREATORBUG-1807
This commit is contained in:
Thorbjørn Lindeijer
2010-07-07 13:17:58 +02:00
parent 60bf641041
commit 72b78c22de

View File

@@ -162,7 +162,16 @@ bool BaseTextDocument::save(const QString &fileName)
{ {
QTextCursor cursor(m_document); QTextCursor cursor(m_document);
// When saving the current editor, make sure to maintain the cursor position for undo
Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor();
if (BaseTextEditorEditable *editable = qobject_cast<BaseTextEditorEditable*>(currentEditor)) {
if (editable->file() == this)
cursor = editable->editor()->textCursor();
}
cursor.beginEditBlock(); cursor.beginEditBlock();
cursor.movePosition(QTextCursor::Start);
if (m_storageSettings.m_cleanWhitespace) if (m_storageSettings.m_cleanWhitespace)
cleanWhitespace(cursor, m_storageSettings.m_cleanIndentation, m_storageSettings.m_inEntireDocument); cleanWhitespace(cursor, m_storageSettings.m_cleanIndentation, m_storageSettings.m_inEntireDocument);
if (m_storageSettings.m_addFinalNewLine) if (m_storageSettings.m_addFinalNewLine)