本文整理汇总了C#中Microsoft.AspNet.Razor.Text.TextChange类的典型用法代码示例。如果您正苦于以下问题:C# TextChange类的具体用法?C# TextChange怎么用?C# TextChange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextChange类属于Microsoft.AspNet.Razor.Text命名空间,在下文中一共展示了TextChange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OwnsChange
public virtual bool OwnsChange(Span target, TextChange change)
{
int end = target.Start.AbsoluteIndex + target.Length;
int changeOldEnd = change.OldPosition + change.OldLength;
return change.OldPosition >= target.Start.AbsoluteIndex &&
(changeOldEnd < end || (changeOldEnd == end && AcceptedCharacters != AcceptedCharacters.None));
}
示例2: WriteDebugTree
internal static void WriteDebugTree(string sourceFile, Block document, PartialParseResult result, TextChange change, RazorEditorParser parser, bool treeStructureChanged)
{
if (!OutputDebuggingEnabled)
{
return;
}
RunTask(() =>
{
string outputFileName = Normalize(sourceFile) + "_tree";
string outputPath = Path.Combine(Path.GetDirectoryName(sourceFile), outputFileName);
var treeBuilder = new StringBuilder();
WriteTree(document, treeBuilder);
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Last Change: {0}", change);
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Normalized To: {0}", change.Normalize());
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Partial Parse Result: {0}", result);
treeBuilder.AppendLine();
if (result.HasFlag(PartialParseResult.Rejected))
{
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Tree Structure Changed: {0}", treeStructureChanged);
treeBuilder.AppendLine();
}
if (result.HasFlag(PartialParseResult.AutoCompleteBlock))
{
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Auto Complete Insert String: \"{0}\"", parser.GetAutoCompleteString());
treeBuilder.AppendLine();
}
File.WriteAllText(outputPath, treeBuilder.ToString());
});
}
示例3: TestIsDelete
public void TestIsDelete()
{
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 1, oldBuffer, 0, newBuffer);
// Assert
Assert.True(change.IsDelete);
}
示例4: TestDeleteCreatesTheRightSizeChange
public void TestDeleteCreatesTheRightSizeChange()
{
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 1, oldBuffer, 0, newBuffer);
// Assert
Assert.Equal(0, change.NewText.Length);
Assert.Equal(1, change.OldText.Length);
}
示例5: CanAcceptChange
protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)
{
if (((AutoCompleteAtEndOfSpan && IsAtEndOfSpan(target, normalizedChange)) || IsAtEndOfFirstLine(target, normalizedChange)) &&
normalizedChange.IsInsert &&
ParserHelpers.IsNewLine(normalizedChange.NewText) &&
AutoCompleteString != null)
{
return PartialParseResult.Rejected | PartialParseResult.AutoCompleteBlock;
}
return PartialParseResult.Rejected;
}
示例6: CanAcceptChange
protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)
{
if (AcceptedCharacters == AcceptedCharacters.Any)
{
return PartialParseResult.Rejected;
}
// In some editors intellisense insertions are handled as "dotless commits". If an intellisense selection is confirmed
// via something like '.' a dotless commit will append a '.' and then insert the remaining intellisense selection prior
// to the appended '.'. This 'if' statement attempts to accept the intermediate steps of a dotless commit via
// intellisense. It will accept two cases:
// 1. '@foo.' -> '@foobaz.'.
// 2. '@foobaz..' -> '@foobaz.bar.'. Includes Sub-cases '@foobaz()..' -> '@foobaz().bar.' etc.
// The key distinction being the double '.' in the second case.
if (IsDotlessCommitInsertion(target, normalizedChange))
{
return HandleDotlessCommitInsertion(target);
}
if (IsAcceptableReplace(target, normalizedChange))
{
return HandleReplacement(target, normalizedChange);
}
var changeRelativePosition = normalizedChange.OldPosition - target.Start.AbsoluteIndex;
// Get the edit context
char? lastChar = null;
if (changeRelativePosition > 0 && target.Content.Length > 0)
{
lastChar = target.Content[changeRelativePosition - 1];
}
// Don't support 0->1 length edits
if (lastChar == null)
{
return PartialParseResult.Rejected;
}
// Accepts cases when insertions are made at the end of a span or '.' is inserted within a span.
if (IsAcceptableInsertion(target, normalizedChange))
{
// Handle the insertion
return HandleInsertion(target, lastChar.Value, normalizedChange);
}
if (IsAcceptableDeletion(target, normalizedChange))
{
return HandleDeletion(target, lastChar.Value, normalizedChange);
}
return PartialParseResult.Rejected;
}
示例7: ConstructorInitializesProperties
public void ConstructorInitializesProperties()
{
// Act
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(42, 24, oldBuffer, 1337, newBuffer);
// Assert
Assert.Equal(42, change.OldPosition);
Assert.Equal(24, change.OldLength);
Assert.Equal(1337, change.NewLength);
Assert.Same(newBuffer, change.NewBuffer);
Assert.Same(oldBuffer, change.OldBuffer);
}
示例8: ApplyChange
public virtual EditResult ApplyChange(Span target, TextChange change, bool force)
{
PartialParseResult result = PartialParseResult.Accepted;
TextChange normalized = change.Normalize();
if (!force)
{
result = CanAcceptChange(target, normalized);
}
// If the change is accepted then apply the change
if (result.HasFlag(PartialParseResult.Accepted))
{
return new EditResult(result, UpdateSpan(target, normalized));
}
return new EditResult(result, new SpanBuilder(target));
}
示例9: UpdateSpan
protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange)
{
string newContent = normalizedChange.ApplyChange(target);
SpanBuilder newSpan = new SpanBuilder(target);
newSpan.ClearSymbols();
foreach (ISymbol sym in Tokenizer(newContent))
{
sym.OffsetStart(target.Start);
newSpan.Accept(sym);
}
if (target.Next != null)
{
SourceLocation newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent);
target.Next.ChangeStart(newEnd);
}
return newSpan;
}
示例10: LocateOwnerReturnsNullIfNoSpanReturnsTrueForOwnsSpan
public void LocateOwnerReturnsNullIfNoSpanReturnsTrueForOwnsSpan()
{
// Arrange
var factory = SpanFactory.CreateCsHtml();
var block = new MarkupBlock(
factory.Markup("Foo "),
new StatementBlock(
factory.CodeTransition(),
factory.Code("bar").AsStatement()),
factory.Markup(" Baz"));
var change = new TextChange(128, 1, new StringTextBuffer("Foo @bar Baz"), 1, new StringTextBuffer("Foo @bor Baz"));
// Act
var actual = block.LocateOwner(change);
// Assert
Assert.Null(actual);
}
示例11: IsAcceptableEndInsertion
// Accepts character insertions at the end of spans. AKA: '@foo' -> '@fooo' or '@foo' -> '@foo ' etc.
private static bool IsAcceptableEndInsertion(Span target, TextChange change)
{
Debug.Assert(change.IsInsert);
return IsAtEndOfSpan(target, change) ||
RemainingIsWhitespace(target, change);
}
示例12: IsAcceptableInsertion
// Acceptable insertions can occur at the end of a span or when a '.' is inserted within a span.
private static bool IsAcceptableInsertion(Span target, TextChange change)
{
return change.IsInsert &&
(IsAcceptableEndInsertion(target, change) ||
IsAcceptableInnerInsertion(target, change));
}
示例13: IsAtEndOfSpan
protected internal static bool IsAtEndOfSpan(Span target, TextChange change)
{
return (change.OldPosition + change.OldLength) == (target.Start.AbsoluteIndex + target.Length);
}
示例14: HandleInsertionAfterDot
private PartialParseResult HandleInsertionAfterDot(Span target, TextChange change)
{
// If the insertion is a full identifier or another dot, accept it
if (ParserHelpers.IsIdentifier(change.NewText) || change.NewText == ".")
{
return TryAcceptChange(target, change);
}
return PartialParseResult.Rejected;
}
示例15: HandleInsertion
private PartialParseResult HandleInsertion(Span target, char previousChar, TextChange change)
{
// What are we inserting after?
if (previousChar == '.')
{
return HandleInsertionAfterDot(target, change);
}
else if (ParserHelpers.IsIdentifierPart(previousChar) || previousChar == ')' || previousChar == ']')
{
return HandleInsertionAfterIdPart(target, change);
}
else
{
return PartialParseResult.Rejected;
}
}