Example #1
0
        /// <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
                _intellisenseManager.ExecuteAutoCompletion <T4AutopopupSettingsKey>(textControl, Solution, key => key.InDirectives);
            });

            return(true);
        }