本文整理汇总了C#中TextRange.ExtendRight方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.ExtendRight方法的具体用法?C# TextRange.ExtendRight怎么用?C# TextRange.ExtendRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextRange
的用法示例。
在下文中一共展示了TextRange.ExtendRight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AfterCompletion
protected override void AfterCompletion(
ITextControl textControl, ISolution solution, Suffix suffix,
TextRange resultRange, string targetText, int caretOffset)
{
var placeholders = new List<TextRange>();
for (var index = 0;; index++)
{
index = targetText.IndexOf(NamePlaceholder, index, StringComparison.Ordinal);
if (index == -1) break;
var range = new TextRange(resultRange.StartOffset + index);
placeholders.Add(range.ExtendRight(NamePlaceholder.Length));
}
if (placeholders.Count == 0)
{
base.AfterCompletion(textControl, solution, suffix, resultRange, targetText, caretOffset);
}
else
{
var nameField = new TemplateField("name", new NameSuggestionsExpression(myNames), 0);
var hotspotInfo = new HotspotInfo(nameField, placeholders);
var endRange = new TextRange(resultRange.StartOffset + caretOffset);
var session = LiveTemplatesManager.Instance.CreateHotspotSessionAtopExistingText(
mySolution, endRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, hotspotInfo);
if (!suffix.IsEmpty)
{
session.HotspotUpdated += delegate
{
if (session.IsFinished)
suffix.Playback(textControl);
};
}
session.Execute();
}
}
示例2: PresentExpression
private static string PresentExpression(
[NotNull] PrefixExpressionContext context, [NotNull] string postfixText, out TextRange range)
{
var text = context.Expression.GetText();
range = context.ExpressionRange.TextRange;
if (context.Expression.Contains(context.PostfixContext.Reference))
{
var originalSize = text.Length;
// "x > 0.par" => "x > 0"
if (text.EndsWith(postfixText, StringComparison.OrdinalIgnoreCase))
text = text.Substring(0, text.Length - postfixText.Length).TrimEnd();
var delta = originalSize - text.Length;
if (delta >= 0) range = range.ExtendRight(-delta);
}
text = text.ReplaceNewLines().TrimStart();
while (true) // "aa\n && bb" => "aa && bb"
{
var reduced = text.Replace(" ", " ");
if (reduced.Length < text.Length) text = reduced;
else break;
}
const int textLength = 50;
if (text.Length > textLength)
{
text = text.Substring(0, textLength) + "…";
}
return text;
}