本文整理汇总了C#中ITextRange类的典型用法代码示例。如果您正苦于以下问题:C# ITextRange类的具体用法?C# ITextRange怎么用?C# ITextRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITextRange类属于命名空间,在下文中一共展示了ITextRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DoActionOnLines
public static void DoActionOnLines(ITextView textView, ITextBuffer textBuffer, ITextRange range, IEditorShell editorShell, Func<ITextSnapshotLine, bool> action, string actionName) {
// When user clicks editor margin to select a line, selection actually
// ends in the beginning of the next line. In order to prevent commenting
// of the next line that user did not select, we need to shrink span to
// format and exclude the trailing line break.
ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
ITextSnapshotLine line = snapshot.GetLineFromPosition(range.End);
int start = range.Start;
int end = range.End;
if (line.Start.Position == range.End && range.Length > 0) {
if (line.LineNumber > 0) {
line = snapshot.GetLineFromLineNumber(line.LineNumber - 1);
end = line.End.Position;
start = Math.Min(start, end);
}
}
int startLineNumber = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(start);
int endLineNumber = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(end);
using (var undoAction = editorShell.CreateCompoundAction(textView, textBuffer)) {
undoAction.Open(actionName);
bool changed = false;
for (int i = startLineNumber; i <= endLineNumber; i++) {
line = textBuffer.CurrentSnapshot.GetLineFromLineNumber(i);
changed |= action(line);
}
if (changed) {
undoAction.Commit();
}
}
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:35,代码来源:RCommenter.cs
示例2: FormatRange
public static bool FormatRange(ITextView textView, ITextBuffer textBuffer, ITextRange formatRange,
AstRoot ast, RFormatOptions options, bool respectUserIndent = true) {
ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
int start = formatRange.Start;
int end = formatRange.End;
// When user clicks editor margin to select a line, selection actually
// ends in the beginning of the next line. In order to prevent formatting
// of the next line that user did not select, we need to shrink span to
// format and exclude the trailing line break.
ITextSnapshotLine line = snapshot.GetLineFromPosition(formatRange.End);
if (line.Start.Position == formatRange.End && formatRange.Length > 0) {
if (line.LineNumber > 0) {
line = snapshot.GetLineFromLineNumber(line.LineNumber - 1);
end = line.End.Position;
start = Math.Min(start, end);
}
}
// Expand span to include the entire line
ITextSnapshotLine startLine = snapshot.GetLineFromPosition(start);
ITextSnapshotLine endLine = snapshot.GetLineFromPosition(end);
formatRange = TextRange.FromBounds(startLine.Start, endLine.End);
return FormatRangeExact(textView, textBuffer, formatRange, ast, options, -1, respectUserIndent);
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:27,代码来源:RangeFormatter.cs
示例3: ValidationErrorBase
public ValidationErrorBase(ITextRange range, string message, ErrorLocation location, ErrorSeverity severity) :
base(range)
{
Message = message;
Severity = severity;
Location = location;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:ValidationErrorBase.cs
示例4: IsSelfClosing
/// <summary>
/// Determines if element is a self-closing element (i.e. like <br />
/// </summary>
/// <param name="textProvider">Text provider</param>
/// <param name="prefixRange">Text range of the element prefix</param>
/// <param name="nameRange">Text range of the element name</param>
/// <returns>True if element is a self-closing element.</returns>
public bool IsSelfClosing(ITextProvider textProvider, ITextRange prefixRange, ITextRange nameRange) {
if (nameRange.Length == 0)
return false;
string name = textProvider.GetText(nameRange);
if (name[0] == '!')
return true; // bang tags are always self-closing
if (prefixRange.Length == 0)
return _defaultProvider.IsSelfClosing(textProvider, nameRange);
string prefix = textProvider.GetText(prefixRange);
IHtmlClosureProvider provider; ;
_providers.TryGetValue(prefix, out provider);
var textRangeProvider = provider as IHtmlClosureProviderTextRange;
if (textRangeProvider != null)
return textRangeProvider.IsSelfClosing(textProvider, nameRange);
if (provider != null)
return provider.IsSelfClosing(name);
return false;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:32,代码来源:ElementClosureProvider.cs
示例5: IndexOf
public int IndexOf(string text, ITextRange range, bool ignoreCase) {
for (int i = range.Start; i < range.End; i++) {
bool found = true;
int k = i;
int j;
for (j = 0; j < text.Length && k < range.End; j++, k++) {
char ch1 = text[j];
char ch2 = this[k];
if (ignoreCase) {
ch1 = Char.ToLowerInvariant(ch1);
ch2 = Char.ToLowerInvariant(ch2);
}
if (ch1 != ch2) {
found = false;
break;
}
}
if (found && j == text.Length) {
return i;
}
}
return -1;
}
开发者ID:lioaphy,项目名称:nodejstools,代码行数:28,代码来源:TextProvider.cs
示例6: WindowsRichEditRange
internal WindowsRichEditRange(ITextRange range, WindowsRichEdit pattern)
{
Debug.Assert(range != null);
Debug.Assert(pattern != null);
_range = range;
_pattern = pattern;
}
开发者ID:JianwenSun,项目名称:cc,代码行数:8,代码来源:WindowsRichEditRange.cs
示例7: Parse
public static AstRoot Parse(ITextProvider textProvider, ITextRange range, IExpressionTermFilter filter) {
var tokenizer = new RTokenizer(separateComments: true);
IReadOnlyTextRangeCollection<RToken> tokens = tokenizer.Tokenize(textProvider, range.Start, range.Length);
TokenStream<RToken> tokenStream = new TokenStream<RToken>(tokens, new RToken(RTokenType.EndOfStream, TextRange.EmptyRange));
return Parse(textProvider, range, tokenStream, tokenizer.CommentTokens, filter);
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:8,代码来源:RParser.cs
示例8: MakeTextView
public static ITextView MakeTextView(string content, ITextRange selectionRange) {
TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
TextViewMock textView = new TextViewMock(textBuffer);
textView.Selection.Select(new SnapshotSpan(textBuffer.CurrentSnapshot,
new Span(selectionRange.Start, selectionRange.Length)), false);
return textView;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:8,代码来源:TextViewTest.cs
示例9: ParseContext
public ParseContext(ITextProvider textProvider, ITextRange range, TokenStream<RToken> tokens, IReadOnlyList<RToken> comments) {
this.AstRoot = new AstRoot(textProvider);
this.TextProvider = textProvider;
this.Tokens = tokens;
this.TextRange = range;
this.Scopes = new Stack<IScope>();
this.Expressions = new Stack<Expression>();
this.Comments = comments;
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:9,代码来源:ParseContext.cs
示例10: ItemsInRange
public IReadOnlyList<EditorErrorTag> ItemsInRange(ITextRange range) {
IReadOnlyList<EditorErrorTag> list;
lock (_lockObj) {
list = _tags.ItemsInRange(range);
}
return list;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:9,代码来源:ErrorTagCollection.cs
示例11: PeekNextToken
public static NextTokenType PeekNextToken(HtmlCharStream cs, int tagEnd, out ITextRange range) {
NextTokenType tokenType = NextTokenType.Unknown;
int current = cs.Position;
if (cs.IsEndOfStream() || cs.Position == tagEnd) {
range = new TextRange();
return NextTokenType.None;
}
int start = cs.Position;
while (cs.IsWhiteSpace())
cs.MoveToNextChar();
if (cs.IsEndOfStream() || cs.Position == tagEnd) {
range = TextRange.FromBounds(start, cs.Position);
return NextTokenType.Unknown;
}
if (cs.IsAtTagDelimiter()) {
tokenType = NextTokenType.Tag;
} else if (cs.CurrentChar == '=') {
tokenType = NextTokenType.Equals;
} else {
int digits = 0;
bool firstLetter = false;
int length = 0;
int chars = 0;
if (cs.IsAnsiLetter())
firstLetter = true;
while (!cs.IsEndOfStream() && !cs.IsWhiteSpace() && !cs.IsAtTagDelimiter() && cs.CurrentChar != '=' && cs.Position < tagEnd) {
if (cs.IsAnsiLetter() || cs.CurrentChar == '_' || cs.CurrentChar == '-')
chars++;
else if (cs.IsDecimal() || cs.CurrentChar == '.')
digits++;
cs.MoveToNextChar();
length++;
}
if (length > 0) {
if (length == digits)
tokenType = NextTokenType.Number;
else if (length == chars)
tokenType = NextTokenType.Letters;
else if (firstLetter)
tokenType = NextTokenType.Identifier;
}
}
range = TextRange.FromBounds(start, cs.Position);
cs.Position = current;
return tokenType;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:56,代码来源:NextTokenPeek.cs
示例12: WriteXaml
/// <summary>
/// Writes a content of current range in form of valid xml.
/// Places an artificial element xaml:FlowDocument as a root of output xml.
/// </summary>
/// <param name="xmlWriter">
/// XmlWriter to which the range will be serialized
/// </param>
/// <param name="range">
/// TextRange whose content is copied into XmlWriter xmlWriter.
/// </param>
/// <param name="useFlowDocumentAsRoot">
/// true means that we need to serialize the whole FlowDocument - used in FileSave scenario;
/// false means that we are in copy-paste scenario and will use Section or Span as a root - depending on context.
/// </param>
/// <param name="wpfPayload">
/// When this parameter is not null, images are serialized. When null, images are stripped out.
/// </param>
/// <param name="preserveTextElements">
/// When TRUE, TextElements are serialized as-is. When FALSE, they're upcast to their base type.
/// </param>
internal static void WriteXaml(XmlWriter xmlWriter, ITextRange range, bool useFlowDocumentAsRoot, WpfPayload wpfPayload, bool preserveTextElements)
{
// Set unindented formatting to avoid inserting insignificant whitespaces as significant ones
Formatting saveWriterFormatting = Formatting.None;
if (xmlWriter is XmlTextWriter)
{
saveWriterFormatting = ((XmlTextWriter)xmlWriter).Formatting;
((XmlTextWriter)xmlWriter).Formatting = Formatting.None;
}
// Get the default xamlTypeMapper.
XamlTypeMapper xamlTypeMapper = XmlParserDefaults.DefaultMapper;
// Identify structural scope of selection - nearest common ancestor
ITextPointer commonAncestor = FindSerializationCommonAncestor(range);
// Decide whether we need last paragraph merging or not
bool lastParagraphMustBeMerged =
!TextPointerBase.IsAfterLastParagraph(range.End) &&
range.End.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.ElementStart;
// Write wrapping element with contextual properties
WriteRootFlowDocument(range, commonAncestor, xmlWriter, xamlTypeMapper, lastParagraphMustBeMerged, useFlowDocumentAsRoot);
// The ignoreWriteHyperlinkEnd flag will be set after call WriteOpeningTags.
// If ignoreWriteHyperlinkEnd is true, WriteXamlTextSegment won't write Hyperlink end element
// since Hyperlink writing opening tag is ignored by selecting the partial of Hyperlink.
bool ignoreWriteHyperlinkEnd;
List<int> ignoreList = new List<int>();
// Start counting tags needed to be closed.
// EmptyDocumentDepth==1 - counts FlowDocument opened in WriteRootFlowDocument above.
int elementLevel = EmptyDocumentDepth + WriteOpeningTags(range, range.Start, commonAncestor, xmlWriter, xamlTypeMapper, /*reduceElement:*/wpfPayload == null, out ignoreWriteHyperlinkEnd, ref ignoreList, preserveTextElements);
if (range.IsTableCellRange)
{
WriteXamlTableCellRange(xmlWriter, range, xamlTypeMapper, ref elementLevel, wpfPayload, preserveTextElements);
}
else
{
WriteXamlTextSegment(xmlWriter, range.Start, range.End, xamlTypeMapper, ref elementLevel, wpfPayload, ignoreWriteHyperlinkEnd, ignoreList, preserveTextElements);
}
// Close all remaining tags - scoping its End position
Invariant.Assert(elementLevel >= 0, "elementLevel cannot be negative");
while (elementLevel-- > 0)
{
xmlWriter.WriteFullEndElement();
}
// Restore xmlWriter's Formatting property
if (xmlWriter is XmlTextWriter)
{
((XmlTextWriter)xmlWriter).Formatting = saveWriterFormatting;
}
}
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:76,代码来源:TextRangeSerialization.cs
示例13: ParseContext
public ParseContext(ITextProvider textProvider, ITextRange range, TokenStream<RToken> tokens, IReadOnlyList<RToken> comments, IExpressionTermFilter filter = null) {
AstRoot = new AstRoot(textProvider);
TextProvider = textProvider;
Tokens = tokens;
TextRange = range;
Scopes = new Stack<IScope>();
Expressions = new Stack<Expression>();
Comments = comments;
ExpressionTermFilter = filter ?? new DefaultExpressionTermFilter();
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:10,代码来源:ParseContext.cs
示例14: CharacterStream
public CharacterStream(ITextProvider textProvider, ITextRange range) {
_text = textProvider;
int end = Math.Min(_text.Length, range.End);
_range = TextRange.FromBounds(range.Start, end);
Position = _range.Start;
_currentChar = _text[_range.Start];
}
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:10,代码来源:CharacterStream.cs
示例15: Parse
/// <summary>
/// Parse text from a text provider within a given range
/// </summary>
/// <param name="textProvider">Text provider</param>
/// <param name="range">Range to parse</param>
public static AstRoot Parse(ITextProvider textProvider, ITextRange range) {
var tokenizer = new RTokenizer(separateComments: true);
IReadOnlyTextRangeCollection<RToken> tokens = tokenizer.Tokenize(textProvider, range.Start, range.Length);
TokenStream<RToken> tokenStream = new TokenStream<RToken>(tokens, new RToken(RTokenType.EndOfStream, TextRange.EmptyRange));
ParseContext context = new ParseContext(textProvider, range, tokenStream, tokenizer.CommentTokens);
context.AstRoot.Parse(context, context.AstRoot);
context.AstRoot.Errors = new TextRangeCollection<IParseError>(context.Errors);
return context.AstRoot;
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:18,代码来源:RParser.cs
示例16: IsImplicitlyClosed
/// <summary>
/// Determines if given element can be implicitly closed like <li> or <td> in HTML"
/// </summary>
/// <param name="text">Text provider</param>
/// <param name="name">Element name</param>
/// <returns>True if element can be implictly closed</returns>
public bool IsImplicitlyClosed(ITextProvider text, ITextRange name, out string[] containerElementNames) {
containerElementNames = null;
if (name.Length < _minCharCountImplicitClosing || name.Length > _maxCharCountImplicitClosing)
return false;
bool found = FindElementName(text, name, _implicitlyClosingElementNameIndex, ignoreCase: true);
if (found) {
string elementName = text.GetText(name);
containerElementNames = GetContainerElements(elementName);
}
return found;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:19,代码来源:DefaultClosureProvider.cs
示例17: GetLanguageBlockOfLocation
protected ITextRange GetLanguageBlockOfLocation(int bufferPosition) {
if (_cachedPosition != bufferPosition) {
var items = Blocks.GetItemsContainingInclusiveEnd(bufferPosition);
int index;
if (items.Count > 0) {
index = items[0];
} else {
index = Blocks.GetItemAtPosition(bufferPosition);
}
_cachedLanguageBlock = index >= 0 ? Blocks[index] : null;
_cachedPosition = bufferPosition;
}
return _cachedLanguageBlock;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:14,代码来源:ContainedLanguageHandler.cs
示例18: FormatRange
public static bool FormatRange(ITextView textView, ITextBuffer textBuffer, ITextRange formatRange, RFormatOptions options, IEditorShell editorShell) {
ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
int start = formatRange.Start;
int end = formatRange.End;
if(!CanFormatRange(textView, textBuffer, formatRange, editorShell)) {
return false;
}
// When user clicks editor margin to select a line, selection actually
// ends in the beginning of the next line. In order to prevent formatting
// of the next line that user did not select, we need to shrink span to
// format and exclude the trailing line break.
ITextSnapshotLine line = snapshot.GetLineFromPosition(formatRange.End);
if (line.Start.Position == formatRange.End && formatRange.Length > 0) {
if (line.LineNumber > 0) {
line = snapshot.GetLineFromLineNumber(line.LineNumber - 1);
end = line.End.Position;
start = Math.Min(start, end);
}
}
// Expand span to include the entire line
ITextSnapshotLine startLine = snapshot.GetLineFromPosition(start);
ITextSnapshotLine endLine = snapshot.GetLineFromPosition(end);
// In case of formatting of multiline expressions formatter needs
// to know the entire expression since otherwise it may not correctly
// preserve user indentation. Consider 'x >% y' which is a plain statement
// and needs to be indented at regular scope level vs
//
// a %>% b %>%
// x %>% y
//
// where user indentation of 'x %>% y' must be preserved. We don't have
// complete information here since expression may not be syntactically
// correct and hence AST may not have correct information and besides,
// the AST is damaged at this point. As a workaround, we will check
// if the previous line ends with an operator current line starts with
// an operator.
int startPosition = FindStartOfExpression(textBuffer, startLine.Start);
formatRange = TextRange.FromBounds(startPosition, endLine.End);
return FormatRangeExact(textView, textBuffer, formatRange, options, editorShell);
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:46,代码来源:RangeFormatter.cs
示例19: IsChangeDestructiveForChildNodes
private static bool IsChangeDestructiveForChildNodes(IAstNode node, ITextRange changedRange) {
if(changedRange.End <= node.Start || changedRange.Start >= node.End) {
return false;
}
else if(node.Children.Count == 0) {
return true;
}
bool result = false;
foreach (var child in node.Children) {
result |= IsChangeDestructiveForChildNodes(child, changedRange);
if(result) {
break;
}
}
return result;
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:18,代码来源:TextChangeAnalyzer.cs
示例20: ApplyChangeByTokens
/// <summary>
/// Incrementally applies whitespace change to the buffer
/// having old and new tokens produced from the 'before formatting'
/// and 'after formatting' versions of the same text.
/// </summary>
/// <param name="textBuffer">Text buffer to apply changes to</param>
/// <param name="newTextProvider">Text provider of the text fragment before formatting</param>
/// <param name="newTextProvider">Text provider of the formatted text</param>
/// <param name="oldTokens">Tokens from the 'before' text fragment</param>
/// <param name="newTokens">Tokens from the 'after' text fragment</param>
/// <param name="formatRange">Range that is being formatted in the text buffer</param>
/// <param name="transactionName">Name of the undo transaction to open</param>
/// <param name="selectionTracker">Selection tracker object that will save, track
/// <param name="additionalAction">Action to perform after changes are applies by undo unit is not yet closed.</param>
/// and restore selection after changes have been applied.</param>
public static void ApplyChangeByTokens(
ITextBuffer textBuffer,
ITextProvider oldTextProvider,
ITextProvider newTextProvider,
IReadOnlyList<ITextRange> oldTokens,
IReadOnlyList<ITextRange> newTokens,
ITextRange formatRange,
string transactionName,
ISelectionTracker selectionTracker,
IEditorShell editorShell,
Action additionalAction = null) {
Debug.Assert(oldTokens.Count == newTokens.Count);
if (oldTokens.Count == newTokens.Count) {
ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
using (CreateSelectionUndo(selectionTracker, editorShell, transactionName)) {
using (ITextEdit edit = textBuffer.CreateEdit()) {
if (oldTokens.Count > 0) {
// Replace whitespace between tokens in reverse so relative positions match
int oldEnd = oldTextProvider.Length;
int newEnd = newTextProvider.Length;
string oldText, newText;
for (int i = newTokens.Count - 1; i >= 0; i--) {
oldText = oldTextProvider.GetText(TextRange.FromBounds(oldTokens[i].End, oldEnd));
newText = newTextProvider.GetText(TextRange.FromBounds(newTokens[i].End, newEnd));
if (oldText != newText) {
edit.Replace(formatRange.Start + oldTokens[i].End, oldEnd - oldTokens[i].End, newText);
}
oldEnd = oldTokens[i].Start;
newEnd = newTokens[i].Start;
}
newText = newTextProvider.GetText(TextRange.FromBounds(0, newEnd));
edit.Replace(formatRange.Start, oldEnd, newText);
} else {
string newText = newTextProvider.GetText(TextRange.FromBounds(0, newTextProvider.Length));
edit.Replace(formatRange.Start, formatRange.Length, newText);
}
edit.Apply();
additionalAction?.Invoke();
}
}
}
}
开发者ID:Microsoft,项目名称:RTVS,代码行数:58,代码来源:IncrementalChangeApplication.cs
注:本文中的ITextRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论