Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| scripting:examples:code-completion [2018/06/18 00:38] – [Usage of CompletionSet and CompletionItem] admin | scripting:examples:code-completion [2018/06/18 00:47] (current) – [Usage of CompletionSet and CompletionItem] admin | ||
|---|---|---|---|
| Line 54: | Line 54: | ||
| if ( ActiveDocument.Syntax.IsInheritedFrom(" | if ( ActiveDocument.Syntax.IsInheritedFrom(" | ||
| // simplest, just pass a list of strings | // simplest, just pass a list of strings | ||
| - | var aSuggestions = [" | + | var aSuggestions = [" |
| this.ShowCompletionList(selection, | this.ShowCompletionList(selection, | ||
| return true; // event is handled | return true; // event is handled | ||
| Line 90: | Line 90: | ||
| CompletionItem(" | CompletionItem(" | ||
| ]); | ]); | ||
| + | |||
| // or | // or | ||
| var completion_set2 = CompletionSet([" | var completion_set2 = CompletionSet([" | ||
| </ | </ | ||
| + | |||
| <note important> | <note important> | ||
| + | |||
| If you need more customization of your item displayed in CompletionList, | If you need more customization of your item displayed in CompletionList, | ||
| <code javascript> | <code javascript> | ||
| var item5 = CompletionItem(" | var item5 = CompletionItem(" | ||
| + | // custom insetion pattern, with code template syntax. | ||
| + | // %CurrentWord% - inserted text | ||
| item5.Pattern = " | item5.Pattern = " | ||
| + | // custom description tooltip, shown when user scrolls over items and stops on one of them | ||
| item5.onDescription = function () { return this.Text + "() ..."; }; | item5.onDescription = function () { return this.Text + "() ..."; }; | ||
| + | |||
| + | function onExpand(view, | ||
| + | ActiveDocument.ReplaceText(selection, | ||
| + | } | ||
| var item6 = CompletionItem(" | var item6 = CompletionItem(" | ||
| + | // adding of custom handler, which is called when item is selected and inserted | ||
| + | // default, inserts item Text property | ||
| item6.onExpand = onExpand; | item6.onExpand = onExpand; | ||
| + | // add small arrow icon on the right of the item, indicating that items expands | ||
| item6.SubMenu = true; | item6.SubMenu = true; | ||
| var aSuggestions = [ | var aSuggestions = [ | ||
| + | // add completion items with text and style, from which color/ | ||
| CompletionItem(" | CompletionItem(" | ||
| CompletionItem(" | CompletionItem(" | ||
| + | |||
| + | // use default style for item display | ||
| CompletionItem(" | CompletionItem(" | ||
| + | |||
| + | // define an item witthout style, but with explicit image, subimage (public/ | ||
| + | // description and selection call-back | ||
| CompletionItem(" | CompletionItem(" | ||
| item5, | item5, | ||
| item6]; | item6]; | ||
| </ | </ | ||
| - | |||
| - | |||