- fix: code suggestion popup window don't highlight current item

- fix:  the order of symbols in local and system headers in the suggestion popopup is wrong
This commit is contained in:
royqh1979@gmail.com 2021-08-29 10:29:56 +08:00
parent 7207994d57
commit 2ae8521bca
5 changed files with 38 additions and 9 deletions

View File

@ -99,8 +99,10 @@ Editor::Editor(QWidget *parent, const QString& filename,
} else {
initParser();
}
mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
// mCompletionPopup = std::make_shared<CodeCompletionPopup>();
// mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
mCompletionPopup = pMainWindow->completionPopup();
mHeaderCompletionPopup = pMainWindow->headerCompletionPopup();
applySettings();
applyColorScheme(pSettings->editor().colorScheme());

View File

@ -122,6 +122,9 @@ MainWindow::MainWindow(QWidget *parent)
//class browser
ui->classBrowser->setModel(&mClassBrowserModel);
mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
updateAppTitle();
}
@ -941,7 +944,17 @@ void MainWindow::prepareDebugger()
// Reset watch vars
// mDebugger->deleteWatchVars(false);
// mDebugger->deleteWatchVars(false);
}
const std::shared_ptr<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const
{
return mHeaderCompletionPopup;
}
const std::shared_ptr<CodeCompletionPopup> &MainWindow::completionPopup() const
{
return mCompletionPopup;
}
SearchDialog *MainWindow::searchDialog() const

View File

@ -5,6 +5,8 @@
#include "common.h"
#include "widgets/searchresultview.h"
#include "widgets/classbrowser.h"
#include "widgets/codecompletionpopup.h"
#include "widgets/headercompletionpopup.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -91,6 +93,10 @@ public:
const std::shared_ptr<CodeCompletionPopup> &completionPopup() const;
const std::shared_ptr<HeaderCompletionPopup> &headerCompletionPopup() const;
protected:
void openFiles(const QStringList& files);
void openFile(const QString& filename);
@ -232,6 +238,9 @@ private:
bool mQuitting;
QElapsedTimer mParserTimer;
std::shared_ptr<CodeCompletionPopup> mCompletionPopup;
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;
SearchResultModel mSearchResultModel;
PSearchResultListModel mSearchResultListModel;
PSearchResultTreeModel mSearchResultTreeModel;
@ -244,6 +253,7 @@ private:
int mPreviousHeight;
PCompileSuccessionTask mCompileSuccessionTask;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;

View File

@ -105,6 +105,7 @@ bool CodeCompletionPopup::search(const QString &phrase, bool autoHideOnSingleRes
setCursor(oldCursor);
if (!mCompletionStatementList.isEmpty()) {
mListView->setCurrentIndex(mModel->index(0,0));
// if only one suggestion, and is exactly the symbol to search, hide the frame (the search is over)
// if only one suggestion and auto hide , don't show the frame
if(mCompletionStatementList.count() == 1)
@ -223,9 +224,9 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
} else if (statement2->kind == StatementKind::skKeyword) {
return false;
// Show stuff from local headers first
} else if (statement1->inSystemHeader && !(statement2->inSystemHeader)) {
return true;
} else if (!(statement1->inSystemHeader) && statement2->inSystemHeader) {
return true;
} else if (statement1->inSystemHeader && !(statement2->inSystemHeader)) {
return false;
// Show local statements first
} else if (statement1->scope != StatementScope::ssGlobal
@ -254,11 +255,11 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2)
} else if (statement1->freqTop < statement2->freqTop) {
return false;
// show keywords first
} else if ((statement1->kind == StatementKind::skKeyword)
&& (statement2->kind != StatementKind::skKeyword)) {
return true;
} else if ((statement1->kind != StatementKind::skKeyword)
&& (statement2->kind == StatementKind::skKeyword)) {
return true;
} else if ((statement1->kind == StatementKind::skKeyword)
&& (statement2->kind != StatementKind::skKeyword)) {
return false;
} else
return statement1->command < statement2->command;

View File

@ -64,6 +64,7 @@ bool HeaderCompletionPopup::search(const QString &phrase, bool autoHideOnSingleR
setCursor(oldCursor);
if (!mCompletionList.isEmpty()) {
mListView->setCurrentIndex(mModel->index(0,0));
if (mCompletionList.count() == 1) {
// if only one suggestion and auto hide , don't show the frame
if (autoHideOnSingleResult)
@ -95,7 +96,9 @@ QString HeaderCompletionPopup::selectedFilename()
int index = mListView->currentIndex().row();
if (index>=0 && index<mCompletionList.count())
return mCompletionList[index];
else
else if (mCompletionList.count()>0) {
return mCompletionList.front();
}
return "";
}