From 5b699f2b46b460b7ac9b3ac3f55a14f9b9734cb4 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 18 Jan 2022 13:08:53 +0800 Subject: [PATCH] - change: symbols that exactly match are sorted to the front in the code suggestion popup list --- NEWS.md | 1 + RedPandaIDE/widgets/codecompletionpopup.cpp | 25 ++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3bde5d5a..d58b8c1d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ Red Panda C++ Version 0.13.3 - enhancement: restore editor position after reformat code - fix: If project's compiler set is not the same with the default compiler set, parser for the project doesn't use the project's compiler set - fix: If project's compiler set is not the same with the default compiler set, auto openned project's file will use wrong compiler set to do syntax check. + - change: symbols that exactly match are sorted to the front in the code suggestion popup list Red Panda C++ Version 0.13.2 - fix: "delete and exit" button in the environtment / folder option page doesn't work correctly diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 835e7995..ad4f26ab 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -211,15 +211,15 @@ void CodeCompletionPopup::addStatement(PStatement statement, const QString &file } static bool nameComparator(PStatement statement1,PStatement statement2) { + return statement1->command < statement2->command; +} + +static bool defaultComparator(PStatement statement1,PStatement statement2) { if (statement1->caseMatch && !statement2->caseMatch) { return true; } else if (!statement1->caseMatch && statement2->caseMatch) { return false; - } else - return statement1->command < statement2->command; -} - -static bool defaultComparator(PStatement statement1,PStatement statement2) { + } // Show user template first if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement2->kind != StatementKind::skUserCodeSnippet) @@ -240,6 +240,11 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) { } static bool sortByScopeComparator(PStatement statement1,PStatement statement2){ + if (statement1->caseMatch && !statement2->caseMatch) { + return true; + } else if (!statement1->caseMatch && statement2->caseMatch) { + return false; + } // Show user template first if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement2->kind != StatementKind::skUserCodeSnippet) @@ -273,6 +278,11 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){ } static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) { + if (statement1->caseMatch && !statement2->caseMatch) { + return true; + } else if (!statement1->caseMatch && statement2->caseMatch) { + return false; + } // Show user template first if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement2->kind != StatementKind::skUserCodeSnippet) @@ -298,6 +308,11 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) } static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement statement2){ + if (statement1->caseMatch && !statement2->caseMatch) { + return true; + } else if (!statement1->caseMatch && statement2->caseMatch) { + return false; + } // Show user template first if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement2->kind != StatementKind::skUserCodeSnippet)