Unable to insert #region snippet

SyntaxEditor for WPF Forum

Posted 7 years ago by Erwin Liong
Version: 16.1.0635
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

Hi Actipro,

I am trying to include C# snippet into a Syntax Editor (#if and #region - found in C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Visual C#).

Steps to reproduce:

1. Copy pp_region.snippet into ..\WPF-Controls\v16.1.0634\SampleBrowser\ProductSamples\SyntaxEditorSamples\Languages\Snippets\CSharp

2. Include as Embedded Resource in CSharp Language Definition

3. Build and launch SDI Editor

4. Edit | Intelliprompt | Insert Snippet. Observe that #region is listed as available snippet and selecting it would insert the relevant #region snippet content.

5. On empty line, type #region. Then, press 'TAB'. Observe that the #region (shortcut for #region) does not activate the insertion of the code snippet.

 

Have I missed some crucial step?

Thank you.

 

Cheers,

Erwin Liong

Comments (7)

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

Hi Erwin,

Thanks for letting us know about this.  The CSharpCodeSnippetProvider is currently using the default logic of getting the word at the caret when checking for a snippet shortcut.  So it's checking "region" instead of "#region".  We've updated it for the next version (probably after the new year) to include a "#" character too if that is before the word.  That fixes this.


Actipro Software Support

Posted 7 years ago by Erwin Liong
Avatar

Thank you for the quick turnaround. 

 

Cheers, 

Erwin Liong 

Posted 7 years ago by Erwin Liong
Avatar

Hi Actipro, 

 

When is the next release coming?

 

Regards, 

Erwin Liong 

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

Hello,

We are working on wrapping up 2017.1 and ran into several things while testing that took longer than expected.  It should be relatively soon though.  We will probably publish one final 2016.1 maintenance release right before 2017.1 comes out.


Actipro Software Support

Posted 7 years ago by Erwin Liong
Avatar

Hi Actipro,

I tried the build 636 and found that the #<shortcut> does not work. Is the fix for #if or #region available in this build?

 

Steps to reproduce:

  • Open .\Actipro Software\WPF-Controls\v16.1.0636\SampleBrowser\ProductSamples\SyntaxEditorSamples\Languages\Snippets\Javascript\JavascriptFor.snippet
  • Modify the shortcut key to be <Shortcut>#fff</Shortcut>
  • Build and Run Intelliprompt Quick Start | Code Snippet.
  • Click Insert Snippet button and select "for": This works and insert the code snippet for "for"
  • On empty line, type "#fff" and press 'Tab'.
  • Observe: The 'for' snippet does not take place.
  • Expected: 'for' snippet is added into the editor.
Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Yes the fix is in that build but you had only originally mentioned the C# language.  As such, we only modified CSharpCodeSnippetProvider.  The reason it's not in the core CodeSnippetProvider base class is that the # symbol isn't used in every language.  And thus if we included that, it could cause some unintended consequences for certain languages. 

It's easily solved though.  If you make a JavaScriptCodeSnippetProvider, simply add this to that class:

protected override TextSnapshotRange GetPossibleShortcutSnapshotRange(TextSnapshotOffset snapshotOffset) {
	var snapshotRange = TextSnapshotRange.Deleted;

	// Get the word right before the offset, and if the word ends at the offset, return it
	var textRange = snapshotOffset.Snapshot.GetWordTextRange(snapshotOffset.Offset - 1);
	if ((!textRange.IsZeroLength) && (textRange.EndOffset == snapshotOffset.Offset)) {
		snapshotRange = new TextSnapshotRange(snapshotOffset.Snapshot, textRange);

		// If the word has a '#' preceding it, include that in the range as well
		if ((snapshotRange.StartOffset > 0) && (snapshotRange.Snapshot[snapshotRange.StartOffset - 1] == '#'))
			snapshotRange = new TextSnapshotRange(snapshotRange.Snapshot, snapshotRange.StartOffset - 1, snapshotRange.EndOffset);
	}

	return snapshotRange;
}


Actipro Software Support

Posted 7 years ago by Erwin Liong
Avatar

Thank you for solution. 

 

Regards, 

Erwin Liong 

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.