Auto-completion currently use both ENTER and TAB to insert the selected item,

in some circumstance people have to ENTER twice to have 1 newline feed.

In this commit, 2 options (ENTER & TAB) are given in Auto-completion settings, so users can choose one of these 2 keystrokes (or both, or none). By default ENTER is disabled and TAB is enabled.
If auto-completion is disabled and completion is triggered manually, then the settings of ENTER & TAB won't be considered, both ENTER & TAB will be able to insert the selection.

Fix #4799, fix #4631, fix #8389, fix #10915, close #11016
This commit is contained in:
Don Ho 2022-01-10 01:05:46 +01:00
parent ed40f11515
commit 68d339d224
9 changed files with 117 additions and 39 deletions

View File

@ -3,7 +3,7 @@
The comments are here for explanation, it's not necessary to translate them.
-->
<NotepadPlus>
<Native-Langue name="English" filename="english.xml" version="8.2">
<Native-Langue name="English" filename="english.xml" version="8.2.1">
<Menu>
<Main>
<!-- Main Menu Entries -->
@ -1042,6 +1042,9 @@ You can define several column markers by using white space to separate the diffe
<Item id="6809" name="Function completion"/>
<Item id="6810" name="Word completion"/>
<Item id="6816" name="Function and word completion"/>
<Item id="6869" name="Insert Selection"/>
<Item id="6870" name="TAB"/> <!-- TAB key on the keyboard, it's not necessary to translate it normally -->
<Item id="6871" name="ENTER"/> <!-- ENTER key on the keyboard, it's not necessary to translate it normally -->
<Item id="6824" name="Ignore numbers"/>
<Item id="6811" name="From"/>
<Item id="6813" name="th character"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<NotepadPlus>
<Native-Langue name="français" filename="french.xml" version="8.1.5">
<Native-Langue name="français" filename="french.xml" version="8.2.1">
<Menu>
<Main>
<!-- Main Menu Entries -->
@ -862,6 +862,7 @@
<Item id="7122" name="Texte plus sombre"/>
<Item id="7123" name="Texte désactivé"/>
<Item id="7124" name="Bord"/>
<Item id="7125" name="Lien"/>
<Item id="7130" name="Réinitialiser"/>
</DarkMode>
@ -1016,6 +1017,9 @@ Vous pouvez définir plusieurs marqueurs de colonne en utilisant un espace pour
<Item id="6813" name="ème caractère"/>
<Item id="6814" name="Valeur possible : de 1 à 9"/>
<Item id="6815" name="Paramètres affichés durant la saisie"/>
<Item id="6869" name="Insérer la sélection"/>
<Item id="6870" name="TAB"/>
<Item id="6871" name="ENTER"/>
<Item id="6824" name="Ignorer les nombres"/>
<Item id="6851" name="Insertion automatique"/>
<Item id="6857" name="Balise fermante (html/xml)"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<NotepadPlus>
<Native-Langue name="台灣繁體" filename="taiwaneseMandarin.xml" version="8.1.5">
<Native-Langue name="台灣繁體" filename="taiwaneseMandarin.xml" version="8.2.1">
<Menu>
<Main>
<!-- Main Menu Entries -->
@ -876,6 +876,7 @@
<Item id="7122" name="色調較暗文字"/>
<Item id="7123" name="暫停使用文字"/>
<Item id="7124" name="邊線"/>
<Item id="7125" name="鏈接"/>
<Item id="7130" name="重設原始值"/>
</DarkMode>
@ -1028,6 +1029,9 @@
<Item id="6809" name="函式"/>
<Item id="6810" name="字詞"/>
<Item id="6816" name="函式與字詞"/>
<Item id="6869" name="插入選擇的字詞或函式名"/>
<Item id="6870" name="TAB"/>
<Item id="6871" name="ENTER"/>
<Item id="6824" name="忽略數字"/>
<Item id="6811" name="從第"/>
<Item id="6813" name="個字元開始"/>

View File

