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 <fawzi.mohamed@qt.io>
This commit is contained in:
Christian Stenger
2021-01-06 15:53:10 +01:00
parent b82d51ad69
commit e7a65dd3c9

View File

@@ -70,6 +70,7 @@
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/textmark.h>
#include <utils/algorithm.h>
#include <utils/delegates.h>
#include <utils/changeset.h>
#include <utils/qtcassert.h>
@@ -373,8 +374,13 @@ void QmlJSEditorWidget::updateUses()
return;
QList<QTextEdit::ExtraSelection> selections;
foreach (const SourceLocation &loc,
m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor())) {
QList<SourceLocation> 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;