Commit 267167a0 authored by Marco Benelli's avatar Marco Benelli

qmljs: do not reset undo/redo history in reformatting

Task-number: QTCREATORBUG-18645
Change-Id: I5b64fa5e59af3d871d3124d668bfd1f86883e752
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent ba54fa8a
......@@ -259,19 +259,29 @@ void QmlJSEditorPlugin::reformatFile()
if (!document->isParsedCorrectly())
return;
TextEditor::TabSettings tabSettings = m_currentDocument->tabSettings();
const QString &newText = QmlJS::reformat(document,
tabSettings.m_indentSize,
tabSettings.m_tabSize);
// QTextDocument::setPlainText cannot be used, as it would reset undo/redo history
const auto setNewText = [this, &newText]() {
QTextCursor tc(m_currentDocument->document());
tc.movePosition(QTextCursor::Start);
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
tc.insertText(newText);
};
QmlJSEditorWidget *widget = EditorManager::currentEditor()
? qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget())
: nullptr;
if (widget) {
const int position = widget->position();
m_currentDocument->document()->setPlainText(newText);
setNewText();
widget->setCursorPosition(position);
} else {
m_currentDocument->document()->setPlainText(newText);
setNewText();
}
}
}
......
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