@ -904,7 +904,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (_pFuncList && (!_pFuncList->isClosed()) && _pFuncList->isVisible())
_pFuncList->markEntry();
AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub;
AutoCompletion * autoC = isFromPrimary ? &_autoCompleteMain : &_autoCompleteSub;
autoC->update(0);
break;
@ -1048,11 +1048,35 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_CALLTIPCLICK:
{
AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub;
AutoCompletion * autoC = isFromPrimary ? &_autoCompleteMain : &_autoCompleteSub;
autoC->callTipClick(notification->position);
break;
}
case SCN_AUTOCSELECTION:
{
const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
// if autocompletion is disabled and it is triggered manually, then both ENTER & TAB will insert the selection
if (nppGui._autocStatus == NppGUI::AutocStatus::autoc_none)
{
break;
}
if (notification->listCompletionMethod == SC_AC_NEWLINE && !nppGui._autocInsertSelectedUseENTER)
{
notifyView->execute(SCI_AUTOCCANCEL);
notifyView->execute(SCI_NEWLINE);
}
if (notification->listCompletionMethod == SC_AC_TAB && !nppGui._autocInsertSelectedUseTAB)
{
notifyView->execute(SCI_AUTOCCANCEL);
notifyView->execute(SCI_TAB);
}
break;
}
case RBN_HEIGHTCHANGE:
{
SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);

View File

@ -5169,6 +5169,15 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if (optName)
_nppGUI._autocIgnoreNumbers = (lstrcmp(optName, TEXT("yes")) == 0);
optName = element->Attribute(TEXT("insertSelectedItemUseENTER"));
if (optName)
_nppGUI._autocInsertSelectedUseENTER = (lstrcmp(optName, TEXT("yes")) == 0);
optName = element->Attribute(TEXT("insertSelectedItemUseTAB"));
if (optName)
_nppGUI._autocInsertSelectedUseTAB = (lstrcmp(optName, TEXT("yes")) == 0);
optName = element->Attribute(TEXT("funcParams"));
if (optName)
_nppGUI._funcParams = (lstrcmp(optName, TEXT("yes")) == 0);
@ -6346,6 +6355,12 @@ void NppParameters::createXmlTreeFromGUIParams()
const TCHAR * pStr = _nppGUI._autocIgnoreNumbers ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(TEXT("autoCIgnoreNumbers"), pStr);
pStr = _nppGUI._autocInsertSelectedUseENTER ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(TEXT("insertSelectedItemUseENTER"), pStr);
pStr = _nppGUI._autocInsertSelectedUseTAB ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(TEXT("insertSelectedItemUseTAB"), pStr);
pStr = _nppGUI._funcParams ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(TEXT("funcParams"), pStr);
}

View File

@ -805,6 +805,8 @@ struct NppGUI final
AutocStatus _autocStatus = autoc_both;
size_t _autocFromLen = 1;
bool _autocIgnoreNumbers = true;
bool _autocInsertSelectedUseENTER = false;
bool _autocInsertSelectedUseTAB = true;
bool _funcParams = true;
MatchedPairConf _matchedPairConf;

View File

