From 2943226e46005ebab36adfd06cc9dfcadb3d0b3d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 14 Jul 2023 22:01:58 +0800 Subject: [PATCH] - fix: Code completion doesn't work if "min id length to show completion" is not 1. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index b8ee1e1e..88920267 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Red Panda C++ Version 2.24 - fix: members of elements of stl maps are not correctly suggested. - fix: memory view's cell size is too wide in linux. + - fix: Code completion doesn't work if "min id length to show completion" is not 1. Red Panda C++ Version 2.23 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 5ed31232..4bcdce58 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -844,6 +844,7 @@ void Editor::keyPressEvent(QKeyEvent *event) QChar ch = t[0]; if (isIdentChar(ch)) { mLastIdCharPressed++; + qDebug()<codeCompletion().minCharRequired(); if (pSettings->codeCompletion().enabled() && pSettings->codeCompletion().showCompletionWhileInput() && mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) { @@ -855,7 +856,10 @@ void Editor::keyPressEvent(QKeyEvent *event) handled=true; return; } else { - QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY()); + QSynedit::BufferCoord cursor=caretXY(); + cursor.ch = std::max(1, cursor.ch-mLastIdCharPressed+1); + + QString lastWord = getPreviousWordAtPositionForSuggestion(cursor); if (mParser && !lastWord.isEmpty()) { if (lastWord == "typedef" || lastWord == "const") { processCommand(QSynedit::EditCommand::Char,ch,nullptr); @@ -926,7 +930,7 @@ void Editor::keyPressEvent(QKeyEvent *event) return; } } - lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(caretXY()); + lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(cursor); if (mParser && !lastWord.isEmpty()) { PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); while(currentScope && currentScope->kind==StatementKind::skBlock) { @@ -4919,7 +4923,7 @@ QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSy QString s = document()->getLine(p.line - 1); int wordBegin; - int wordEnd = p.ch-1; + int wordEnd = p.ch-2; if (wordEnd >= s.length()) wordEnd = s.length()-1; while (wordEnd > 0 && (isIdentChar(s[wordEnd]) || s[wordEnd] == ':')) {