in Backend/Core/ForTea.Core/Services/TypingAssist/T4TypingAssist.cs [301:336]
private bool OnPercentTyped(ITypingContext context)
{
var textControl = context.TextControl;
if (!IsInAttributeValue(textControl)) return false;
// get the token type after %
var lexer = GetCachingLexer(textControl);
if (lexer == null) return false;
var offset = textControl.Caret.DocumentOffset();
if (!lexer.FindTokenAt(offset.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;
}