+ add: option to merge Lexer's KeyWord List into AutoCompletion List

This commit is contained in:
Rainer Kottenhoff 2018-09-09 14:44:05 +02:00
parent 30e815c97f
commit acb6b1e2a8
13 changed files with 143 additions and 59 deletions

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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);

View File

@ -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);

View File

@ -33,7 +33,7 @@ typedef struct _editstyle
typedef struct _keywordlist
{
char *pszKeyWords[KEYWORDSET_MAX + 1];
char* pszKeyWords[KEYWORDSET_MAX + 1];
} KEYWORDLIST, *PKEYWORDLIST;