1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using System.Windows.Input;
7
using ICSharpCode.AvalonEdit.Document;
9
namespace ICSharpCode.AvalonEdit.Snippets
12
/// Inserts the previously selected text at the selection marker.
15
public class SnippetSelectionElement : SnippetElement
18
/// Gets/Sets the new indentation of the selected text.
20
public int Indentation { get; set; }
23
public override void Insert(InsertionContext context)
25
StringBuilder tabString = new StringBuilder();
27
for (int i = 0; i < Indentation; i++) {
28
tabString.Append(context.Tab);
31
string indent = tabString.ToString();
33
string text = context.SelectedText.TrimStart(' ', '\t');
35
text = text.Replace(context.LineTerminator,
36
context.LineTerminator + indent);
38
context.Document.Insert(context.InsertionPosition, text);
39
context.InsertionPosition += text.Length;
41
if (string.IsNullOrEmpty(context.SelectedText))
42
SnippetCaretElement.SetCaret(context);