public void InsertSnippet() { ScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); editor.BeginUndoAction(); Position end = editor.GetLineEndPosition(editor.LineFromPosition(editor.GetSelectionEnd())); Position start = editor.PositionFromLine(editor.LineFromPosition(editor.GetSelectionStart())); int indent = KeepIndent ? editor.GetLineIndentation(editor.LineFromPosition(start)) : 0; string insertText = IndentSnippetBody(SnippetBodyBefore, indent) + IndentSelectedStrings(editor, start, end) + IndentSnippetBody(SnippetBodyAfter, indent); editor.DeleteRange(start, end.Value - start.Value + 1); editor.InsertText(start, insertText); using (TextToFind textToFind = new TextToFind(start.Value, start.Value + insertText.Length, Placeholder)) { Position placeholderPosition = editor.FindText(0, textToFind); editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value); } editor.EndUndoAction(); }