@ -344,37 +344,39 @@ IDD_PREFERENCE_SUB_AUTOCOMPLETION DIALOGEX 0, 0, 455, 185
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,15,100,10
GROUPBOX "Auto-Completion",IDD_AUTOC_GRPSTATIC,131,4,289,84,BS_CENTER
CONTROL "Enable auto-completion on each input",IDD_AUTOC_ENABLECHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,136,15,150,10
CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,163,27,145,10
CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,163,41,145,10
CONTROL "Function and word completion",IDD_AUTOC_BOTHRADIO,"Button",BS_AUTORADIOBUTTON,163,55,145,10
RTEXT "From",IDD_AUTOC_STATIC_FROM,293,15,47,8
CTEXT "1",IDD_AUTOC_STATIC_N,344,15,8,8,WS_TABSTOP
LTEXT "th character",IDD_AUTOC_STATIC_CHAR,358,15,57,8
LTEXT "Valid value : 1 - 9",IDD_AUTOC_STATIC_NOTE,323,25,93,8
CONTROL "Ignore numbers",IDD_AUTOC_IGNORENUMBERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,323,55,80,10
CONTROL "Function parameters hint on input",IDD_FUNC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,136,72,160,10
GROUPBOX "Auto-Insert",IDD_AUTOCINSERT_GRPSTATIC,131,94,289,84,BS_CENTER
CONTROL " (",IDD_AUTOCPARENTHESES_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,115,24,10
CONTROL " [",IDD_AUTOCBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,133,24,10
CONTROL " {",IDD_AUTOCCURLYBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,152,24,10
CONTROL " """,IDD_AUTOC_DOUBLEQUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,190,116,24,10
CONTROL " '",IDD_AUTOC_QUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,190,133,24,10
CONTROL " html/xml close tag",IDD_AUTOCTAG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,190,152,76,10
RTEXT "Open",IDC_MACHEDPAIROPEN_STATIC,352,103,25,8
LTEXT "Close",IDC_MACHEDPAIRCLOSE_STATIC,390,103,25,8
RTEXT "Matched pair 1:",IDC_MACHEDPAIR_STATIC1,293,117,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT1,365,115,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT1,393,115,14,14
RTEXT "Matched pair 2:",IDC_MACHEDPAIR_STATIC2,293,137,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT2,365,135,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT2,393,135,14,14
RTEXT "Matched pair 3:",IDC_MACHEDPAIR_STATIC3,293,157,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT3,365,155,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT3,393,155,14,14
CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,347,15,100,10
GROUPBOX "Auto-Completion",IDD_AUTOC_GRPSTATIC,33,4,289,90,BS_CENTER
CONTROL "Enable auto-completion on each input",IDD_AUTOC_ENABLECHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,38,15,150,10
CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,65,27,145,10
CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,65,41,145,10
CONTROL "Function and word completion",IDD_AUTOC_BOTHRADIO,"Button",BS_AUTORADIOBUTTON,65,55,145,10
RTEXT "From",IDD_AUTOC_STATIC_FROM,195,12,47,8
CTEXT "1",IDD_AUTOC_STATIC_N,246,12,8,8,WS_TABSTOP
LTEXT "th character",IDD_AUTOC_STATIC_CHAR,260,12,57,8
LTEXT "Valid value : 1 - 9",IDD_AUTOC_STATIC_NOTE,225,22,93,8
GROUPBOX "Insert Selection",IDD_AUTOC_USEKEY_GRP_STATIC,218,36,96,38,BS_CENTER
CONTROL "TAB",IDD_AUTOC_USETAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,240,49,54,10
CONTROL "ENTER",IDD_AUTOC_USEENTER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,240,61,55,10
CONTROL "Ignore numbers",IDD_AUTOC_IGNORENUMBERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,219,79,80,10
CONTROL "Function parameters hint on input",IDD_FUNC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,38,79,160,10
GROUPBOX "Auto-Insert",IDD_AUTOCINSERT_GRPSTATIC,33,99,289,84,BS_CENTER
CONTROL " (",IDD_AUTOCPARENTHESES_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,48,120,24,10
CONTROL " [",IDD_AUTOCBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,48,138,24,10
CONTROL " {",IDD_AUTOCCURLYBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,48,157,24,10
CONTROL " """,IDD_AUTOC_DOUBLEQUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,92,121,24,10
CONTROL " '",IDD_AUTOC_QUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,92,138,24,10
CONTROL " html/xml close tag",IDD_AUTOCTAG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,92,157,76,10
RTEXT "Open",IDC_MACHEDPAIROPEN_STATIC,254,108,25,8
LTEXT "Close",IDC_MACHEDPAIRCLOSE_STATIC,292,108,25,8
RTEXT "Matched pair 1:",IDC_MACHEDPAIR_STATIC1,195,122,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT1,267,120,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT1,295,120,14,14
RTEXT "Matched pair 2:",IDC_MACHEDPAIR_STATIC2,195,142,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT2,267,140,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT2,295,140,14,14
RTEXT "Matched pair 3:",IDC_MACHEDPAIR_STATIC3,195,162,70,8
EDITTEXT IDC_MACHEDPAIROPEN_EDIT3,267,160,14,14
EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT3,295,160,14,14
END

