Prevent suggestion of autocompletion while word modifying
Fix #330, close #8297
This commit is contained in:
parent
fdcd11ccc6
commit
e27d1a94c9
@ -77,24 +77,37 @@ bool AutoCompletion::showApiComplete()
|
|||||||
|
|
||||||
bool AutoCompletion::showApiAndWordComplete()
|
bool AutoCompletion::showApiAndWordComplete()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Get beginning of word and complete word
|
||||||
|
|
||||||
auto curPos = _pEditView->execute(SCI_GETCURRENTPOS);
|
auto curPos = _pEditView->execute(SCI_GETCURRENTPOS);
|
||||||
auto startPos = _pEditView->execute(SCI_WORDSTARTPOSITION, curPos, true);
|
auto startPos = _pEditView->execute(SCI_WORDSTARTPOSITION, curPos, true);
|
||||||
|
auto endPos = _pEditView->execute(SCI_WORDENDPOSITION, curPos, true);
|
||||||
|
|
||||||
if (curPos == startPos)
|
if (curPos == startPos)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const size_t bufSize = 256;
|
const size_t bufSize = 256;
|
||||||
TCHAR beginChars[bufSize];
|
TCHAR beginChars[bufSize];
|
||||||
|
TCHAR allChars[bufSize];
|
||||||
|
|
||||||
size_t len = (curPos > startPos)?(curPos - startPos):(startPos - curPos);
|
size_t len = (curPos > startPos)?(curPos - startPos):(startPos - curPos);
|
||||||
if (len >= bufSize)
|
if (len >= bufSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get word array
|
size_t lena = (endPos > startPos)?(endPos - startPos):(startPos - endPos);
|
||||||
vector<generic_string> wordArray;
|
if (lena >= bufSize)
|
||||||
_pEditView->getGenericText(beginChars, bufSize, startPos, curPos);
|
return false;
|
||||||
|
|
||||||
getWordArray(wordArray, beginChars);
|
_pEditView->getGenericText(beginChars, bufSize, startPos, curPos);
|
||||||
|
_pEditView->getGenericText(allChars, bufSize, startPos, endPos);
|
||||||
|
|
||||||
|
// Get word array containing all words beginning with beginChars, excluding word equal to allChars
|
||||||
|
|
||||||
|
vector<generic_string> wordArray;
|
||||||
|
getWordArray(wordArray, beginChars, allChars);
|
||||||
|
|
||||||
|
// Add keywords to word array
|
||||||
|
|
||||||
bool canStop = false;
|
bool canStop = false;
|
||||||
for (size_t i = 0, kwlen = _keyWordArray.size(); i < kwlen; ++i)
|
for (size_t i = 0, kwlen = _keyWordArray.size(); i < kwlen; ++i)
|
||||||
@ -112,9 +125,10 @@ bool AutoCompletion::showApiAndWordComplete()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort word array and convert it to a single string with space-separated words
|
||||||
|
|
||||||
sort(wordArray.begin(), wordArray.end());
|
sort(wordArray.begin(), wordArray.end());
|
||||||
|
|
||||||
// Get word list
|
|
||||||
generic_string words;
|
generic_string words;
|
||||||
|
|
||||||
for (size_t i = 0, wordArrayLen = wordArray.size(); i < wordArrayLen; ++i)
|
for (size_t i = 0, wordArrayLen = wordArray.size(); i < wordArrayLen; ++i)
|
||||||
@ -124,6 +138,8 @@ bool AutoCompletion::showApiAndWordComplete()
|
|||||||
words += TEXT(" ");
|
words += TEXT(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make Scintilla show the autocompletion menu
|
||||||
|
|
||||||
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' '));
|
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' '));
|
||||||
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
|
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
|
||||||
_pEditView->showAutoComletion(curPos - startPos, words.c_str());
|
_pEditView->showAutoComletion(curPos - startPos, words.c_str());
|
||||||
@ -131,7 +147,7 @@ bool AutoCompletion::showApiAndWordComplete()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beginChars)
|
void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beginChars, TCHAR *allChars)
|
||||||
{
|
{
|
||||||
const size_t bufSize = 256;
|
const size_t bufSize = 256;
|
||||||
const NppGUI & nppGUI = NppParameters::getInstance().getNppGUI();
|
const NppGUI & nppGUI = NppParameters::getInstance().getNppGUI();
|
||||||
@ -160,9 +176,11 @@ void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beg
|
|||||||
{
|
{
|
||||||
TCHAR w[bufSize];
|
TCHAR w[bufSize];
|
||||||
_pEditView->getGenericText(w, bufSize, wordStart, wordEnd);
|
_pEditView->getGenericText(w, bufSize, wordStart, wordEnd);
|
||||||
|
if (!allChars || (generic_strncmp (w, allChars, bufSize) != 0))
|
||||||
if (!isInList(w, wordArray))
|
{
|
||||||
wordArray.push_back(w);
|
if (!isInList(w, wordArray))
|
||||||
|
wordArray.push_back(w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
posFind = _pEditView->searchInTarget(expr.c_str(), static_cast<int32_t>(expr.length()), wordEnd, docLength);
|
posFind = _pEditView->searchInTarget(expr.c_str(), static_cast<int32_t>(expr.length()), wordEnd, docLength);
|
||||||
}
|
}
|
||||||
@ -325,27 +343,39 @@ void AutoCompletion::showPathCompletion()
|
|||||||
|
|
||||||
bool AutoCompletion::showWordComplete(bool autoInsert)
|
bool AutoCompletion::showWordComplete(bool autoInsert)
|
||||||
{
|
{
|
||||||
|
// Get beginning of word and complete word
|
||||||
|
|
||||||
int curPos = int(_pEditView->execute(SCI_GETCURRENTPOS));
|
int curPos = int(_pEditView->execute(SCI_GETCURRENTPOS));
|
||||||
int startPos = int(_pEditView->execute(SCI_WORDSTARTPOSITION, curPos, true));
|
int startPos = int(_pEditView->execute(SCI_WORDSTARTPOSITION, curPos, true));
|
||||||
|
int endPos = int(_pEditView->execute(SCI_WORDENDPOSITION, curPos, true));
|
||||||
|
|
||||||
if (curPos == startPos)
|
if (curPos == startPos)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const size_t bufSize = 256;
|
const size_t bufSize = 256;
|
||||||
TCHAR beginChars[bufSize];
|
TCHAR beginChars[bufSize];
|
||||||
|
TCHAR allChars[bufSize];
|
||||||
|
|
||||||
size_t len = (curPos > startPos)?(curPos - startPos):(startPos - curPos);
|
size_t len = (curPos > startPos)?(curPos - startPos):(startPos - curPos);
|
||||||
if (len >= bufSize)
|
if (len >= bufSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get word array
|
size_t lena = (endPos > startPos)?(endPos - startPos):(startPos - endPos);
|
||||||
vector<generic_string> wordArray;
|
if (lena >= bufSize)
|
||||||
_pEditView->getGenericText(beginChars, bufSize, startPos, curPos);
|
return false;
|
||||||
|
|
||||||
getWordArray(wordArray, beginChars);
|
_pEditView->getGenericText(beginChars, bufSize, startPos, curPos);
|
||||||
|
_pEditView->getGenericText(allChars, bufSize, startPos, endPos);
|
||||||
|
|
||||||
|
// Get word array containing all words beginning with beginChars, excluding word equal to allChars
|
||||||
|
|
||||||
|
vector<generic_string> wordArray;
|
||||||
|
getWordArray(wordArray, beginChars, allChars);
|
||||||
|
|
||||||
if (wordArray.size() == 0) return false;
|
if (wordArray.size() == 0) return false;
|
||||||
|
|
||||||
|
// Optionally, auto-insert word
|
||||||
|
|
||||||
if (wordArray.size() == 1 && autoInsert)
|
if (wordArray.size() == 1 && autoInsert)
|
||||||
{
|
{
|
||||||
int replacedLength = _pEditView->replaceTargetRegExMode(wordArray[0].c_str(), startPos, curPos);
|
int replacedLength = _pEditView->replaceTargetRegExMode(wordArray[0].c_str(), startPos, curPos);
|
||||||
@ -353,9 +383,10 @@ bool AutoCompletion::showWordComplete(bool autoInsert)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort word array and convert it to a single string with space-separated words
|
||||||
|
|
||||||
sort(wordArray.begin(), wordArray.end());
|
sort(wordArray.begin(), wordArray.end());
|
||||||
|
|
||||||
// Get word list
|
|
||||||
generic_string words(TEXT(""));
|
generic_string words(TEXT(""));
|
||||||
|
|
||||||
for (size_t i = 0, wordArrayLen = wordArray.size(); i < wordArrayLen; ++i)
|
for (size_t i = 0, wordArrayLen = wordArray.size(); i < wordArrayLen; ++i)
|
||||||
@ -365,6 +396,8 @@ bool AutoCompletion::showWordComplete(bool autoInsert)
|
|||||||
words += TEXT(" ");
|
words += TEXT(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make Scintilla show the autocompletion menu
|
||||||
|
|
||||||
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' '));
|
_pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' '));
|
||||||
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
|
_pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase);
|
||||||
_pEditView->showAutoComletion(curPos - startPos, words.c_str());
|
_pEditView->showAutoComletion(curPos - startPos, words.c_str());
|
||||||
|
@ -102,5 +102,5 @@ private:
|
|||||||
FunctionCallTip _funcCalltip;
|
FunctionCallTip _funcCalltip;
|
||||||
|
|
||||||
const TCHAR * getApiFileName();
|
const TCHAR * getApiFileName();
|
||||||
void getWordArray(std::vector<generic_string> & wordArray, TCHAR *beginChars);
|
void getWordArray(std::vector<generic_string> & wordArray, TCHAR *beginChars, TCHAR *excludeChars);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user