private bool OnDollarTyped(ITypingContext context) { var textControl = context.TextControl; if (!IsInAttributeValue(textControl)) { return(false); } int offset = textControl.GetOffset(); textControl.Selection.Delete(); textControl.Document.InsertText(offset, "$"); textControl.Caret.MoveTo(offset + 1, CaretVisualPlacement.DontScrollIfVisible); context.QueueCommand(() => { using (CommandProcessor.UsingCommand("Inserting T4 Macro Parenthesis")) { textControl.Document.InsertText(offset + 1, "()"); textControl.Caret.MoveTo(offset + 2, CaretVisualPlacement.DontScrollIfVisible); } SkippingTypingAssist.SetCharsToSkip(textControl.Document, "("); }); return(true); }
/// <summary>When a " is typed, insert another ".</summary> private bool OnQuoteTyped(ITypingContext context) { ITextControl textControl = context.TextControl; // the " character should be skipped to avoid double insertions if (SkippingTypingAssist.ShouldSkip(textControl.Document, context.Char)) { SkippingTypingAssist.SkipIfNeeded(textControl.Document, context.Char); return(true); } // get the token type after " CachingLexer cachingLexer = GetCachingLexer(textControl); int offset = textControl.Selection.OneDocRangeWithCaret().GetMinOffset(); if (cachingLexer == null || offset <= 0 || !cachingLexer.FindTokenAt(offset)) { return(false); } // there is already another quote after the ", swallow the typing TokenNodeType tokenType = cachingLexer.TokenType; if (tokenType == T4TokenNodeTypes.Quote) { textControl.Caret.MoveTo(offset + 1, CaretVisualPlacement.DontScrollIfVisible); return(true); } // we're inside or after an attribute value, simply do nothing and let the " be typed if (tokenType == T4TokenNodeTypes.Value) { return(false); } // insert the first " textControl.Selection.Delete(); textControl.FillVirtualSpaceUntilCaret(); textControl.Document.InsertText(offset, "\""); // insert the second " context.QueueCommand(() => { using (CommandProcessor.UsingCommand("Inserting \"")) { textControl.Document.InsertText(offset + 1, "\""); textControl.Caret.MoveTo(offset + 1, CaretVisualPlacement.DontScrollIfVisible); } // ignore if a subsequent " is typed by the user SkippingTypingAssist.SetCharsToSkip(textControl.Document, "\""); // popup auto completion _codeCompletionSessionManager.ExecuteAutoCompletion <T4AutopopupSettingsKey>(textControl, Solution, key => key.InDirectives); }); return(true); }
/// <summary> /// When = is typed, insert "". /// </summary> private bool OnEqualTyped(ITypingContext context) { ITextControl textControl = context.TextControl; // get the token type before = CachingLexer cachingLexer = GetCachingLexer(textControl); int offset = textControl.Selection.OneDocRangeWithCaret().GetMinOffset(); if (cachingLexer == null || offset <= 0 || !cachingLexer.FindTokenAt(offset - 1)) { return(false); } // do nothing if we're not after an attribute name TokenNodeType tokenType = cachingLexer.TokenType; if (tokenType != T4TokenNodeTypes.Name) { return(false); } // insert = TextControlUtil.DeleteSelection(textControl); textControl.FillVirtualSpaceUntilCaret(); textControl.Document.InsertText(offset, "="); textControl.Caret.MoveTo(offset + 1, CaretVisualPlacement.DontScrollIfVisible); // insert "" context.QueueCommand(() => { using (CommandProcessor.UsingCommand("Inserting \"\"")) { textControl.Document.InsertText(offset + 1, "\"\""); textControl.Caret.MoveTo(offset + 2, CaretVisualPlacement.DontScrollIfVisible); } // ignore if a subsequent " is typed by the user _skippingTypingAssist.SetCharsToSkip(textControl.Document, "\""); // popup auto completion _codeCompletionSessionManager.ExecuteAutoCompletion <T4AutopopupSettingsKey>(textControl, Solution, key => key.InDirectives); }); return(true); }
private void InsertBlockEnd([NotNull] ITypingContext context) { var textControl = context.TextControl; int offset = textControl.GetOffset(); InsertOctothorpe(textControl); context.QueueCommand(() => { using (CommandProcessor.UsingCommand("Inserting >")) { textControl.Document.InsertText(offset + 1, ">"); textControl.Caret.MoveTo(offset + 2, CaretVisualPlacement.DontScrollIfVisible); } SkippingTypingAssist.SetCharsToSkip(textControl.Document, ">"); }); }