madskristensen / AddAnyFile

A Visual Studio extension
Apache License 2.0
262 stars 119 forks source link

Custom templates dollar ($) symbol #133

Open jasontaylordev opened 2 years ago

jasontaylordev commented 2 years ago

When creating a custom template I don't understand how the dollar ($) symbol is used. I thought perhaps it was to specify the cursor position or preserve whitespace - but couldn't confirm that behaviour.

Please can someone advise? Thanks. 😀

FXZFun commented 6 months ago

@jasontaylordev You are correct, the dollar symbol ($) is used to mark where the cursor is placed when the file is opened after creation. The position of the first $ is returned from the function and used after the file is opened in the editor.

https://github.com/madskristensen/AddAnyFile/blob/8a8443fbf0f5953cf83849a489350b0e42ca2e86/src/AddAnyFilePackage.cs#L198

If you're wondering how to keep a dollar sign in your template, such as when you have an interpolated string in your template, you just need to double them up so you have two dollar signs in the template, or include a single dollar sign to specify the cursor position somewhere before the interpolated string.