+rfc: code cleanup for AutoCompletion parts

This commit is contained in:
METANEOCORTEX\Kotti 2021-12-02 16:05:54 +01:00
parent cb2934e45e
commit c25aa557d1
5 changed files with 35 additions and 21 deletions

View File

@ -379,6 +379,7 @@ void EditInitWordDelimiter(HWND hwnd)
++i;
}
}
SciCall_AutoCSetFillups(AutoCompleteFillUpChars);
if (StrIsNotEmpty(Settings2.AutoCompleteWordCharSet)) {
WideCharToMultiByte(Encoding_SciCP, 0, Settings2.AutoCompleteWordCharSet, -1, AutoCompleteWordCharSet, (int)COUNTOF(AutoCompleteWordCharSet), NULL, NULL);
@ -7669,16 +7670,13 @@ typedef struct WLIST {
} WLIST, *PWLIST;
static int wordcmp(PWLIST a, PWLIST b)
{
static int wordcmp(PWLIST a, PWLIST b) {
return StringCchCompareXA(a->word, b->word);
}
/* unused yet
static int wordcmpi(PWLIST a, PWLIST b) {
return StringCchCompareXIA(a->word, b->word);
}
*/
// ----------------------------------------------
@ -7764,6 +7762,8 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
PWLIST pListHead = NULL;
bool const bDoSortOrder = (SciCall_AutoCGetOrder() == SC_ORDER_PRESORTED);
// --------------------------------------------------------------------------
if (Settings.AutoCompleteWords || (autoInsert && !Settings.AutoCLexerKeyWords)) {
// --------------------------------------------------------------------------
@ -7791,8 +7791,12 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
PWLIST pWLItem = NULL;
LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlNewWord, wordcmp);
if (!pWLItem) { // not found
//LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi);
LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord);
if (bDoSortOrder) {
LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi);
}
else {
LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord);
}
++iNumWords;
iWListSize += (wordLength + 1);
pwlNewWord = NULL; // alloc new
@ -7832,8 +7836,12 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
PWLIST pWLItem = NULL;
LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlNewWord, wordcmp);
if (!pWLItem) { // not found
//LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi);
LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord);
if (bDoSortOrder) {
LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi);
}
else {
LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord);
}
++iNumWords;
iWListSize += ((size_t)wlen + 1LL);
pwlNewWord = NULL; // alloc new
@ -7852,20 +7860,11 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
if (iNumWords > 0) {
const char* const sep = " ";
SciCall_AutoCCancel();
SciCall_ClearRegisteredImages();
SciCall_AutoCSetOptions(SC_AUTOCOMPLETE_FIXED_SIZE);
SciCall_AutoCSetSeperator(sep[0]);
SciCall_AutoCSetIgnoreCase(true);
//~SciCall_AutoCSetCaseInsensitiveBehaviour(SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE);
SciCall_AutoCSetChooseSingle(autoInsert);
SciCall_AutoCSetOrder(SC_ORDER_PERFORMSORT); // already sorted
SciCall_AutoCSetFillups(AutoCompleteFillUpChars);
SciCall_SetElementColour(SC_ELEMENT_LIST, RGBxA(GetModeTextColor(UseDarkMode()), SC_ALPHA_OPAQUE));
SciCall_SetElementColour(SC_ELEMENT_LIST_BACK, RGBxA(GetModeBkColor(UseDarkMode()), SC_ALPHA_OPAQUE));
const char* const sep = " ";
SciCall_AutoCSetSeperator(sep[0]);
++iWListSize; // zero termination
char* const pList = AllocMem(iWListSize + 1, HEAP_ZERO_MEMORY);

View File

@ -295,7 +295,7 @@ inline COLORREF GetModeBtnfaceColor(const bool bDarkMode)
inline int SetModeTextColor(const HDC hdc, const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return SetTextColor(hdc, bDarkMode ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_BTNTEXT));
return SetTextColor(hdc, bDarkMode ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_WINDOWTEXT));
#else
UNREFERENCED_PARAMETER(bDarkMode);
return SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
@ -305,7 +305,7 @@ inline int SetModeTextColor(const HDC hdc, const bool bDarkMode)
inline COLORREF GetModeTextColor(const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return bDarkMode ? Settings2.DarkModeTxtColor : (COLORREF)GetSysColor(COLOR_BTNTEXT);
return bDarkMode ? Settings2.DarkModeTxtColor : (COLORREF)GetSysColor(COLOR_WINDOWTEXT);
#else
UNREFERENCED_PARAMETER(bDarkMode);
return (COLORREF)GetSysColor(COLOR_BTNTEXT);

View File

@ -2260,6 +2260,13 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl)
// word delimiter handling
EditInitWordDelimiter(hwndEditCtrl);
EditSetAccelWordNav(hwndEditCtrl, Settings.AccelWordNavigation);
SciCall_ClearRegisteredImages();
SciCall_AutoCSetOptions(SC_AUTOCOMPLETE_FIXED_SIZE);
SciCall_AutoCSetIgnoreCase(true);
//~SciCall_AutoCSetCaseInsensitiveBehaviour(SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE);
SciCall_AutoCSetOrder(SC_ORDER_PRESORTED); // already sorted
//SciCall_AutoCSetOrder(SC_ORDER_PERFORMSORT);
}

View File

@ -444,6 +444,7 @@ DeclareSciCallV1(AutoCSetCaseInsensitiveBehaviour, AUTOCSETCASEINSENSITIVEBEHAVI
DeclareSciCallV1(AutoCSetSeperator, AUTOCSETSEPARATOR, char, seperator);
DeclareSciCallV01(AutoCSetFillups, AUTOCSETFILLUPS, const char*, text);
DeclareSciCallV1(AutoCSetChooseSingle, AUTOCSETCHOOSESINGLE, bool, flag);
DeclareSciCallR0(AutoCGetOrder, AUTOCGETORDER, int);
DeclareSciCallV1(AutoCSetOrder, AUTOCSETORDER, int, options);
DeclareSciCallV1(AutoCSetMulti, AUTOCSETMULTI, int, options);
DeclareSciCallV2(AutoCShow, AUTOCSHOW, DocPos, len, const char*, list);

View File

@ -1542,6 +1542,13 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew)
SciCall_ResetElementColour(SC_ELEMENT_SELECTION_ADDITIONAL_BACK);
}
// AutoCompletion List
SciCall_SetElementColour(SC_ELEMENT_LIST, RGBxA(GetModeTextColor(UseDarkMode()), SC_ALPHA_OPAQUE));
SciCall_SetElementColour(SC_ELEMENT_LIST_BACK, RGBxA(GetModeBkColor(UseDarkMode()), SC_ALPHA_OPAQUE));
//SciCall_SetElementColour(SC_ELEMENT_LIST_SELECTED, SciCall_GetElementBaseColour(SC_ELEMENT_LIST_SELECTED));
//SciCall_SetElementColour(SC_ELEMENT_LIST_SELECTED_BACK, SciCall_GetElementBaseColour(SC_ELEMENT_LIST_SELECTED_BACK));
// selection eolfilled
bFlag = Style_StrHasAttribute(pCurrentStandard->Styles[STY_SEL_TXT].szValue, FontEffects[FE_EOLFILLED]);
SciCall_SetSelEOLFilled(bFlag);