diff --git a/language/common_res.h b/language/common_res.h index 380c2c367..d2d50c6d8 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -504,32 +504,34 @@ #define IDM_VIEW_MARKOCCUR_CURRENT 40451 #define IDM_VIEW_MARKOCCUR_VISIBLE 40452 #define IDM_VIEW_AUTOCOMPLETEWORDS 40453 -#define IDM_VIEW_ACCELWORDNAV 40454 -#define IDM_VIEW_NOPRESERVECARET 40455 -#define IDM_VIEW_HYPERLINKHOTSPOTS 40456 -#define IDM_VIEW_CURRENTSCHEME 40457 -#define IDM_VIEW_SCROLLPASTEOF 40458 -#define IDM_VIEW_TOGGLE_VIEW 40459 -#define IDM_VIEW_CHASING_DOCTAIL 40460 -#define IDM_VIEW_TOGGLETB 40461 -#define IDM_SET_RENDER_TECH_DEFAULT 40462 -#define IDM_SET_RENDER_TECH_D2D 40463 -#define IDM_SET_RENDER_TECH_D2DRETAIN 40464 -#define IDM_SET_RENDER_TECH_D2DDC 40465 -#define IDM_SET_BIDIRECTIONAL_NONE 40466 -#define IDM_SET_BIDIRECTIONAL_L2R 40467 -#define IDM_SET_BIDIRECTIONAL_R2L 40468 +#define IDM_VIEW_AUTOCLEXKEYWORDS 40454 +#define IDM_VIEW_ACCELWORDNAV 40455 +#define IDM_VIEW_NOPRESERVECARET 40456 +#define IDM_VIEW_HYPERLINKHOTSPOTS 40457 +#define IDM_VIEW_CURRENTSCHEME 40458 +#define IDM_VIEW_SCROLLPASTEOF 40459 +#define IDM_VIEW_TOGGLE_VIEW 40460 +#define IDM_VIEW_CHASING_DOCTAIL 40461 +#define IDM_VIEW_TOGGLETB 40462 -#define IDM_HELP_ABOUT 40500 -#define IDM_HELP_CMD 40501 -#define IDM_HELP_ONLINEDOCUMENTATION 40502 +#define IDM_SET_RENDER_TECH_DEFAULT 40500 +#define IDM_SET_RENDER_TECH_D2D 40501 +#define IDM_SET_RENDER_TECH_D2DRETAIN 40502 +#define IDM_SET_RENDER_TECH_D2DDC 40503 +#define IDM_SET_BIDIRECTIONAL_NONE 40504 +#define IDM_SET_BIDIRECTIONAL_L2R 40505 +#define IDM_SET_BIDIRECTIONAL_R2L 40506 -#define IDM_TRAY_RESTORE 40600 -#define IDM_TRAY_EXIT 40601 -#define IDM_SETPASS 40602 +#define IDM_HELP_ABOUT 40600 +#define IDM_HELP_CMD 40601 +#define IDM_HELP_ONLINEDOCUMENTATION 40602 #define IDM_HELP_ADMINEXE 40603 #define IDM_HELP_UPDATEWEBSITE 40604 -#define IDM_EDIT_INSERT_GUID 40605 + +#define IDM_TRAY_RESTORE 40700 +#define IDM_TRAY_EXIT 40701 +#define IDM_SETPASS 40702 +#define IDM_EDIT_INSERT_GUID 40705 #define IDS_ENC_ANSI 61000 diff --git a/language/np3_af_za/menu_af_za.rc b/language/np3_af_za/menu_af_za.rc index 122b1b0b9..074d51fab 100644 Binary files a/language/np3_af_za/menu_af_za.rc and b/language/np3_af_za/menu_af_za.rc differ diff --git a/language/np3_de_de/menu_de_de.rc b/language/np3_de_de/menu_de_de.rc index 8941cf2f8..40a786781 100644 Binary files a/language/np3_de_de/menu_de_de.rc and b/language/np3_de_de/menu_de_de.rc differ diff --git a/language/np3_en_gb/menu_en_gb.rc b/language/np3_en_gb/menu_en_gb.rc index acc2a3822..3d605e721 100644 Binary files a/language/np3_en_gb/menu_en_gb.rc and b/language/np3_en_gb/menu_en_gb.rc differ diff --git a/language/np3_en_us/menu_en_us.rc b/language/np3_en_us/menu_en_us.rc index fe76a5d17..11033fee4 100644 Binary files a/language/np3_en_us/menu_en_us.rc and b/language/np3_en_us/menu_en_us.rc differ diff --git a/language/np3_es_es/menu_es_es.rc b/language/np3_es_es/menu_es_es.rc index 061baf88d..371b37fce 100644 Binary files a/language/np3_es_es/menu_es_es.rc and b/language/np3_es_es/menu_es_es.rc differ diff --git a/language/np3_fr_fr/menu_fr_fr.rc b/language/np3_fr_fr/menu_fr_fr.rc index 27769e863..3ad33daf6 100644 Binary files a/language/np3_fr_fr/menu_fr_fr.rc and b/language/np3_fr_fr/menu_fr_fr.rc differ diff --git a/language/np3_ja_jp/menu_ja_jp.rc b/language/np3_ja_jp/menu_ja_jp.rc index 08dd86515..b612145af 100644 Binary files a/language/np3_ja_jp/menu_ja_jp.rc and b/language/np3_ja_jp/menu_ja_jp.rc differ diff --git a/language/np3_nl_nl/menu_nl_nl.rc b/language/np3_nl_nl/menu_nl_nl.rc index 72e781561..781b8fa6a 100644 Binary files a/language/np3_nl_nl/menu_nl_nl.rc and b/language/np3_nl_nl/menu_nl_nl.rc differ diff --git a/language/np3_zh_cn/menu_zh_cn.rc b/language/np3_zh_cn/menu_zh_cn.rc index eb93fa7eb..0ac28463c 100644 Binary files a/language/np3_zh_cn/menu_zh_cn.rc and b/language/np3_zh_cn/menu_zh_cn.rc differ diff --git a/src/Edit.c b/src/Edit.c index 9b9c9e4f1..d6ddf60d8 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -97,6 +97,8 @@ extern bool bForceLoadASCIIasUTF8; extern bool bLoadNFOasOEM; extern bool bNoEncodingTags; +extern bool g_bAutoCompleteWords; +extern bool g_bAutoCLexerKeyWords; extern bool g_bAccelWordNavigation; extern int g_iReplacedOccurrences; @@ -6595,12 +6597,41 @@ static int __fastcall wordcmpi(PWLIST a, PWLIST b) { // ---------------------------------------------- +static const char* __fastcall _strNextLexKeyWord(const char* strg, const char* const wdroot, DocPosCR* pwdlen) +{ + char const sep = ' '; + bool found = false; + const char* start = strg; + do { + start = StrStrIA(start, wdroot); + if (start) { + if ((start == strg) || (start[-1] == sep)) { // word begin + found = true; + break; + } + ++start; + } + } while (start && *start); + + if (found) { + DocPosCR len = *pwdlen; + while (start[len] && (start[len] != sep)) { ++len; } + *pwdlen = len; + } + else { + *pwdlen = 0; + } + return (found ? start : NULL); +} + +// ---------------------------------------------- + void EditCompleteWord(HWND hwnd, bool autoInsert) { UNUSED(hwnd); // OLD: "_abcdefghijklmnopqrstuvwxyz0123456789" - char const * ALLOWED_WORD_CHARS = AutoCompleteWordASCII; + char const* ALLOWED_WORD_CHARS = AutoCompleteWordASCII; if (ALLOWED_WORD_CHARS[0] == '\0') { ALLOWED_WORD_CHARS = g_bAccelWordNavigation ? WordCharsAccelerated : WordCharsDefault; @@ -6632,53 +6663,94 @@ void EditCompleteWord(HWND hwnd, bool autoInsert) StringCchCopyNA(pRoot, COUNTOF(pRoot), pLine + iStartWordPos, (size_t)iRootLen); - - DocPosCR const iDocLen = (DocPosCR)SciCall_GetTextLength(); - struct Sci_TextToFind ft = { { 0, 0 }, 0, { 0, 0 } }; - ft.lpstrText = pRoot; - ft.chrg.cpMax = iDocLen; - - DocPos iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); - int iNumWords = 0; size_t iWListSize = 0; - PWLIST pwlWord = NULL; - PWLIST pWLItem = NULL; PWLIST pListHead = NULL; - while ((iPosFind >= 0) && (iPosFind < iDocLen)) + if (g_bAutoCompleteWords) { - DocPos wordEnd = (DocPosCR)(iPosFind + iRootLen); + DocPosCR const iDocLen = (DocPosCR)SciCall_GetTextLength(); + struct Sci_TextToFind ft = { { 0, 0 }, 0, { 0, 0 } }; + ft.lpstrText = pRoot; + ft.chrg.cpMax = iDocLen; - if (iPosFind != (iCurrentPos - iRootLen)) + DocPos iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); + PWLIST pwlNewWord = NULL; + while ((iPosFind >= 0) && (iPosFind < iDocLen)) { - while ((wordEnd < iDocLen) && StrChrIA(ALLOWED_WORD_CHARS, SciCall_GetCharAt(wordEnd))) { ++wordEnd; } + DocPos wordEnd = (DocPosCR)(iPosFind + iRootLen); - DocPos const wordLength = (wordEnd - iPosFind); - if (wordLength > iRootLen) + if (iPosFind != (iCurrentPos - iRootLen)) { - if (!pwlWord) { pwlWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } - if (pwlWord) - { - StringCchCopyNA(pwlWord->word, _MAX_AUTOC_WORD_LEN, SciCall_GetRangePointer(iPosFind, wordLength), wordLength); + while ((wordEnd < iDocLen) && StrChrIA(ALLOWED_WORD_CHARS, SciCall_GetCharAt(wordEnd))) { ++wordEnd; } - PWLIST pPrev = NULL; - LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlWord, wordcmp); - if (!pWLItem) { // not found - //LL_INSERT_INORDER(pListHead, pwlWord, wordcmpi); - LL_APPEND_ELEM(pListHead, pPrev, pwlWord); - ++iNumWords; - iWListSize += (wordLength + 1); - pwlWord = NULL; // alloc new + DocPos const wordLength = (wordEnd - iPosFind); + if (wordLength > iRootLen) + { + if (!pwlNewWord) { pwlNewWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } + if (pwlNewWord) + { + StringCchCopyNA(pwlNewWord->word, _MAX_AUTOC_WORD_LEN, SciCall_GetRangePointer(iPosFind, wordLength), wordLength); + + PWLIST pPrev = NULL; + 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); + ++iNumWords; + iWListSize += (wordLength + 1); + pwlNewWord = NULL; // alloc new + } } } } + ft.chrg.cpMin = (DocPosCR)wordEnd; + iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); } - ft.chrg.cpMin = (DocPosCR)wordEnd; - iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); + if (pwlNewWord) { FreeMem(pwlNewWord); pwlNewWord = NULL; } } - if (pwlWord) { FreeMem(pwlWord); pwlWord = NULL; } + + // -------------------------------------------------------------------------- + + if (g_bAutoCLexerKeyWords) + { + PKEYWORDLIST const pKeyWordList = Style_GetCurrentLexerPtr()->pKeyWords; + + PWLIST pwlNewWord = NULL; + for (int i = 0; i <= KEYWORDSET_MAX; ++i) { + const char* word = pKeyWordList->pszKeyWords[i]; + do { + DocPosCR wlen = iRootLen; + word = _strNextLexKeyWord(word, pRoot, &wlen); + if (word) { + if (wlen > iRootLen) { + if (!pwlNewWord) { pwlNewWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } + if (pwlNewWord) + { + StringCchCopyNA(pwlNewWord->word, _MAX_AUTOC_WORD_LEN, word, wlen); + + PWLIST pPrev = NULL; + 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); + ++iNumWords; + iWListSize += (wlen + 1); + pwlNewWord = NULL; // alloc new + } + } + } + word += (wlen ? wlen : 1); + } + } while (word && word[0]); + } + if (pwlNewWord) { FreeMem(pwlNewWord); pwlNewWord = NULL; } + } + + // -------------------------------------------------------------------------- if (iNumWords > 0) { @@ -6696,6 +6768,7 @@ void EditCompleteWord(HWND hwnd, bool autoInsert) char* const pList = AllocMem(iWListSize, HEAP_ZERO_MEMORY); if (pList) { PWLIST pTmp = NULL; + PWLIST pWLItem = NULL; LL_FOREACH_SAFE(pListHead, pWLItem, pTmp) { if (pWLItem->word[0]) { StringCchCatA(pList, iWListSize, sep); diff --git a/src/Notepad3.c b/src/Notepad3.c index 45b67a2b5..b55d3f43f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -211,6 +211,7 @@ bool g_bMarkOccurrencesMatchWords; bool g_bMarkOccurrencesCurrentWord; bool g_bUseOldStyleBraceMatching; bool g_bAutoCompleteWords; +bool g_bAutoCLexerKeyWords; bool g_bAccelWordNavigation; bool g_bDenyVirtualSpaceAccess; bool g_bCodeFoldingAvailable; @@ -2932,6 +2933,8 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) EnableCmd(hmenu,IDM_EDIT_COMPLETEWORD,!e && !ro); CheckCmd(hmenu,IDM_VIEW_AUTOCOMPLETEWORDS,g_bAutoCompleteWords && !ro); + CheckCmd(hmenu,IDM_VIEW_AUTOCLEXKEYWORDS, g_bAutoCLexerKeyWords && !ro); + CheckCmd(hmenu,IDM_VIEW_ACCELWORDNAV,g_bAccelWordNavigation); CheckCmd(hmenu, IDM_VIEW_MARKOCCUR_ONOFF, (g_iMarkOccurrences > 0)); @@ -4735,9 +4738,12 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_AUTOCOMPLETEWORDS: g_bAutoCompleteWords = (g_bAutoCompleteWords) ? false : true; // toggle - if (!g_bAutoCompleteWords) { - SciCall_AutoCCancel(); // close the auto completion list - } + SciCall_AutoCCancel(); + break; + + case IDM_VIEW_AUTOCLEXKEYWORDS: + g_bAutoCLexerKeyWords = (g_bAutoCLexerKeyWords) ? false : true; // toggle + SciCall_AutoCCancel(); break; case IDM_VIEW_ACCELWORDNAV: @@ -6341,7 +6347,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) else if (scn->ch == '?') { _HandleTinyExpr(); } - else if (g_bAutoCompleteWords && !SciCall_AutoCActive() && !_IsInlineIMEActive()) { + else if ((g_bAutoCompleteWords || g_bAutoCLexerKeyWords) && !SciCall_AutoCActive() && !_IsInlineIMEActive()) { EditCompleteWord(g_hwndEdit, false); } } @@ -6772,6 +6778,8 @@ void LoadSettings() bAutoIndent = IniSectionGetBool(pIniSection, L"AutoIndent", true); g_bAutoCompleteWords = IniSectionGetBool(pIniSection, L"AutoCompleteWords", false); + + g_bAutoCLexerKeyWords = IniSectionGetBool(pIniSection, L"AutoCLexerKeyWords", false); g_bAccelWordNavigation = IniSectionGetBool(pIniSection, L"AccelWordNavigation", false); @@ -7127,6 +7135,7 @@ void SaveSettings(bool bSaveSettingsNow) { IniSectionSetBool(pIniSection, L"ScrollPastEOF", bScrollPastEOF); IniSectionSetBool(pIniSection, L"AutoIndent", bAutoIndent); IniSectionSetBool(pIniSection, L"AutoCompleteWords", g_bAutoCompleteWords); + IniSectionSetBool(pIniSection, L"AutoCLexerKeyWords", g_bAutoCLexerKeyWords); IniSectionSetBool(pIniSection, L"AccelWordNavigation", g_bAccelWordNavigation); IniSectionSetBool(pIniSection, L"ShowIndentGuides", bShowIndentGuides); IniSectionSetBool(pIniSection, L"TabsAsSpaces", bTabsAsSpacesG); diff --git a/src/StyleLexers/EditLexer.h b/src/StyleLexers/EditLexer.h index a28b7bdc2..a36a0fd68 100644 --- a/src/StyleLexers/EditLexer.h +++ b/src/StyleLexers/EditLexer.h @@ -33,7 +33,7 @@ typedef struct _editstyle typedef struct _keywordlist { - char *pszKeyWords[KEYWORDSET_MAX + 1]; + char* pszKeyWords[KEYWORDSET_MAX + 1]; } KEYWORDLIST, *PKEYWORDLIST;