From 62a23a8dc792144f6e51ae045f28a3afbdc6d85b Mon Sep 17 00:00:00 2001 From: mpheath Date: Mon, 26 Dec 2022 23:29:17 +1000 Subject: [PATCH] Fix autocomplete to sort case insensitive issue Fix #12495, close #12703 --- .../src/ScintillaComponent/AutoCompletion.cpp | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp index e40d12a94..100c982ea 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp @@ -268,6 +268,25 @@ static bool isAllDigits(const generic_string &str) return true; } +void sortInsensitive(vector &wordArray) +{ + sort( + wordArray.begin(), + wordArray.end(), + [](const generic_string &a, const generic_string &b) + { + return lexicographical_compare( + a.begin(), a.end(), + b.begin(), b.end(), + [](const wchar_t &ch1, const wchar_t &ch2) + { + return toupper(ch1) < toupper(ch2); + } + ); + } + ); +} + bool AutoCompletion::showApiComplete() { @@ -311,6 +330,7 @@ bool AutoCompletion::showApiComplete() _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('\x1E')); _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); + _pEditView->execute(SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, _keyWords.c_str()); return true; @@ -376,7 +396,10 @@ bool AutoCompletion::showApiAndWordComplete() // Sort word array and convert it to a single string with space-separated words - sort(wordArray.begin(), wordArray.end()); + if (_ignoreCase) + sortInsensitive(wordArray); + else + sort(wordArray.begin(), wordArray.end()); generic_string words; @@ -415,6 +438,7 @@ bool AutoCompletion::showApiAndWordComplete() _pEditView->execute(SCI_AUTOCSETTYPESEPARATOR, WPARAM('\x1E')); _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); + _pEditView->execute(SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, words.c_str()); return true; } @@ -610,6 +634,7 @@ void AutoCompletion::showPathCompletion() // Show autocompletion box. _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM('\n')); _pEditView->execute(SCI_AUTOCSETIGNORECASE, true); + _pEditView->execute(SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, true); _pEditView->showAutoComletion(rawPath.length(), autoCompleteEntries.c_str()); return; } @@ -658,7 +683,10 @@ bool AutoCompletion::showWordComplete(bool autoInsert) // Sort word array and convert it to a single string with space-separated words - sort(wordArray.begin(), wordArray.end()); + if (_ignoreCase) + sortInsensitive(wordArray); + else + sort(wordArray.begin(), wordArray.end()); generic_string words(TEXT("")); @@ -673,6 +701,7 @@ bool AutoCompletion::showWordComplete(bool autoInsert) _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); + _pEditView->execute(SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, _ignoreCase); _pEditView->showAutoComletion(curPos - startPos, words.c_str()); return true; } @@ -1193,7 +1222,10 @@ bool AutoCompletion::setLanguage(LangType language) } } - sort(_keyWordArray.begin(), _keyWordArray.end()); + if (_ignoreCase) + sortInsensitive(_keyWordArray); + else + sort(_keyWordArray.begin(), _keyWordArray.end()); for (size_t i = 0, len = _keyWordArray.size(); i < len; ++i) {