From e7a65dd3c9531d72386b9c68d4c09155ef78fe07 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 6 Jan 2021 15:53:10 +0100 Subject: [PATCH] QmlJSEditor: Ensure extra selections are ordered The code model may provide selections that are not ordered as they appear inside the document due to the declarative nature of QML. Ordering before using them avoids couple of warnings stating "overlay selections not in order". Change-Id: Ie912e94aa01ffde52b01dca7a9bde24ae02e8b33 Reviewed-by: Fawzi Mohamed --- src/plugins/qmljseditor/qmljseditor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index c591ecfe2c7..25049089aab 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -70,6 +70,7 @@ #include #include +#include #include #include #include @@ -373,8 +374,13 @@ void QmlJSEditorWidget::updateUses() return; QList selections; - foreach (const SourceLocation &loc, - m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor())) { + QList locations + = m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor()); + // code model may present the locations not in a document order + Utils::sort(locations, [](const SourceLocation &lhs, const SourceLocation &rhs) { + return lhs.begin() < rhs.begin(); + }); + for (const SourceLocation &loc : qAsConst(locations)) { if (! loc.isValid()) continue;