I'm implementing Code Snippets in my application. I've extended CodeSnippetProvider and overriden the GetPossibleShortcutSnapshotRange() method so that snippets won't be inserted within comments and literals. This works perfectly when typing a snippet key and then pressing Tab within the editor. However, when I open a code snippet selection session via code using editor.ActiveView.IntelliPrompt.RequestInsertSnippetSession(), select a snippet and enter it by pressing the Tab key, Enter Key or double-clicking the entry, the overriden GetPossibleShortcutSnapshotRange() is not executed so the snippet is inserted when it shouldn't be. Is there something additional I need to do to get the overriden GetPossibleShortcutSnapshotRange() to execute from programmatically opened code snippet selection session?
You can recreate this in the sample browser's Code Snippet sample. Add this class to folder \Actipro Software\WPF-Controls\v25.1.2\SampleBrowser\ProductSamples\SyntaxEditorSamples\QuickStart\IntelliPromptCodeSnippets as CodeSnippetProviderEx.cs. Then update MainControl.xaml.cs in the same folder and modify line 30 to instantiate CodeSnippetProviderEx() rather than CodeSnippetProvider().
using ActiproSoftware.Text;
using ActiproSoftware.Text.Lexing;
using ActiproSoftware.Windows.Controls.SyntaxEditor.IntelliPrompt.Implementation;
using System;
using System.Linq;
namespace ActiproSoftware.ProductSamples.SyntaxEditorSamples.QuickStart.IntelliPromptCodeSnippets {
internal class CodeSnippetProviderEx : CodeSnippetProvider {
private string[] TokenKeys = { "MultiLineCommentText", "SingleLineCommentText" };
protected override TextSnapshotRange GetPossibleShortcutSnapshotRange(TextSnapshotOffset snapshotOffset) {
TextSnapshotRange SnapshotRange = base.GetPossibleShortcutSnapshotRange(snapshotOffset);
if (SnapshotRange.Length > 0) {
ITextSnapshotReader reader = SnapshotRange.Snapshot.GetReader(SnapshotRange.StartOffset);
IToken token = reader.ReadToken();
if (TokenKeys.Contains(token.Key))
return TextSnapshotRange.Deleted;
}
return SnapshotRange;
}
}
}
Thanks.