From 352a188c2af3949713c45cc5449bfaa1973a7043 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Sun, 4 Aug 2024 08:47:22 +0800 Subject: [PATCH] Add option to only use words in current document for auto-completion, discussion #798. --- locale/de/Notepad4.rc | 4 ++-- locale/fr/Notepad4.rc | 4 ++-- locale/it/Notepad4.rc | 4 ++-- locale/ja/Notepad4.rc | 4 ++-- locale/ko/Notepad4.rc | 4 ++-- locale/pt-BR/Notepad4.rc | 4 ++-- locale/zh-Hans/Notepad4.rc | 4 ++-- locale/zh-Hant/Notepad4.rc | 4 ++-- src/Dialogs.cpp | 12 ++++++------ src/Edit.h | 3 ++- src/EditAutoC.cpp | 2 +- src/Notepad4.cpp | 8 +++++--- src/Notepad4.rc | 4 ++-- src/resource.h | 4 ++-- wiki | 2 +- 15 files changed, 35 insertions(+), 32 deletions(-) diff --git a/locale/de/Notepad4.rc b/locale/de/Notepad4.rc index 65942a91b3..9096a35c2e 100644 --- a/locale/de/Notepad4.rc +++ b/locale/de/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "Scanning words in current document for",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "Auto completion is case insensitive.",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "Auto complete word inside:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "Comment",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/fr/Notepad4.rc b/locale/fr/Notepad4.rc index def2ad187d..782ca85f48 100644 --- a/locale/fr/Notepad4.rc +++ b/locale/fr/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "Scanner les mots dans le document pour",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "Déclencher l'auto-complémention seulement pour le mode IME anglais.",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "L'auto-completion est insensible à la casse.",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "Déclencher l'auto-complémention seulement pour le mode IME anglais.",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "Auto complete word inside:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "Comment",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/it/Notepad4.rc b/locale/it/Notepad4.rc index 8d95832f3a..45da1deed4 100644 --- a/locale/it/Notepad4.rc +++ b/locale/it/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "Scansione delle parole nel documento ogni:",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "Attiva il completamento solo in modalità IME inglese.",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "Il completamento non fa distinzione tra maiuscole e minuscole.",IDC_AUTOC_CASE_INSENSITIVE,14,92,200,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "Attiva il completamento solo in modalità IME inglese.",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,200,10,WS_TABSTOP GROUPBOX "Autocompleta parole in:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "Commenti",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/ja/Notepad4.rc b/locale/ja/Notepad4.rc index 8f03e593d8..be5fcaf64c 100644 --- a/locale/ja/Notepad4.rc +++ b/locale/ja/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "以下の時間だけ現在の文書中の単語を拾う(&S)",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "IMEが英数の場合にだけ自動補完を行う",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "自動補完で大・小文字を無視",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "IMEが英数の場合にだけ自動補完を行う",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "以下の中の単語を自動補完:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "コメント",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/ko/Notepad4.rc b/locale/ko/Notepad4.rc index a5b5fba0d4..4d88e3f12d 100644 --- a/locale/ko/Notepad4.rc +++ b/locale/ko/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "현재 문서의 단어를 검색",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "영어 IME 모드에서만 자동 완성 작동",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "자동 완성은 대소문자를 구분하지 않음",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "영어 IME 모드에서만 자동 완성 작동",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "내부 단어 자동 완성:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "주석",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/pt-BR/Notepad4.rc b/locale/pt-BR/Notepad4.rc index f093aa8aa0..c9a0c08629 100644 --- a/locale/pt-BR/Notepad4.rc +++ b/locale/pt-BR/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "Scanning words in current document for",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "Auto completion is case insensitive.",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "Auto complete word inside:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "Comment",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/zh-Hans/Notepad4.rc b/locale/zh-Hans/Notepad4.rc index 1821a4524b..d36124054c 100644 --- a/locale/zh-Hans/Notepad4.rc +++ b/locale/zh-Hans/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "在以下时间内扫描当前文档中的单词",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "仅在英文输入法模式下触发自动完成",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "自动完成忽略大小写",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "仅使用当前文档中的单词",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "仅在英文输入法模式下触发自动完成",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "在以下内容中启用单词自动完成:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "注释",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/locale/zh-Hant/Notepad4.rc b/locale/zh-Hant/Notepad4.rc index 3d3396e4c2..b87836558d 100644 --- a/locale/zh-Hant/Notepad4.rc +++ b/locale/zh-Hant/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "在以下時間內掃描目前文中的單詞",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "只在英文輸入法模式下觸發自動完成",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "自動完成忽略大小寫",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "僅使用當前文檔中的單詞",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "只在英文輸入法模式下觸發自動完成",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "在以下內容中啟用單詞自動完成:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "注释",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/src/Dialogs.cpp b/src/Dialogs.cpp index 1f8157b9cc..4dcc3af60e 100644 --- a/src/Dialogs.cpp +++ b/src/Dialogs.cpp @@ -2284,11 +2284,11 @@ static INT_PTR CALLBACK AutoCompletionSettingsDlgProc(HWND hwnd, UINT umsg, WPAR if (autoCompletionConfig.bScanWordsInDocument) { CheckDlgButton(hwnd, IDC_AUTOC_SCAN_DOCUMENT_WORDS, BST_CHECKED); } - if (autoCompletionConfig.bEnglistIMEModeOnly) { - CheckDlgButton(hwnd, IDC_AUTOC_ENGLISH_IME_ONLY, BST_CHECKED); + if (autoCompletionConfig.bOnlyWordsInDocument) { + CheckDlgButton(hwnd, IDC_AUTOC_ONLY_DOCUMENT_WORDS, BST_CHECKED); } - if (autoCompletionConfig.bIgnoreCase) { - CheckDlgButton(hwnd, IDC_AUTOC_CASE_INSENSITIVE, BST_CHECKED); + if (autoCompletionConfig.bEnglishIMEModeOnly) { + CheckDlgButton(hwnd, IDC_AUTOC_ENGLISH_IME_ONLY, BST_CHECKED); } SetDlgItemInt(hwnd, IDC_AUTOC_VISIBLE_ITEM_COUNT, autoCompletionConfig.iVisibleItemCount, FALSE); @@ -2386,8 +2386,8 @@ static INT_PTR CALLBACK AutoCompletionSettingsDlgProc(HWND hwnd, UINT umsg, WPAR autoCompletionConfig.bCompleteWord = IsButtonChecked(hwnd, IDC_AUTO_COMPLETE_WORD); autoCompletionConfig.bScanWordsInDocument = IsButtonChecked(hwnd, IDC_AUTOC_SCAN_DOCUMENT_WORDS); - autoCompletionConfig.bEnglistIMEModeOnly = IsButtonChecked(hwnd, IDC_AUTOC_ENGLISH_IME_ONLY); - autoCompletionConfig.bIgnoreCase = IsButtonChecked(hwnd, IDC_AUTOC_CASE_INSENSITIVE); + autoCompletionConfig.bOnlyWordsInDocument = IsButtonChecked(hwnd, IDC_AUTOC_ONLY_DOCUMENT_WORDS); + autoCompletionConfig.bEnglishIMEModeOnly = IsButtonChecked(hwnd, IDC_AUTOC_ENGLISH_IME_ONLY); int mask = GetDlgItemInt(hwnd, IDC_AUTOC_VISIBLE_ITEM_COUNT, nullptr, FALSE); autoCompletionConfig.iVisibleItemCount = max(mask, MIN_AUTO_COMPLETION_VISIBLE_ITEM_COUNT); diff --git a/src/Edit.h b/src/Edit.h index 7f8621b01d..9b2b2d4ee2 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -328,7 +328,8 @@ struct EditAutoCompletionConfig { int fCompleteScope; int fScanWordScope; UINT dwScanWordsTimeout; - bool bEnglistIMEModeOnly; + bool bOnlyWordsInDocument; + bool bEnglishIMEModeOnly; bool bIgnoreCase; bool bLaTeXInputMethod; UINT iVisibleItemCount; diff --git a/src/EditAutoC.cpp b/src/EditAutoC.cpp index 11e9699e4c..7f394a577e 100644 --- a/src/EditAutoC.cpp +++ b/src/EditAutoC.cpp @@ -1617,7 +1617,7 @@ static bool EditCompleteWordCore(int iCondition, bool autoInsert) noexcept { watch.Start(); #endif - bool bIgnoreLexer = (pRoot[0] >= '0' && pRoot[0] <= '9'); // number + bool bIgnoreLexer = autoCompletionConfig.bOnlyWordsInDocument || (pRoot[0] >= '0' && pRoot[0] <= '9'); // number const bool bIgnoreCase = bIgnoreLexer || autoCompletionConfig.bIgnoreCase; WordList pWList; pWList.Init(pRoot, iRootLen, bIgnoreCase); diff --git a/src/Notepad4.cpp b/src/Notepad4.cpp index 3670b4f2fa..a6cd2282d6 100644 --- a/src/Notepad4.cpp +++ b/src/Notepad4.cpp @@ -4993,7 +4993,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) { // auto complete word if (!autoCompletionConfig.bCompleteWord // ignore IME input - || (scn->characterSource != SC_CHARACTERSOURCE_DIRECT_INPUT && (ch >= 0x80 || autoCompletionConfig.bEnglistIMEModeOnly)) + || (scn->characterSource != SC_CHARACTERSOURCE_DIRECT_INPUT && (ch >= 0x80 || autoCompletionConfig.bEnglishIMEModeOnly)) || !IsAutoCompletionWordCharacter(ch) ) { return 0; @@ -5424,7 +5424,8 @@ void LoadSettings() noexcept { autoCompletionConfig.fScanWordScope = iValue >> 4; iValue = section.GetInt(L"AutoCScanWordsTimeout", AUTOC_SCAN_WORDS_DEFAULT_TIMEOUT); autoCompletionConfig.dwScanWordsTimeout = max(iValue, AUTOC_SCAN_WORDS_MIN_TIMEOUT); - autoCompletionConfig.bEnglistIMEModeOnly = section.GetBool(L"AutoCEnglishIMEModeOnly", false); + autoCompletionConfig.bOnlyWordsInDocument = section.GetBool(L"AutoCOnlyWordsInDocument", false); + autoCompletionConfig.bEnglishIMEModeOnly = section.GetBool(L"AutoCEnglishIMEModeOnly", false); autoCompletionConfig.bIgnoreCase = section.GetBool(L"AutoCIgnoreCase", false); autoCompletionConfig.bLaTeXInputMethod = section.GetBool(L"LaTeXInputMethod", false); iValue = section.GetInt(L"AutoCVisibleItemCount", 16); @@ -5773,7 +5774,8 @@ void SaveSettings(bool bSaveSettingsNow) noexcept { iValue = autoCompletionConfig.fCompleteScope | (autoCompletionConfig.fScanWordScope << 4); section.SetIntEx(L"AutoCompleteScope", iValue, AutoCompleteScope_Default); section.SetIntEx(L"AutoCScanWordsTimeout", autoCompletionConfig.dwScanWordsTimeout, AUTOC_SCAN_WORDS_DEFAULT_TIMEOUT); - section.SetBoolEx(L"AutoCEnglishIMEModeOnly", autoCompletionConfig.bEnglistIMEModeOnly, false); + section.SetBoolEx(L"AutoCOnlyWordsInDocument", autoCompletionConfig.bOnlyWordsInDocument, false); + section.SetBoolEx(L"AutoCEnglishIMEModeOnly", autoCompletionConfig.bEnglishIMEModeOnly, false); section.SetBoolEx(L"AutoCIgnoreCase", autoCompletionConfig.bIgnoreCase, false); section.SetBoolEx(L"LaTeXInputMethod", autoCompletionConfig.bLaTeXInputMethod, false); section.SetIntEx(L"AutoCVisibleItemCount", autoCompletionConfig.iVisibleItemCount, 16); diff --git a/src/Notepad4.rc b/src/Notepad4.rc index e74bec7e4f..e59d98d11e 100644 --- a/src/Notepad4.rc +++ b/src/Notepad4.rc @@ -1620,8 +1620,8 @@ BEGIN EDITTEXT IDC_AUTOC_MIN_NUMBER_LENGTH,166,48,50,12,ES_NUMBER | WS_TABSTOP AUTOCHECKBOX "Scanning words in current document for",IDC_AUTOC_SCAN_DOCUMENT_WORDS,14,68,150,10,WS_TABSTOP EDITTEXT IDC_AUTOC_SCAN_WORDS_TIMEOUT,166,64,50,12,WS_TABSTOP - AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,80,180,10,WS_TABSTOP - AUTOCHECKBOX "Auto completion is case insensitive.",IDC_AUTOC_CASE_INSENSITIVE,14,92,180,10,WS_TABSTOP + AUTOCHECKBOX "Only use words in current document.",IDC_AUTOC_ONLY_DOCUMENT_WORDS,14,80,180,10,WS_TABSTOP + AUTOCHECKBOX "Only trigger auto completion in English IME mode.",IDC_AUTOC_ENGLISH_IME_ONLY,14,92,180,10,WS_TABSTOP GROUPBOX "Auto complete word inside:",IDC_STATIC,7,111,218,26 AUTOCHECKBOX "Comment",IDC_AUTO_COMPLETE_INSIDE_COMMONT,14,123,65,10,WS_TABSTOP diff --git a/src/resource.h b/src/resource.h index de961a5767..fb956db443 100644 --- a/src/resource.h +++ b/src/resource.h @@ -319,8 +319,8 @@ #define IDC_AUTOC_MIN_WORD_LENGTH 152 #define IDC_AUTOC_MIN_NUMBER_LENGTH 153 #define IDC_AUTOC_SCAN_DOCUMENT_WORDS 154 -#define IDC_AUTOC_ENGLISH_IME_ONLY 155 -#define IDC_AUTOC_CASE_INSENSITIVE 156 +#define IDC_AUTOC_ONLY_DOCUMENT_WORDS 155 +#define IDC_AUTOC_ENGLISH_IME_ONLY 156 #define IDC_AUTOC_SCAN_WORDS_TIMEOUT 157 #define IDC_AUTO_COMPLETE_INSIDE_COMMONT 180 #define IDC_AUTO_COMPLETE_INSIDE_STRING 181 diff --git a/wiki b/wiki index 8a4446537a..a8acee4688 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 8a4446537a415e5b5f77e9cadf83775a920e3762 +Subproject commit a8acee46887da7968ce43847cbb568aec49018be