/// <summary> /// Inserts the snippet into the text area. /// </summary> public InsertionContext Insert(TextArea textArea) { if (textArea == null) { throw new ArgumentNullException(nameof(textArea)); } var selection = textArea.Selection.SurroundingSegment; var insertionPosition = textArea.Caret.Offset; if (selection != null) // if something is selected // use selection start instead of caret position, // because caret could be at end of selection or anywhere inside. // Removal of the selected text causes the caret position to be invalid. { insertionPosition = selection.Offset + TextUtilities.GetWhitespaceAfter(textArea.Document, selection.Offset).Length; } var context = new InsertionContext(textArea, insertionPosition); using (context.Document.RunUpdate()) { if (selection != null) { textArea.Document.Remove(insertionPosition, selection.EndOffset - insertionPosition); } Insert(context); context.RaiseInsertionCompleted(EventArgs.Empty); } return(context); }
/// <inheritdoc/> public override void Insert(InsertionContext context) { if (!_setCaretOnlyIfTextIsSelected || !string.IsNullOrEmpty(context.SelectedText)) { SetCaret(context); } }
public BoundActiveElement(InsertionContext context, SnippetReplaceableTextElement targetSnippetElement, SnippetBoundElement boundElement, AnchorSegment segment) { _context = context; _targetSnippetElement = targetSnippetElement; _boundElement = boundElement; _segment = segment; }
/// <inheritdoc/> public override void Insert(InsertionContext context) { foreach (var e in Elements) { e.Insert(context); } }
/// <inheritdoc/> public override void Insert(InsertionContext context) { var start = context.InsertionPosition; base.Insert(context); var end = context.InsertionPosition; context.RegisterActiveElement(this, new ReplaceableActiveElement(context, start, end)); }
/// <inheritdoc /> public override void Insert(InsertionContext context) { var start = context.Document.CreateAnchor(context.InsertionPosition); start.MovementType = AnchorMovementType.BeforeInsertion; start.SurviveDeletion = true; var segment = new AnchorSegment(start, start); context.RegisterActiveElement(this, new AnchorElement(segment, Name, context)); }
internal static void SetCaret(InsertionContext context) { var pos = context.Document.CreateAnchor(context.InsertionPosition); pos.MovementType = AnchorMovementType.BeforeInsertion; pos.SurviveDeletion = true; context.Deactivated += (sender, e) => { if (e.Reason == DeactivateReason.ReturnPressed || e.Reason == DeactivateReason.NoActiveElements) { context.TextArea.Caret.Offset = pos.Offset; } }; }
/// <inheritdoc/> public override void Insert(InsertionContext context) { if (TargetElement != null) { var start = context.Document.CreateAnchor(context.InsertionPosition); start.MovementType = AnchorMovementType.BeforeInsertion; start.SurviveDeletion = true; var inputText = TargetElement.Text; if (inputText != null) { context.InsertText(ConvertText(inputText)); } var end = context.Document.CreateAnchor(context.InsertionPosition); end.MovementType = AnchorMovementType.BeforeInsertion; end.SurviveDeletion = true; var segment = new AnchorSegment(start, end); context.RegisterActiveElement(this, new BoundActiveElement(context, TargetElement, this, segment)); } }
/// <inheritdoc/> public override void Insert(InsertionContext context) { var tabString = new StringBuilder(); for (var i = 0; i < Indentation; i++) { tabString.Append(context.Tab); } var indent = tabString.ToString(); var text = context.SelectedText.TrimStart(' ', '\t'); text = text.Replace(context.LineTerminator, context.LineTerminator + indent); context.Document.Insert(context.InsertionPosition, text); context.InsertionPosition += text.Length; if (string.IsNullOrEmpty(context.SelectedText)) { SnippetCaretElement.SetCaret(context); } }
public SnippetInputHandler(InsertionContext context) : base(context.TextArea) { _context = context; }
public ReplaceableActiveElement(InsertionContext context, int startOffset, int endOffset) { _context = context; _startOffset = startOffset; _endOffset = endOffset; }
/// <summary> /// Creates a new AnchorElement. /// </summary> public AnchorElement(AnchorSegment segment, string name, InsertionContext context) { _segment = segment; _context = context; Name = name; }