本文整理汇总了C#中ITextSnapshotLine.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshotLine.GetText方法的具体用法?C# ITextSnapshotLine.GetText怎么用?C# ITextSnapshotLine.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSnapshotLine
的用法示例。
在下文中一共展示了ITextSnapshotLine.GetText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Modify
protected override void Modify(ITextEdit edit, ITextSnapshotLine line)
{
if (line.GetText().StartsWith("#"))
{
edit.Delete(line.Start, 1);
}
}
示例2: LineProgress
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="line">The line snapshot</param>
/// <param name="state">The starting state</param>
/// <param name="naturalTextSpans">The collection of natural text spans</param>
public LineProgress(ITextSnapshotLine line, State state, List<SnapshotSpan> naturalTextSpans)
{
_snapshotLine = line;
_lineText = line.GetText();
_linePosition = 0;
_naturalTextSpans = naturalTextSpans;
this.State = state;
}
示例3: CommentLine
internal static bool CommentLine(ITextSnapshotLine line) {
string lineText = line.GetText();
if (!string.IsNullOrWhiteSpace(lineText)) {
int leadingWsLength = lineText.Length - lineText.TrimStart().Length;
line.Snapshot.TextBuffer.Insert(line.Start + leadingWsLength, "#");
return true;
}
return false;
}
示例4: UncommentLine
internal static bool UncommentLine(ITextSnapshotLine line) {
string lineText = line.GetText();
if (!string.IsNullOrWhiteSpace(lineText)) {
int leadingWsLength = lineText.Length - lineText.TrimStart().Length;
if (leadingWsLength < lineText.Length) {
if (lineText[leadingWsLength] == '#') {
line.Snapshot.TextBuffer.Delete(new Span(line.Start + leadingWsLength, 1));
return true;
}
}
}
return false;
}
示例5: SkipPreceedingBlankLines
private static void SkipPreceedingBlankLines(ITextSnapshotLine line, out string baselineText, out ITextSnapshotLine baseline) {
string text;
while (line.LineNumber > 0) {
line = line.Snapshot.GetLineFromLineNumber(line.LineNumber - 1);
text = line.GetText();
if (!IsBlankLine(text)) {
baseline = line;
baselineText = text;
return;
}
}
baselineText = line.GetText();
baseline = line;
}
示例6: Match
public IEnumerable<SnapshotSpan> Match(ITextSnapshotLine line)
{
Regex regex = GetRegex();
if ( line.Length == 0 || regex == null ) {
yield break;
}
ITextSnapshot snapshot = line.Snapshot;
var matches = GetRegex().Matches(line.GetText());
foreach ( Match m in matches ) {
switch ( Options ) {
case ExpressionOptions.HideMatch:
yield return new SnapshotSpan(snapshot,
line.Start + m.Index, m.Length);
break;
case Util.ExpressionOptions.HideGroups:
for ( int g = 1; g < m.Groups.Count; g++ ) {
yield return new SnapshotSpan(snapshot,
line.Start + m.Groups[g].Index, m.Groups[g].Length);
}
break;
}
}
}
示例7: IsSelectorEligible
private static bool IsSelectorEligible(ITextSnapshotLine line, int position)
{
string text = line.GetText();
if (text.IndexOf('{') > -1)
return false;
if (line.Snapshot.ContentType.DisplayName == "LESS")
{
var commentStart = text.IndexOf("//");
if (commentStart > position)
return false;
if (commentStart > 0)
text = text.Remove(commentStart);
}
if (text.Trim().EndsWith(",", StringComparison.Ordinal))
return false;
if (line.LineNumber + 1 < line.Snapshot.LineCount)
{
var next = line.Snapshot.GetLineFromLineNumber(line.LineNumber + 1);
if (next.GetText().Trim().StartsWith("{", StringComparison.Ordinal))
return false;
}
return true;
}
示例8: IsPropertyNameEligible
private static bool IsPropertyNameEligible(ITextSnapshotLine line)
{
return !line.GetText().Contains(":");
}
示例9: DoSmartIndent
private int? DoSmartIndent(ITextSnapshotLine line) {
if (line.LineNumber == 0) {
return null;
}
int? indentation = GetLeadingWhiteSpace(line.GetText());
var classifications = EnumerateClassificationsInReverse(
_classifier,
line.Snapshot.GetLineFromLineNumber(line.LineNumber - 1).End
);
if (classifications.MoveNext()) {
var starting = classifications.Current;
// first check to see if we're in an unterminated multiline token
if (starting != null) {
if (starting.Tag.ClassificationType.Classification == "comment" &&
starting.Span.GetText().StartsWith("/*") &&
(!starting.Span.GetText().EndsWith("*/") || starting.Span.End.GetContainingLine() == line)) {
// smart indent in comment, dont indent
return null;
} else if (starting.Tag.ClassificationType.Classification == "string") {
var text = starting.Span.GetText();
if (!text.EndsWith("\"") && !text.EndsWith("'")) {
// smart indent in multiline string, no indent
return null;
}
}
}
// walk backwards and collect all of the possible tokens that could
// be useful here...
var tokenStack = new System.Collections.Generic.Stack<ITagSpan<ClassificationTag>>();
tokenStack.Push(null); // end with an implicit newline
bool endAtNextNull = false;
do {
var token = classifications.Current;
tokenStack.Push(token);
if (token == null && endAtNextNull) {
break;
} else if (token != null &&
token.Span.GetText() == "{") {
endAtNextNull = true;
}
} while (classifications.MoveNext());
var indentStack = new System.Collections.Generic.Stack<LineInfo>();
var current = LineInfo.Empty;
while (tokenStack.Count > 0) {
var token = tokenStack.Pop();
bool didDedent = false;
if (token == null) {
current.NeedsUpdate = true;
} else if (IsOpenGrouping(token)) {
if (current.WasIndentKeyword && token.Span.GetText() == "{") {
// the indentation statement is followed by braces, go ahead
// and remove the level of indentation now
current.WasIndentKeyword = false;
current.Indentation -= _editorOptions.GetTabSize();
}
indentStack.Push(current);
var start = token.Span.Start;
current = new LineInfo {
Indentation = GetLeadingWhiteSpace(start.GetContainingLine().GetText()) + _editorOptions.GetTabSize()
};
} else if (_indentKeywords.Contains(token.Span.GetText()) && !current.WasDoKeyword) {
// if (foo)
// console.log('hi')
// We should indent here
var start = token.Span.Start;
int dedentTo = GetLeadingWhiteSpace(start.GetContainingLine().GetText());
if (current.DedentTo != null && token.Span.GetText() != "if") {
// https://nodejstools.codeplex.com/workitem/1176
// if (true)
// while (true)
// ;
//
// We should dedent to the if (true)
// But for:
// if (true)
// if (true)
// ;
// We still want to dedent to our current level for the else
dedentTo = current.DedentTo.Value;
}
current = new LineInfo {
Indentation = GetLeadingWhiteSpace(start.GetContainingLine().GetText()) + _editorOptions.GetTabSize(),
DedentTo = dedentTo,
WasIndentKeyword = true,
WasDoKeyword = token.Span.GetText() == "do"
};
} else if (IsCloseGrouping(token)) {
if (indentStack.Count > 0) {
current = indentStack.Pop();
} else {
current = new LineInfo {
Indentation = GetLeadingWhiteSpace(token.Span.Start.GetContainingLine().GetText())
};
}
//.........这里部分代码省略.........
示例10: CurrentLineType
CodeLineType CurrentLineType(ITextSnapshotLine tsl)
{
if(tsl == null)
{
throw new NullReferenceException();
}
string originStr = tsl.GetText();
//more types to be added, currently only normal or blank
if(Regex.IsMatch(originStr, rx_nonwhite))
{
//add more types here
return CodeLineType.Normal;
}
else return CodeLineType.Blank;
}
示例11: GetIndentation
/// <summary>
/// find how many tabs are there
/// </summary>
/// <param name="tsl"></param>
/// <returns></returns>
int GetIndentation(ITextSnapshotLine tsl)
{
if(tsl == null)
{
throw new NullReferenceException();
}
string originStr = tsl.GetText();
//position of first non-white
int firstNonWhite = Regex.Match(originStr, rx_nonwhite).Index;
string whiteString = originStr.Substring(0, firstNonWhite);
int tabCount = Regex.Matches(whiteString, rx_tab).Count;
int spaceCount = Regex.Matches(whiteString, rx_space).Count;
tabCount += spaceCount / tab_count;
return tabCount;
}
示例12: DeleteCommentChars
private static void DeleteCommentChars(ITextEdit edit, ITextSnapshotLine curLine) {
var text = curLine.GetText();
for (int j = 0; j < text.Length; j++) {
if (!Char.IsWhiteSpace(text[j])) {
if (text.Substring(j, 2) == "//") {
edit.Delete(curLine.Start.Position + j, 2);
}
break;
}
}
}
示例13: GetItemAtPosition
public static string GetItemAtPosition(ITextSnapshotLine line, int position, Func<RTokenType, bool> tokenTypeCheck, out Span span) {
string lineText = line.GetText();
var offset = 0;
var positionInTokens = position - line.Start;
var tokenizer = new RTokenizer();
var tokens = tokenizer.Tokenize(lineText);
var tokenIndex = tokens.GetItemContaining(positionInTokens);
if (tokenIndex >= 0) {
var token = tokens[tokenIndex];
if (token.TokenType == RTokenType.Comment) {
// Tokenize inside comment since we do want F1 to work inside
// commented out code, code samples or Roxygen blocks.
positionInTokens -= token.Start;
offset = token.Start + 1;
tokens = tokenizer.Tokenize(lineText.Substring(offset, token.Length - 1));
tokenIndex = tokens.GetItemContaining(positionInTokens);
if (tokenIndex >= 0) {
token = tokens[tokenIndex];
}
}
if (tokenTypeCheck(token.TokenType)) {
var start = token.Start + offset;
var end = Math.Min(start + token.Length, line.End);
span = Span.FromBounds(line.Start + start, line.Start + end); // return view span
return lineText.Substring(start, end - start);
}
}
span = Span.FromBounds(0, 0);
return string.Empty;
}
示例14: GetCommentIndent
private int GetCommentIndent(CommentType commentType, ITextSnapshotLine line) {
return line.GetText().IndexOf(commentType.Token, StringComparison.Ordinal);
}
示例15: GetCommentText
private string GetCommentText(CommentType commentType, ITextSnapshotLine line) {
return line.GetText().Substring(GetCommentIndent(commentType, line) + commentType.Token.Length).Trim();
}