From afc7afe13b6eb49984e1c9c66eef3cebc1392a09 Mon Sep 17 00:00:00 2001
From: nyamatongwe Last edited 29/May/2004 NH Last edited 9/March/2005 NH There is an overview of the internal design of
Scintilla. Autocompletion displays a list box showing likely identifiers based upon the users typing.
+ Autocompletion displays a list box showing likely identifiers based upon the user's typing.
The user chooses the currently selected item by pressing the tab character or another character
that is a member of the fillup character set defined with When the user makes a selection from the list the container is sent a To make use of autocompletion you must monitor each character added to the document. See
Scintilla Documentation
-
@@ -2876,7 +2876,7 @@ struct TextToFind {
Autocompletion
- SCI_AUTOCSETFILLUPS.
Autocompletion is triggered by your application. For example, in C if you detect that the user
@@ -2886,6 +2886,12 @@ struct TextToFind {
the choice to a reasonable list. As yet another alternative, you could define a key code to
activate the list. notification message. On return from the notification Scintilla will insert
+ the selected text unless the autocompletion list has been cancelled, for example by the container sending
+ .SciTEBase::CharAdded() in SciTEBase.cxx for an example of autocompletion.notification message.
SCN_AUTOCSELECTION.
BEWARE: if you have set fillup characters or stop characters, these will still be active
with the user list, and may result in items being selected or the user list cancelled due to
@@ -4315,7 +4322,7 @@ struct SCNotification {
int ch; // SCN_CHARADDED, SCN_KEY
int modifiers; // SCN_KEY, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
int modificationType; // SCN_MODIFIED
- const char *text; // SCN_MODIFIED
+ const char *text; // SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
int length; // SCN_MODIFIED
int linesAdded; // SCN_MODIFIED
int message; // SCN_MACRORECORD
@@ -4325,7 +4332,7 @@ struct SCNotification {
int foldLevelNow; // SCN_MODIFIED
int foldLevelPrev; // SCN_MODIFIED
int margin; // SCN_MARGINCLICK
- int listType; // SCN_USERLISTSELECTION
+ int listType; // SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
int x; // SCN_DWELLSTART, SCN_DWELLEND
int y; // SCN_DWELLSTART, SCN_DWELLEND
};
@@ -4354,6 +4361,7 @@ struct SCNotification {
+
The following SCI_* messages are associated with these notifications:
position field is set to 1 if the click is in an up arrow,
2 if in a down arrow, and 0 if elsewhere.
+ SCN_AUTOCSELECTION
+ The user has selected an item in an autocompletion list. The
+ notification is sent before the selection is inserted. Automatic insertion can be cancelled by sending a
+ message
+ before returning from the notification. The SCNotification fields used are:
| Field | + +Usage | +
|---|---|
lParam |
+
+ The start position of the word being completed. | +
text |
+
+ The text of the selection. | +
The following messages are currently supported to emulate existing Windows controls, but diff --git a/include/Scintilla.h b/include/Scintilla.h index d02ea54b8..cd1dbd77f 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -658,6 +658,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_HOTSPOTCLICK 2019 #define SCN_HOTSPOTDOUBLECLICK 2020 #define SCN_CALLTIPCLICK 2021 +#define SCN_AUTOCSELECTION 2022 //--Autogenerated -- end of section automatically generated from Scintilla.iface // These structures are defined to be exactly the same shape as the Win32 @@ -710,7 +711,7 @@ struct SCNotification { int ch; // SCN_CHARADDED, SCN_KEY int modifiers; // SCN_KEY int modificationType; // SCN_MODIFIED - const char *text; // SCN_MODIFIED + const char *text; // SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION int length; // SCN_MODIFIED int linesAdded; // SCN_MODIFIED int message; // SCN_MACRORECORD diff --git a/include/Scintilla.iface b/include/Scintilla.iface index bf4af856f..5436fced4 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2633,6 +2633,7 @@ evt void Zoom=2018(void) evt void HotSpotClick=2019(int modifiers, int position) evt void HotSpotDoubleClick=2020(int modifiers, int position) evt void CallTipClick=2021(int position) +evt void AutoCSelection=2022(string text) cat Deprecated diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index b4d14944f..65b1788bb 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -118,9 +118,10 @@ void AutoComplete::SetList(const char *list) { } } -void AutoComplete::Show() { - lb->Show(); - lb->Select(0); +void AutoComplete::Show(bool show) { + lb->Show(show); + if (show) + lb->Select(0); } void AutoComplete::Cancel() { diff --git a/src/AutoComplete.h b/src/AutoComplete.h index 981fb44c0..ee5a2de4c 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -57,7 +57,7 @@ public: /// The list string contains a sequence of words separated by the separator character void SetList(const char *list); - void Show(); + void Show(bool show); void Cancel(); /// Move the current list element by delta, scrolling appropriately diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 78c15f7d7..7735d35db 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -262,7 +262,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { } rcList.bottom = rcList.top + heightAlloced; ac.lb->SetPositionRelative(rcList, wMain); - ac.Show(); + ac.Show(true); if (lenEntered != 0) { AutoCompleteMoveToCurrentWord(); } @@ -312,25 +312,31 @@ void ScintillaBase::AutoCompleteCompleted() { selected[0] = '\0'; if (item != -1) { ac.lb->GetValue(item, selected, sizeof(selected)); + } else { + ac.Cancel(); + return; } - ac.Cancel(); - if (item == -1) + + ac.Show(false); + + listSelected = selected; + SCNotification scn; + scn.nmhdr.code = listType > 0 ? SCN_USERLISTSELECTION : SCN_AUTOCSELECTION; + scn.message = 0; + scn.wParam = listType; + scn.listType = listType; + Position firstPos = ac.posStart - ac.startLen; + scn.lParam = firstPos; + scn.text = listSelected.c_str(); + NotifyParent(scn); + + if (!ac.Active()) return; + ac.Cancel(); - if (listType > 0) { - userListSelected = selected; - SCNotification scn; - scn.nmhdr.code = SCN_USERLISTSELECTION; - scn.message = 0; - scn.wParam = listType; - scn.listType = listType; - scn.lParam = 0; - scn.text = userListSelected.c_str(); - NotifyParent(scn); + if (listType > 0) return; - } - Position firstPos = ac.posStart - ac.startLen; Position endPos = currentPos; if (ac.dropRestOfWord) endPos = pdoc->ExtendWordSelect(endPos, 1, true); diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index 6ea23ab5a..362231148 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -37,7 +37,7 @@ protected: CallTip ct; int listType; ///< 0 is an autocomplete list - SString userListSelected; ///< Receives listbox selected string + SString listSelected; ///< Receives listbox selected string #ifdef SCI_LEXER int lexLanguage; -- cgit v1.2.3