forked from qt-creator/qt-creator
TextEditor: Sort indent ranges before applying
It can easily happen that callers insert indent ranges out of order, and without sorting the indentation done earlier in the file is not considered for the later parts, leading to inconsistent results. Fixes: QTCREATORBUG-18929 Change-Id: Ice2abe92d54446bcdd102c6a1f822262a8533543 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -121,4 +121,9 @@ private:
|
||||
bool m_error;
|
||||
};
|
||||
|
||||
inline bool operator<(const ChangeSet::Range &r1, const ChangeSet::Range &r2)
|
||||
{
|
||||
return r1.start < r2.start;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -1582,6 +1582,40 @@ void CppEditorPlugin::test_quickfix_data()
|
||||
"};\n"
|
||||
);
|
||||
|
||||
QTest::newRow("InsertQtPropertyMembersPrivateBeforePublic")
|
||||
<< CppQuickFixFactoryPtr(new InsertQtPropertyMembers)
|
||||
<< _("class XmarksTheSpot {\n"
|
||||
"private:\n"
|
||||
" @Q_PROPERTY(int it READ getIt WRITE setIt NOTIFY itChanged)\n"
|
||||
"public:\n"
|
||||
" void find();\n"
|
||||
"};\n"
|
||||
)
|
||||
<< _("class XmarksTheSpot {\n"
|
||||
"private:\n"
|
||||
" Q_PROPERTY(int it READ getIt WRITE setIt NOTIFY itChanged)\n"
|
||||
" int m_it;\n"
|
||||
"\n"
|
||||
"public:\n"
|
||||
" void find();\n"
|
||||
" int getIt() const\n"
|
||||
" {\n"
|
||||
" return m_it;\n"
|
||||
" }\n"
|
||||
"public slots:\n"
|
||||
" void setIt(int it)\n"
|
||||
" {\n"
|
||||
" if (m_it == it)\n"
|
||||
" return;\n"
|
||||
"\n"
|
||||
" m_it = it;\n"
|
||||
" emit itChanged(m_it);\n"
|
||||
" }\n"
|
||||
"signals:\n"
|
||||
" void itChanged(int it);\n"
|
||||
"};\n"
|
||||
);
|
||||
|
||||
// Escape String Literal as UTF-8 (no-trigger)
|
||||
QTest::newRow("EscapeStringLiteral_notrigger")
|
||||
<< CppQuickFixFactoryPtr(new EscapeStringLiteral)
|
||||
|
@@ -31,8 +31,9 @@
|
||||
#include <coreplugin/dialogs/readonlyfilesdialog.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@@ -343,6 +344,9 @@ bool RefactoringFile::apply()
|
||||
else
|
||||
c.beginEditBlock();
|
||||
|
||||
sort(m_indentRanges);
|
||||
sort(m_reindentRanges);
|
||||
|
||||
// build indent selections now, applying the changeset will change locations
|
||||
const RefactoringSelections &indentSelections =
|
||||
RefactoringChanges::rangesToSelections(doc, m_indentRanges);
|
||||
|
Reference in New Issue
Block a user