本文整理汇总了C#中ICSharpCode.TextEditor.Document.LineSegment类的典型用法代码示例。如果您正苦于以下问题:C# LineSegment类的具体用法?C# LineSegment怎么用?C# LineSegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LineSegment类属于ICSharpCode.TextEditor.Document命名空间,在下文中一共展示了LineSegment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BookmarkDocumentChanged
void BookmarkDocumentChanged(object sender, EventArgs e)
{
if (bookmark.Document != null) {
line = bookmark.Document.GetLineSegment(Math.Min(bookmark.LineNumber, bookmark.Document.TotalNumberOfLines));
Text = positionText + bookmark.Document.GetText(line);
}
}
示例2: DrawableLine
public DrawableLine(IDocument document, LineSegment line, Font monospacedFont, Font boldMonospacedFont)
{
this.monospacedFont = monospacedFont;
this.boldMonospacedFont = boldMonospacedFont;
if (line.Words != null)
{
foreach (TextWord word in line.Words)
{
if (word.Type == TextWordType.Space)
{
words.Add(SimpleTextWord.Space);
}
else if (word.Type == TextWordType.Tab)
{
words.Add(SimpleTextWord.Tab);
}
else
{
words.Add(new SimpleTextWord(TextWordType.Word, word.Word, word.Bold, word.Color));
}
}
}
else
{
words.Add(new SimpleTextWord(TextWordType.Word, document.GetText(line), false, Color.Black));
}
}
示例3: IsInMultilineCommentOrStringLiteral
static bool IsInMultilineCommentOrStringLiteral(LineSegment line)
{
if (line.HighlightSpanStack == null || line.HighlightSpanStack.IsEmpty) {
return false;
}
return !line.HighlightSpanStack.Peek().StopEOL;
}
示例4: TryHighlightAddedAndDeletedLines
protected override int TryHighlightAddedAndDeletedLines(IDocument document, int line, LineSegment lineSegment)
{
ProcessLineSegment(document, ref line, lineSegment, "++", AppSettings.DiffAddedColor);
ProcessLineSegment(document, ref line, lineSegment, "+ ", AppSettings.DiffAddedColor);
ProcessLineSegment(document, ref line, lineSegment, " +", AppSettings.DiffAddedColor);
ProcessLineSegment(document, ref line, lineSegment, "--", AppSettings.DiffRemovedColor);
ProcessLineSegment(document, ref line, lineSegment, "- ", AppSettings.DiffRemovedColor);
ProcessLineSegment(document, ref line, lineSegment, " -", AppSettings.DiffRemovedColor);
return line;
}
示例5:
/// <summary>
/// Get the object, which was inserted under the keyword (line, at offset, with length length),
/// returns null, if no such keyword was inserted.
/// </summary>
public object this[IDocument document, LineSegment line, int offset, int length]
{
get
{
if(length == 0)
{
return null;
}
Node next = root;
int wordOffset = line.Offset + offset;
if (casesensitive)
{
for (int i = 0; i < length; ++i)
{
int index = ((int)document.GetCharAt(wordOffset + i)) % 256;
next = next[index];
if (next == null)
{
return null;
}
if (next.color != null && TextUtility.RegionMatches(document, wordOffset, length, next.word))
{
return next.color;
}
}
}
else
{
for (int i = 0; i < length; ++i)
{
int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256;
next = next[index];
if (next == null)
{
return null;
}
if (next.color != null && TextUtility.RegionMatches(document, casesensitive, wordOffset, length, next.word))
{
return next.color;
}
}
}
return null;
}
}
示例6: MarkWords
protected override void MarkWords(int lineNumber, LineSegment currentLine, List<TextWord> words)
{
if (IsInMultilineCommentOrStringLiteral(currentLine)) {
return;
}
ParseInformation parseInfo = ParserService.GetParseInformation(this.TextEditor.FileName);
if (parseInfo == null) return;
CSharpExpressionFinder finder = new CSharpExpressionFinder(parseInfo);
Func<string, int, ExpressionResult> findExpressionMethod;
IClass callingClass = parseInfo.MostRecentCompilationUnit.GetInnermostClass(lineNumber, 0);
if (callingClass != null) {
if (GetCurrentMember(callingClass, lineNumber, 0) != null) {
findExpressionMethod = finder.FindFullExpressionInMethod;
} else {
findExpressionMethod = finder.FindFullExpressionInTypeDeclaration;
}
} else {
findExpressionMethod = finder.FindFullExpression;
}
string lineText = this.Document.GetText(currentLine.Offset, currentLine.Length);
bool changedLine = false;
// now go through the word list:
foreach (TextWord word in words) {
if (word.IsWhiteSpace) continue;
if (char.IsLetter(lineText[word.Offset]) || lineText[word.Offset] == '_') {
ExpressionResult result = findExpressionMethod(lineText, word.Offset);
if (result.Expression != null) {
// result.Expression
if (ICSharpCode.NRefactory.Parser.CSharp.Keywords.IsNonIdentifierKeyword(result.Expression))
continue;
// convert text editor to DOM coordinates:
resolveCount++;
ResolveResult rr = ParserService.Resolve(result, lineNumber + 1, word.Offset + 1, this.TextEditor.FileName, this.TextEditor.Text);
if (rr is MixedResolveResult || rr is TypeResolveResult) {
changedLine = true;
word.SyntaxColor = this.Document.HighlightingStrategy.GetColorFor("TypeReference");
} else if (rr == null) {
changedLine = true;
word.SyntaxColor = this.Document.HighlightingStrategy.GetColorFor("UnknownEntity");
}
}
}
}
if (markingOutstanding && changedLine) {
this.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber));
}
}
示例7: TextWord
// TAB
public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
{
if (document == null || line == null || color == null)
throw new Exception();
/*Debug.Assert(document != null);
Debug.Assert(line != null);
Debug.Assert(color != null);
*/
this.document = document;
this.line = line;
this.offset = offset;
this.length = length;
this.color = color;
this.hasDefaultColor = hasDefaultColor;
}
示例8: SmartReplaceLine
/// <summary>
/// Replaces the text in a line.
/// If only whitespace at the beginning and end of the line was changed, this method
/// only adjusts the whitespace and doesn't replace the other text.
/// </summary>
public static void SmartReplaceLine(IDocument document, LineSegment line, string newLineText)
{
if (document == null)
throw new ArgumentNullException("document");
if (line == null)
throw new ArgumentNullException("line");
if (newLineText == null)
throw new ArgumentNullException("newLineText");
string newLineTextTrim = newLineText.Trim(whitespaceChars);
string oldLineText = document.GetText(line);
if (oldLineText == newLineText)
return;
int pos = oldLineText.IndexOf(newLineTextTrim);
if (newLineTextTrim.Length > 0 && pos >= 0)
{
document.UndoStack.StartUndoGroup();
try
{
// find whitespace at beginning
int startWhitespaceLength = 0;
while (startWhitespaceLength < newLineText.Length)
{
char c = newLineText[startWhitespaceLength];
if (c != ' ' && c != '\t')
break;
startWhitespaceLength++;
}
// find whitespace at end
int endWhitespaceLength = newLineText.Length - newLineTextTrim.Length - startWhitespaceLength;
// replace whitespace sections
int lineOffset = line.Offset;
document.Replace(lineOffset + pos + newLineTextTrim.Length, line.Length - pos - newLineTextTrim.Length, newLineText.Substring(newLineText.Length - endWhitespaceLength));
document.Replace(lineOffset, pos, newLineText.Substring(0, startWhitespaceLength));
}
finally
{
document.UndoStack.EndUndoGroup();
}
}
else
{
document.Replace(line.Offset, line.Length, newLineText);
}
}
示例9: MarkTokens
public void MarkTokens(IDocument document)
{
if (Rules.Count == 0) {
return;
}
int lineNumber = 0;
while (lineNumber < document.TotalNumberOfLines) {
LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);
if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
break; // then the last line is not in the collection :)
}
currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? new Stack<Span>(previousLine.HighlightSpanStack.ToArray()) : null);
if (currentSpanStack != null) {
while (currentSpanStack.Count > 0 && ((Span)currentSpanStack.Peek()).StopEOL)
{
currentSpanStack.Pop();
}
if (currentSpanStack.Count == 0) currentSpanStack = null;
}
currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];
if (currentLine.Length == -1) { // happens when buffer is empty !
return;
}
List<TextWord> words = ParseLine(document);
// Alex: clear old words
if (currentLine.Words != null) {
currentLine.Words.Clear();
}
currentLine.Words = words;
currentLine.HighlightSpanStack = (currentSpanStack==null || currentSpanStack.Count==0) ? null : currentSpanStack;
++lineNumber;
}
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
document.CommitUpdate();
currentLine = null;
}
示例10: TryDeclarationTypeInference
bool TryDeclarationTypeInference(SharpDevelopTextAreaControl editor, LineSegment curLine)
{
string lineText = editor.Document.GetText(curLine.Offset, curLine.Length);
ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.CSharp, new System.IO.StringReader(lineText));
Token typeToken = lexer.NextToken();
if (typeToken.kind == CSTokens.Question) {
if (lexer.NextToken().kind == CSTokens.Identifier) {
Token t = lexer.NextToken();
if (t.kind == CSTokens.Assign) {
string expr = lineText.Substring(t.col);
LoggingService.Debug("DeclarationTypeInference: >" + expr + "<");
ResolveResult rr = ParserService.Resolve(new ExpressionResult(expr),
editor.ActiveTextAreaControl.Caret.Line + 1,
t.col, editor.FileName,
editor.Document.TextContent);
if (rr != null && rr.ResolvedType != null) {
ClassFinder context = new ClassFinder(editor.FileName, editor.ActiveTextAreaControl.Caret.Line, t.col);
if (CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context))
CSharpAmbience.Instance.ConversionFlags = ConversionFlags.None;
else
CSharpAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames;
string typeName = CSharpAmbience.Instance.Convert(rr.ResolvedType);
editor.Document.Replace(curLine.Offset + typeToken.col - 1, 1, typeName);
editor.ActiveTextAreaControl.Caret.Column += typeName.Length - 1;
return true;
}
}
}
}
return false;
}
示例11: GetColor
HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
{
if (ruleSet != null) {
if (ruleSet.Reference != null) {
return ruleSet.Highlighter.GetColor(document, currentSegment, currentOffset, currentLength);
} else {
return (HighlightColor)ruleSet.KeyWords[document, currentSegment, currentOffset, currentLength];
}
}
return null;
}
示例12: SetSegmentLength
void SetSegmentLength(LineSegment segment, int newTotalLength)
{
int delta = newTotalLength - segment.TotalLength;
if (delta != 0) {
lineCollection.SetSegmentLength(segment, newTotalLength);
OnLineLengthChanged(new LineLengthChangeEventArgs(document, segment, delta));
}
}
示例13: GetLogicalColumnInternal
int GetLogicalColumnInternal(Graphics g, LineSegment line, int start, int end, ref int drawingPos, int targetVisualPosX)
{
if (start == end)
return end;
Debug.Assert(start < end);
Debug.Assert(drawingPos < targetVisualPosX);
int tabIndent = Document.TextEditorProperties.TabIndent;
/*float spaceWidth = SpaceWidth;
float drawingPos = 0;
LineSegment currentLine = Document.GetLineSegment(logicalLine);
List<TextWord> words = currentLine.Words;
if (words == null) return 0;
int wordCount = words.Count;
int wordOffset = 0;
FontContainer fontContainer = TextEditorProperties.FontContainer;
*/
FontContainer fontContainer = TextEditorProperties.FontContainer;
List<TextWord> words = line.Words;
if (words == null) return 0;
int wordOffset = 0;
for (int i = 0; i < words.Count; i++) {
TextWord word = words[i];
if (wordOffset >= end) {
return wordOffset;
}
if (wordOffset + word.Length >= start) {
int newDrawingPos;
switch (word.Type) {
case TextWordType.Space:
newDrawingPos = drawingPos + spaceWidth;
if (newDrawingPos >= targetVisualPosX)
return IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos) ? wordOffset : wordOffset+1;
break;
case TextWordType.Tab:
// go to next tab position
drawingPos = (int)((drawingPos + MinTabWidth) / tabIndent / WideSpaceWidth) * tabIndent * WideSpaceWidth;
newDrawingPos = drawingPos + tabIndent * WideSpaceWidth;
if (newDrawingPos >= targetVisualPosX)
return IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos) ? wordOffset : wordOffset+1;
break;
case TextWordType.Word:
int wordStart = Math.Max(wordOffset, start);
int wordLength = Math.Min(wordOffset + word.Length, end) - wordStart;
string text = Document.GetText(line.Offset + wordStart, wordLength);
Font font = word.GetFont(fontContainer) ?? fontContainer.RegularFont;
newDrawingPos = drawingPos + MeasureStringWidth(g, text, font);
if (newDrawingPos >= targetVisualPosX) {
for (int j = 0; j < text.Length; j++) {
newDrawingPos = drawingPos + MeasureStringWidth(g, text[j].ToString(), font);
if (newDrawingPos >= targetVisualPosX) {
if (IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos))
return wordStart + j;
else
return wordStart + j + 1;
}
drawingPos = newDrawingPos;
}
return wordStart + text.Length;
}
break;
default:
throw new NotSupportedException();
}
drawingPos = newDrawingPos;
}
wordOffset += word.Length;
}
return wordOffset;
}
示例14: MeasurePrintingHeight
// btw. I hate source code duplication ... but this time I don't care !!!!
float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
{
float xPos = 0;
float yPos = 0;
float fontHeight = Font.GetHeight(g);
// bool gotNonWhitespace = false;
curTabIndent = 0;
FontContainer fontContainer = TextEditorProperties.FontContainer;
foreach (TextWord word in line.Words) {
switch (word.Type) {
case TextWordType.Space:
Advance(ref xPos, ref yPos, maxWidth, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
// if (!gotNonWhitespace) {
// curTabIndent = xPos;
// }
break;
case TextWordType.Tab:
Advance(ref xPos, ref yPos, maxWidth, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight);
// if (!gotNonWhitespace) {
// curTabIndent = xPos;
// }
break;
case TextWordType.Word:
// if (!gotNonWhitespace) {
// gotNonWhitespace = true;
// curTabIndent += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' ');
// }
SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, fontHeight * 100), printingStringFormat);
Advance(ref xPos, ref yPos, maxWidth, drawingSize.Width, fontHeight);
break;
}
}
return yPos + fontHeight;
}
示例15: PrintWords
void PrintWords(LineSegment lineSegment, StringBuilder b)
{
string currentSpan = null;
foreach (TextWord word in lineSegment.Words) {
if (word.Type == TextWordType.Space) {
b.Append(' ');
} else if (word.Type == TextWordType.Tab) {
b.Append('\t');
} else {
string newSpan = GetStyle(word);
if (currentSpan != newSpan) {
if (currentSpan != null) b.Append("</span>");
if (newSpan != null) {
b.Append("<span");
WriteStyle(newSpan, b);
b.Append('>');
}
currentSpan = newSpan;
}
b.Append(HtmlEncode(word.Word));
}
}
if (currentSpan != null) b.Append("</span>");
}