From 4fd972cda372fd96229883d29481f600dd7873d4 Mon Sep 17 00:00:00 2001 From: mpheath Date: Sun, 12 Feb 2023 12:59:45 +1000 Subject: [PATCH] Auto-completion enhancement: reduce duplicate items in function/word list Fix #13061, close #13098 --- .../src/ScintillaComponent/AutoCompletion.cpp | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp index 3d446daa6..d6556ae88 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp @@ -372,7 +372,15 @@ bool AutoCompletion::showAutoComplete(AutocompleteType autocType, bool autoInser if (autocType == autocWord && wordArray.size() == 1 && autoInsert) { - intptr_t replacedLength = _pEditView->replaceTarget(wordArray[0].c_str(), startPos, curPos); + size_t typeSeparatorPos = wordArray[0].find(L"\x1E"); + + intptr_t replacedLength = _pEditView->replaceTarget( + (typeSeparatorPos == std::string::npos) ? + wordArray[0].c_str() : + wordArray[0].substr(0, typeSeparatorPos).c_str(), + startPos, curPos + ); + _pEditView->execute(SCI_GOTOPOS, startPos + replacedLength); return true; } @@ -465,6 +473,9 @@ void AutoCompletion::getWordArray(vector & wordArray, TCHAR *beg _pEditView->execute(SCI_SETSEARCHFLAGS, flags); intptr_t posFind = _pEditView->searchInTarget(expr.c_str(), expr.length(), 0, docLength); + generic_string boxId = TEXT("\x1E") + intToString(BOX_IMG_ID); + generic_string funcId = TEXT("\x1E") + intToString(FUNC_IMG_ID); + while (posFind >= 0) { intptr_t wordStart = _pEditView->execute(SCI_GETTARGETSTART); @@ -477,8 +488,28 @@ void AutoCompletion::getWordArray(vector & wordArray, TCHAR *beg _pEditView->getGenericText(w, bufSize, wordStart, wordEnd); if (!allChars || (wcsncmp(w, allChars, bufSize) != 0)) { - if (!isInList(w, wordArray)) - wordArray.push_back(w); + if (_funcCompletionActive) + { + if (isInList(w + boxId, _keyWordArray)) + { + if (!isInList(w + boxId, wordArray)) + wordArray.push_back(w + boxId); + } + else if (isInList(w + funcId, _keyWordArray)) + { + if (!isInList(w + funcId, wordArray)) + wordArray.push_back(w + funcId); + } + else if (!isInList(w, wordArray)) + { + wordArray.push_back(w); + } + } + else + { + if (!isInList(w, wordArray)) + wordArray.push_back(w); + } } } posFind = _pEditView->searchInTarget(expr.c_str(), expr.length(), wordEnd, docLength);