From 934641f45cf54e20c7a75d7ab4c44a66d3965d85 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 12 Jun 2020 13:41:00 +0200 Subject: [PATCH] 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 --- src/libs/utils/changeset.h | 5 +++ src/plugins/cppeditor/cppquickfix_test.cpp | 34 +++++++++++++++++++ src/plugins/texteditor/refactoringchanges.cpp | 6 +++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/changeset.h b/src/libs/utils/changeset.h index 5cb484c9b67..31e9540f0ba 100644 --- a/src/libs/utils/changeset.h +++ b/src/libs/utils/changeset.h @@ -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 diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 85ca917e954..cf66662e09c 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -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) diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index cc8166e0fe0..0ee7410b41a 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -31,8 +31,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -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);