- fix: Code completion doesn't work if "min id length to show completion" is not 1.

This commit is contained in:
Roy Qu 2023-07-14 22:01:58 +08:00
parent cd4284f13d
commit 2943226e46
2 changed files with 8 additions and 3 deletions

View File

@ -2,6 +2,7 @@ Red Panda C++ Version 2.24
- fix: members of elements of stl maps are not correctly suggested. - fix: members of elements of stl maps are not correctly suggested.
- fix: memory view's cell size is too wide in linux. - 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 Red Panda C++ Version 2.23

View File

@ -844,6 +844,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
QChar ch = t[0]; QChar ch = t[0];
if (isIdentChar(ch)) { if (isIdentChar(ch)) {
mLastIdCharPressed++; mLastIdCharPressed++;
qDebug()<<mLastIdCharPressed<<pSettings->codeCompletion().minCharRequired();
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() && pSettings->codeCompletion().showCompletionWhileInput()
&& mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) { && mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) {
@ -855,7 +856,10 @@ void Editor::keyPressEvent(QKeyEvent *event)
handled=true; handled=true;
return; return;
} else { } 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 (mParser && !lastWord.isEmpty()) {
if (lastWord == "typedef" || lastWord == "const") { if (lastWord == "typedef" || lastWord == "const") {
processCommand(QSynedit::EditCommand::Char,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
@ -926,7 +930,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
return; return;
} }
} }
lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(caretXY()); lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(cursor);
if (mParser && !lastWord.isEmpty()) { if (mParser && !lastWord.isEmpty()) {
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
while(currentScope && currentScope->kind==StatementKind::skBlock) { while(currentScope && currentScope->kind==StatementKind::skBlock) {
@ -4919,7 +4923,7 @@ QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSy
QString s = document()->getLine(p.line - 1); QString s = document()->getLine(p.line - 1);
int wordBegin; int wordBegin;
int wordEnd = p.ch-1; int wordEnd = p.ch-2;
if (wordEnd >= s.length()) if (wordEnd >= s.length())
wordEnd = s.length()-1; wordEnd = s.length()-1;
while (wordEnd > 0 && (isIdentChar(s[wordEnd]) || s[wordEnd] == ':')) { while (wordEnd > 0 && (isIdentChar(s[wordEnd]) || s[wordEnd] == ':')) {