Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
scripting:examples:code-completion [2018/06/18 00:39] – [Subscribing on onCompletion event] adminscripting:examples:code-completion [2018/06/18 00:47] (current) – [Usage of CompletionSet and CompletionItem] admin
Line 101: Line 101:
 <code javascript> <code javascript>
 var item5 = CompletionItem("Item5"); var item5 = CompletionItem("Item5");
 +// custom insetion pattern, with code template syntax. 
 +// %CurrentWord% - inserted text
 item5.Pattern = "%CurrentWord%(%|%)"; item5.Pattern = "%CurrentWord%(%|%)";
 +// 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, selection) {
 + ActiveDocument.ReplaceText(selection, this.Text + "(...)");
 +}
  
 var item6 = CompletionItem("Item6"); var item6 = CompletionItem("Item6");
 +// 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/image/style of item shall be derived 
 CompletionItem("Item1", "js:methods"),  CompletionItem("Item1", "js:methods"), 
 CompletionItem("Item2", "variable"),  CompletionItem("Item2", "variable"), 
 +
 +// use default style for item display
 CompletionItem("Item3"),  CompletionItem("Item3"), 
 +
 +// define an item witthout style, but with explicit image, subimage (public/protected/private)
 +// description and selection call-back
 CompletionItem("Item4", null, 11, 1, "Item4 Description", onExpand),  CompletionItem("Item4", null, 11, 1, "Item4 Description", onExpand), 
 item5,  item5, 
 item6];  item6]; 
 </code> </code>