Пример #1
0
        /// <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
            // 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;
            }

            InsertionContext 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);
            }
        }
 public BoundActiveElement(InsertionContext context, SnippetReplaceableTextElement targetSnippetElement, SnippetBoundElement boundElement, AnchorSegment segment)
 {
     this.context = context;
     this.targetSnippetElement = targetSnippetElement;
     this.boundElement         = boundElement;
     this.segment = segment;
 }
Пример #3
0
 /// <inheritdoc/>
 public override void Insert(InsertionContext context)
 {
     if (text != null)
     {
         context.InsertText(text);
     }
 }
Пример #4
0
 /// <inheritdoc/>
 public override void Insert(InsertionContext context)
 {
     foreach (SnippetElement e in this.Elements)
     {
         e.Insert(context);
     }
 }
 /// <inheritdoc/>
 public override void Insert(InsertionContext context)
 {
     if (!setCaretOnlyIfTextIsSelected || !string.IsNullOrEmpty(context.SelectedText))
     {
         SetCaret(context);
     }
 }
Пример #6
0
        /// <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));
        }
        /// <inheritdoc />
        public override void Insert(InsertionContext context)
        {
            TextAnchor start = context.Document.CreateAnchor(context.InsertionPosition);

            start.MovementType    = AnchorMovementType.BeforeInsertion;
            start.SurviveDeletion = true;
            AnchorSegment segment = new AnchorSegment(start, start);

            context.RegisterActiveElement(this, new AnchorElement(segment, Name, context));
        }
        internal static void SetCaret(InsertionContext context)
        {
            TextAnchor 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)
     {
         TextAnchor start = context.Document.CreateAnchor(context.InsertionPosition);
         start.MovementType    = AnchorMovementType.BeforeInsertion;
         start.SurviveDeletion = true;
         string inputText = targetElement.Text;
         if (inputText != null)
         {
             context.InsertText(ConvertText(inputText));
         }
         TextAnchor end = context.Document.CreateAnchor(context.InsertionPosition);
         end.MovementType    = AnchorMovementType.BeforeInsertion;
         end.SurviveDeletion = true;
         AnchorSegment segment = new AnchorSegment(start, end);
         context.RegisterActiveElement(this, new BoundActiveElement(context, targetElement, this, segment));
     }
 }
        /// <inheritdoc/>
        public override void Insert(InsertionContext context)
        {
            StringBuilder tabString = new StringBuilder();

            for (int i = 0; i < Indentation; i++)
            {
                tabString.Append(context.Tab);
            }

            string indent = tabString.ToString();

            string 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);
            }
        }
Пример #11
0
 public ReplaceableActiveElement(InsertionContext context, int startOffset, int endOffset)
 {
     this.context     = context;
     this.startOffset = startOffset;
     this.endOffset   = endOffset;
 }
 /// <summary>
 /// Creates a new AnchorElement.
 /// </summary>
 public AnchorElement(AnchorSegment segment, string name, InsertionContext context)
 {
     this.segment = segment;
     this.context = context;
     this.Name    = name;
 }
Пример #13
0
 public SnippetInputHandler(InsertionContext context)
     : base(context.TextArea)
 {
     this.context = context;
 }
Пример #14
0
 /// <summary>
 /// Performs insertion of the snippet.
 /// </summary>
 public abstract void Insert(InsertionContext context);