Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <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 "
            TextControlUtil.DeleteSelection(textControl);
            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);
        }
Esempio n. 3
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.TOKEN)
            {
                return(false);
            }

            // insert =
            textControl.Selection.Delete();
            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);
        }
Esempio n. 4
0
        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, ">");
            });
        }
Esempio n. 5
0
        // When '%' is typed, insert another
        private bool OnPercentTyped(ITypingContext context)
        {
            var textControl = context.TextControl;

            if (!IsInAttributeValue(textControl))
            {
                return(false);
            }

            // get the token type after %
            var lexer  = GetCachingLexer(textControl);
            int offset = textControl.Selection.OneDocRangeWithCaret().GetMinOffset();

            if (lexer == null || offset <= 0 || !lexer.FindTokenAt(offset))
            {
                return(false);
            }

            // If there is already another percent after the %, swallow the typing
            var tokenType = lexer.TokenType;

            if (tokenType == T4TokenNodeTypes.PERCENT)
            {
                textControl.Caret.MoveTo(offset + 1, CaretVisualPlacement.DontScrollIfVisible);
                return(true);
            }

            // 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);
                }
            });

            return(true);
        }