/// <inheritdoc/> public override void Insert(InsertionContext context) { foreach (SnippetElement e in this.Elements) { e.Insert(context); } }
/// <inheritdoc/> public override void Insert(InsertionContext context) { if (!string.IsNullOrEmpty(context.SelectedText)) { SetCaret(context); } }
/// <summary> /// Inserts the snippet into the text area. /// </summary> public void Insert(TextArea textArea) { if (textArea == null) { throw new ArgumentNullException("textArea"); } ISegment selection = textArea.Selection.SurroundingSegment; int insertionPosition = textArea.Caret.Offset; if (selection != null) // if something is selected { insertionPosition = selection.Offset; // 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. InsertionContext context = new InsertionContext(textArea, insertionPosition); if (selection != null) { textArea.Document.Remove(selection); } using (context.Document.RunUpdate()) { Insert(context); context.RaiseInsertionCompleted(EventArgs.Empty); } }
public BoundActiveElement(InsertionContext context, SnippetReplaceableTextElement targetSnippetElement, SnippetBoundElement boundElement, AnchorSegment segment) { this.context = context; this.targetSnippetElement = targetSnippetElement; this.boundElement = boundElement; this.segment = segment; }
/// <inheritdoc/> public override void Insert(InsertionContext context) { if (text != null) { context.InsertText(text); } }
/// <inheritdoc/> public override void Insert(InsertionContext context) { context.InsertText(context.SelectedText); if (string.IsNullOrEmpty(context.SelectedText)) { SnippetCaretElement.SetCaret(context); } }
/// <inheritdoc/> public override void Insert(InsertionContext context) { int start = context.InsertionPosition; base.Insert(context); int end = context.InsertionPosition; context.RegisterActiveElement(this, new ReplaceableActiveElement(context, start, end)); }
internal static void SetCaret(InsertionContext context) { TextAnchor pos = context.Document.CreateAnchor(context.InsertionPosition); 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) { int start = context.InsertionPosition; string inputText = targetElement.Text; if (inputText != null) { context.InsertText(ConvertText(inputText)); } int end = context.InsertionPosition; AnchorSegment segment = new AnchorSegment(context.Document, start, end - start); context.RegisterActiveElement(this, new BoundActiveElement(context, targetElement, this, segment)); } }
public ReplaceableActiveElement(InsertionContext context, int startOffset, int endOffset) { this.context = context; this.startOffset = startOffset; this.endOffset = endOffset; }
public SnippetInputHandler(InsertionContext context) : base(context.TextArea) { this.context = context; }
/// <summary> /// Performs insertion of the snippet. /// </summary> public abstract void Insert(InsertionContext context);