Auto-completion enhancement: reduce duplicate items in function/word list

Fix #13061, close #13098
This commit is contained in:
mpheath 2023-02-12 12:59:45 +10:00 committed by Don Ho
parent 1b65cc0104
commit 4fd972cda3

View File

@ -372,7 +372,15 @@ bool AutoCompletion::showAutoComplete(AutocompleteType autocType, bool autoInser
if (autocType == autocWord && wordArray.size() == 1 && autoInsert) 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); _pEditView->execute(SCI_GOTOPOS, startPos + replacedLength);
return true; return true;
} }
@ -465,6 +473,9 @@ void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beg
_pEditView->execute(SCI_SETSEARCHFLAGS, flags); _pEditView->execute(SCI_SETSEARCHFLAGS, flags);
intptr_t posFind = _pEditView->searchInTarget(expr.c_str(), expr.length(), 0, docLength); 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) while (posFind >= 0)
{ {
intptr_t wordStart = _pEditView->execute(SCI_GETTARGETSTART); intptr_t wordStart = _pEditView->execute(SCI_GETTARGETSTART);
@ -477,8 +488,28 @@ void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beg
_pEditView->getGenericText(w, bufSize, wordStart, wordEnd); _pEditView->getGenericText(w, bufSize, wordStart, wordEnd);
if (!allChars || (wcsncmp(w, allChars, bufSize) != 0)) if (!allChars || (wcsncmp(w, allChars, bufSize) != 0))
{ {
if (!isInList(w, wordArray)) if (_funcCompletionActive)
wordArray.push_back(w); {
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); posFind = _pEditView->searchInTarget(expr.c_str(), expr.length(), wordEnd, docLength);