Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
scripting:examples:code-completion [2018/06/18 00:38] – [Usage of CompletionSet and CompletionItem] adminscripting:examples:code-completion [2018/06/18 00:47] (current) – [Usage of CompletionSet and CompletionItem] admin
Line 54: Line 54:
  if ( ActiveDocument.Syntax.IsInheritedFrom("js") ) {  if ( ActiveDocument.Syntax.IsInheritedFrom("js") ) {
                 // simplest, just pass a list of strings                 // simplest, just pass a list of strings
- var aSuggestions = ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10"];+ var aSuggestions = ["Item1", "Item2", "Item3", "Item4", "Item5"];
  this.ShowCompletionList(selection, aSuggestions, false);  this.ShowCompletionList(selection, aSuggestions, false);
  return true; // event is handled  return true; // event is handled
Line 90: Line 90:
 CompletionItem("Item3" CompletionItem("Item3"
 ]); ]);
 +
 // or // or
 var completion_set2 = CompletionSet(["Item1", "Item2", "Item3"]); var completion_set2 = CompletionSet(["Item1", "Item2", "Item3"]);
 </code> </code>
 +
 <note important>Do not mix strings and CompletionItems in the same set - it is not supported, and editor will use a type of first object</note> <note important>Do not mix strings and CompletionItems in the same set - it is not supported, and editor will use a type of first object</note>
 +
 If you need more customization of your item displayed in CompletionList, there are several options you can use when constructing explicit [[scripting:api:completion-item:start|CompletionItem]] and passing it to the list. If you need more customization of your item displayed in CompletionList, there are several options you can use when constructing explicit [[scripting:api:completion-item:start|CompletionItem]] and passing it to the list.
  
 <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>
- 
-