How to trigger snippet insertion programmatically?

SyntaxEditor for WPF Forum

Posted 6 years ago by Louis-Philippe Perras
Version: 17.2.0664
Avatar

I tried to trigger the insertion of a code snippet programmatically with the EditorDocument. I tried to call AppendText and InsertText with the shortcut of the snippet plus a tab in the string (\t"). It inserted the text of the shortcut with a tab after. I used the TextChangeTypes.InsertCodeSnippetTemplate but always the same behaviour.

 

I would really appreciate if you could point me to what call I should be doing to trigger the snipper insertion programmatically.

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The CodeSnippetProvider language service is what watches for a KeyDown event that has a plain old Tab and if it sees one, it calls its protected CheckForShortcut(view) method.  

If you make a class that inherited CodeSnippetProvider and added a public method you could call that would invoke CheckForShortcut(view), then you could register an instance of your class instead as the language service.  As long as you had snippet text with a zero-length selection right after it, I think that will trigger the expansion.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.