From a64bbd0d4bbe4d072a20342e91c40c3b1dec884d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 22 Apr 2022 15:55:39 +0800 Subject: [PATCH] - enhancement: add project templates for tcp server / tcp client - enhancement: only show function tips when cursor is after ',' or '('. - enhancement: when auto complete function names, only append '(' if before identifier or "/' --- NEWS.md | 4 ++++ RedPandaIDE/editor.cpp | 22 ++++++++++++++++------ RedPandaIDE/qsynedit/SynEdit.cpp | 24 +++++++++++++++++++++++- RedPandaIDE/qsynedit/SynEdit.h | 3 ++- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2e90b75f..3ec7b242 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,10 @@ Red Panda C++ Version 1.0.5 - enhancement: add project template for libmysqlclient(libmariadbclient) - enhancement: add libmysqlclient to the x86-64 version gcc in distribution - enhancement: select and delete multiple watches + - enhancement: add project templates for tcp server / tcp client + - enhancement: only show function tips when cursor is after ',' or '('. + - enhancement: when auto complete function names, only append '(' if before identifier or "/' + - update highconstrast icon set Red Panda C++ Version 1.0.4 - fix: hide function tips, when move or resize the main window diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index dfcde216..759abd10 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -809,8 +809,9 @@ void Editor::keyPressEvent(QKeyEvent *event) handled = handleSymbolCompletion(ch); return; case '(': { - QChar nextCh = nextNotspaceChar(caretY()-1,caretX()-1); - if (!isIdentChar(nextCh) && nextCh!='(' ){ + QChar nextCh = nextNonSpaceChar(caretY()-1,caretX()-1); + if (!isIdentChar(nextCh) && nextCh!='(' + && nextCh!='"' && nextCh!='\'' ){ handled = handleSymbolCompletion(ch); } return; @@ -3080,10 +3081,14 @@ void Editor::completionInsert(bool appendFunc) || (statement->kind == StatementKind::skPreprocessor && !statement->args.isEmpty())) { - if ((p.Char >= lineText().length()) // it's the last char on line - || (lineText().at(p.Char-1) != '(')) { // it don't have '(' after it - if (statement->fullName!="std::endl") - funcAddOn = "()"; + QChar nextCh = nextNonSpaceChar(caretY()-1,p.Char-1); + if (nextCh=='(') { + funcAddOn = ""; + } else if (isIdentChar(nextCh) || nextCh == '"' + || nextCh == '\'') { + funcAddOn = '('; + } else { + funcAddOn = "()"; } } } @@ -3476,6 +3481,11 @@ void Editor::updateFunctionTip(bool showTip) int currentParamPos = 1; if (currentLine>=document()->count()) return; + QChar ch=lastNonSpaceChar(currentLine,currentChar); + qDebug()<=0) { QString line = document()->getString(currentLine); if (currentLine!=caretPos.Line-1) diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 0aa05cbf..c42d395e 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -1093,7 +1093,7 @@ QChar SynEdit::charAt(const BufferCoord &pos) return QChar(0); } -QChar SynEdit::nextNotspaceChar(int line, int ch) +QChar SynEdit::nextNonSpaceChar(int line, int ch) { if (ch<0) return QChar(); @@ -1110,6 +1110,28 @@ QChar SynEdit::nextNotspaceChar(int line, int ch) return QChar(); } +QChar SynEdit::lastNonSpaceChar(int line, int ch) +{ + if (line>=mDocument->count()) + return QChar(); + QString s = mDocument->getString(line); + int x = std::min(ch-1,s.length()-1); + while (line>=0) { + while (x>=0) { + QChar c = s[x]; + if (!c.isSpace()) + return c; + x--; + } + line--; + if (line>=0) { + s = mDocument->getString(line); + x = s.length()-1; + } + } + return QChar(); +} + void SynEdit::setCaretAndSelection(const BufferCoord &ptCaret, const BufferCoord &ptBefore, const BufferCoord &ptAfter) { SynSelectionMode vOldMode = mActiveSelectionMode; diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index b633a5a9..135e437d 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -215,7 +215,8 @@ public: QString wordAtRowCol(const BufferCoord& XY); QChar charAt(const BufferCoord& pos); - QChar nextNotspaceChar(int line, int ch); + QChar nextNonSpaceChar(int line, int ch); + QChar lastNonSpaceChar(int line, int ch); int charColumns(QChar ch) const; bool isPointInSelection(const BufferCoord& Value) const;