Commit 5d6ca433 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

back out whitespace cleanups after autosave

otherwise the editing flow is disturbed

Change-Id: I1ae74ab192b19ac8ea0b77b803c797afcd29e7c7
Reviewed-on: http://codereview.qt.nokia.com/564

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent b146a917
......@@ -372,11 +372,21 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool
{
QTextCursor cursor(d->m_document);
// When autosaving, we don't want to modify the document/location under the user's fingers.
BaseTextEditorWidget *editorWidget = 0;
int savedPosition, savedAnchor;
int undos = d->m_document->availableUndoSteps();
// When saving the current editor, make sure to maintain the cursor position for undo
Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor();
if (BaseTextEditor *editable = qobject_cast<BaseTextEditor*>(currentEditor)) {
if (editable->file() == this)
cursor.setPosition(editable->editorWidget()->textCursor().position());
if (editable->file() == this) {
editorWidget = editable->editorWidget();
QTextCursor cur = editorWidget->textCursor();
savedPosition = cur.position();
savedAnchor = cur.anchor();
cursor.setPosition(cur.position());
}
}
cursor.beginEditBlock();
......@@ -408,6 +418,17 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool
saver.write(d->m_codec->fromUnicode(plainText));
}
if (autoSave && undos < d->m_document->availableUndoSteps()) {
d->m_document->undo();
if (editorWidget) {
QTextCursor cur = editorWidget->textCursor();
cur.setPosition(savedAnchor);
cur.setPosition(savedPosition, QTextCursor::KeepAnchor);
editorWidget->setTextCursor(cur);
}
}
if (!saver.finalize(errorString))
return false;
d->m_autoSaveRevision = d->m_document->revision();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment