From 5332ffee84e2c7d8395cc9deb17bf691c8d64daa Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 21 Oct 2023 10:14:12 +0800 Subject: [PATCH] - enhancement: Auto adjust position of the suggestion popup window. --- NEWS.md | 3 ++- RedPandaIDE/editor.cpp | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index fd33be61..58e97808 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ Red Panda C++ Version 2.26 - - enhancment: Code suggestion for embedded std::vectors. + - enhancement: Code suggestion for embedded std::vectors. - change: Use ctrl+mouseMove event to highlight jumpable symbols (instead of ctrl+tooltip). + - enhancement: Auto adjust position of the suggestion popup window. Red Panda C++ Version 2.25 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 7209a45f..ca0fdc86 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include "iconsmanager.h" #include "debugger.h" #include "editorlist.h" @@ -3435,11 +3436,6 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple } } - // Position it at the top of the next line - QPoint p = rowColumnToPixels(displayXY()); - p+=QPoint(0,textHeight()+2); - mCompletionPopup->move(mapToGlobal(p)); - mCompletionPopup->setRecordUsage(pSettings->codeCompletion().recordUsage()); mCompletionPopup->setSortByScope(pSettings->codeCompletion().sortByScope()); mCompletionPopup->setShowKeywords(pSettings->codeCompletion().showKeywords()); @@ -3456,6 +3452,21 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple mCompletionPopup->setIgnoreCase(pSettings->codeCompletion().ignoreCase()); mCompletionPopup->resize(pSettings->codeCompletion().width(), pSettings->codeCompletion().height()); + + // Position it at the top of the next line + QPoint popupPos = mapToGlobal(rowColumnToPixels(displayXY())); + QSize desktopSize = screen()->virtualSize(); + if (desktopSize.height() - popupPos.y() < mCompletionPopup->height() && popupPos.y() > mCompletionPopup->height()) + popupPos-=QPoint(0, mCompletionPopup->height()+2); + else + popupPos+=QPoint(0,textHeight()+2); + + if (desktopSize.width() - popupPos.x() < mCompletionPopup->width() ) { + popupPos.setX(std::max(0, desktopSize.width()-mCompletionPopup->width())-10); + } + + mCompletionPopup->move(popupPos); + // fCompletionBox.CodeInsList := dmMain.CodeInserts.ItemList; // fCompletionBox.SymbolUsage := dmMain.SymbolUsage; // fCompletionBox.ShowCount := devCodeCompletion.MaxCount;