View File

@ -3562,12 +3562,18 @@ INT_PTR CALLBACK AutoCompletionSubDlg::run_dlgProc(UINT message, WPARAM wParam,
if (nppGUI._autocStatus == nppGUI.autoc_word || nppGUI._autocStatus == nppGUI.autoc_both)
::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_SETCHECK, nppGUI._autocIgnoreNumbers ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDD_AUTOC_USEENTER, BM_SETCHECK, nppGUI._autocInsertSelectedUseENTER ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDD_AUTOC_USETAB, BM_SETCHECK, nppGUI._autocInsertSelectedUseTAB ? BST_CHECKED : BST_UNCHECKED, 0);
if (!isEnableAutoC)
{
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_BOTHRADIO), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_USEENTER), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_USETAB), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), FALSE);
@ -3738,6 +3744,9 @@ INT_PTR CALLBACK AutoCompletionSubDlg::run_dlgProc(UINT message, WPARAM wParam,
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_BOTHRADIO), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_USEKEY_GRP_STATIC), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_USEENTER), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_USETAB), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), isEnableAutoC);
@ -3771,15 +3780,27 @@ INT_PTR CALLBACK AutoCompletionSubDlg::run_dlgProc(UINT message, WPARAM wParam,
return TRUE;
}
case IDD_AUTOC_USEENTER:
{
nppGUI._autocInsertSelectedUseENTER = isCheckedOrNot(static_cast<int32_t>(wParam));
return TRUE;
}
case IDD_AUTOC_USETAB:
{
nppGUI._autocInsertSelectedUseTAB = isCheckedOrNot(static_cast<int32_t>(wParam));
return TRUE;
}
case IDD_AUTOC_IGNORENUMBERS:
{
nppGUI._autocIgnoreNumbers = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_GETCHECK, 0, 0));
nppGUI._autocIgnoreNumbers = isCheckedOrNot(static_cast<int32_t>(wParam));
return TRUE;
}
case IDD_FUNC_CHECK :
{
nppGUI._funcParams = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_FUNC_CHECK, BM_GETCHECK, 0, 0));
nppGUI._funcParams = isCheckedOrNot(static_cast<int32_t>(wParam));
return TRUE;
}
@ -3818,7 +3839,7 @@ INT_PTR CALLBACK AutoCompletionSubDlg::run_dlgProc(UINT message, WPARAM wParam,
case IDD_AUTOC_DOUBLEQUOTESCHECK :
case IDD_AUTOC_QUOTESCHECK :
{
bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
bool isChecked = isCheckedOrNot(static_cast<int32_t>(wParam));
const TCHAR *label;
if (wParam == IDD_AUTOCPARENTHESES_CHECK)
{

View File

@ -371,6 +371,9 @@
#define IDC_MACHEDPAIR_STATIC3 (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 16)
#define IDC_MACHEDPAIROPEN_EDIT3 (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 17)
#define IDC_MACHEDPAIRCLOSE_EDIT3 (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 18)
#define IDD_AUTOC_USEKEY_GRP_STATIC (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 19)
#define IDD_AUTOC_USETAB (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 20)
#define IDD_AUTOC_USEENTER (IDD_PREFERENCE_SUB_AUTOCOMPLETION + 21)
#define IDD_PREFERENCE_SUB_SEARCHING 6900 //(IDD_PREFERENCE_BOX + 900)
#define IDC_CHECK_STOPFILLINGFINDFIELD (IDD_PREFERENCE_SUB_SEARCHING + 1)