本文整理汇总了C#中IDocumentLine类的典型用法代码示例。如果您正苦于以下问题:C# IDocumentLine类的具体用法?C# IDocumentLine怎么用?C# IDocumentLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDocumentLine类属于命名空间,在下文中一共展示了IDocumentLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
LineIndenter indenter = CreateLineIndenter(editor, line);
if (!indenter.Indent()) {
base.IndentLine(editor, line);
}
}
示例2: ModifyLineIndent
void ModifyLineIndent(ITextEditor editor, IDocumentLine line, bool increaseIndent)
{
string indentation = GetLineIndentation(editor, line.LineNumber - 1);
indentation = GetNewLineIndentation(indentation, editor.Options.IndentationString, increaseIndent);
string newIndentedText = indentation + line.Text;
editor.Document.Replace(line.Offset, line.Length, newIndentedText);
}
示例3: 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(this IDocument document, IDocumentLine 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 = line.Text;
if (oldLineText == newLineText)
return;
int pos = oldLineText.IndexOf(newLineTextTrim, StringComparison.Ordinal);
if (newLineTextTrim.Length > 0 && pos >= 0) {
using (document.OpenUndoGroup()) {
// 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));
}
} else {
document.Replace(line.Offset, line.Length, newLineText);
}
}
示例4: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
if (line.LineNumber == 1) {
base.IndentLine(editor, line);
return;
}
IDocument document = editor.Document;
IDocumentLine previousLine = document.GetLine(line.LineNumber - 1);
string previousLineText = previousLine.Text.Trim();
if (previousLineText.EndsWith(":")) {
IncreaseLineIndent(editor, line);
} else if (previousLineText == "pass") {
DecreaseLineIndent(editor, line);
} else if ((previousLineText == "return") || (previousLineText.StartsWith("return "))) {
DecreaseLineIndent(editor, line);
} else if ((previousLineText == "raise") || (previousLineText.StartsWith("raise "))) {
DecreaseLineIndent(editor, line);
} else if (previousLineText == "break") {
DecreaseLineIndent(editor, line);
} else {
base.IndentLine(editor, line);
}
}
示例5: IsBracketOnly
bool IsBracketOnly(IDocument document, IDocumentLine documentLine)
{
string lineText = document.GetText(documentLine).Trim();
return lineText == "{" || string.IsNullOrEmpty(lineText)
|| lineText.StartsWith("//", StringComparison.Ordinal)
|| lineText.StartsWith("/*", StringComparison.Ordinal)
|| lineText.StartsWith("*", StringComparison.Ordinal)
|| lineText.StartsWith("'", StringComparison.Ordinal);
}
示例6: RubyLineIndenter
public RubyLineIndenter(ITextEditor editor, IDocumentLine line)
: base(editor, line)
{
CreateDecreaseLineIndentStatements();
CreateDecreaseLineIndentStartsWithStatements();
CreateIncreaseLineIndentStatements();
CreateIncreaseLineIndentStartsWithStatements();
CreateIncreaseLineIndentEndsWithStatements();
CreateIncreaseLineIndentContainsStatements();
}
示例7: ScanLine
/// <summary>
/// Updates <see cref="CurrentSpanStack"/> for the specified line in the specified document.
///
/// Before calling this method, <see cref="CurrentSpanStack"/> must be set to the proper
/// state for the beginning of this line. After highlighting has completed,
/// <see cref="CurrentSpanStack"/> will be updated to represent the state after the line.
/// </summary>
public void ScanLine(IDocument document, IDocumentLine line)
{
//this.lineStartOffset = line.Offset; not necessary for scanning
this.lineText = document.GetText(line);
try {
Debug.Assert(highlightedLine == null);
HighlightLineInternal();
} finally {
this.lineText = null;
}
}
示例8: IndentSingleLine
static void IndentSingleLine(CacheIndentEngine engine, IDocument document, IDocumentLine line)
{
engine.Update(line.EndOffset);
if (engine.NeedsReindent) {
var indentation = TextUtilities.GetWhitespaceAfter(document, line.Offset);
// replacing the indentation in two steps is necessary to make the caret move accordingly.
document.Replace(indentation.Offset, indentation.Length, "");
document.Replace(indentation.Offset, 0, engine.ThisLineIndent);
engine.ResetEngineToPosition(line.Offset);
}
}
示例9: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
editor.Document.StartUndoableAction();
try {
TryIndent(editor, line.LineNumber, line.LineNumber);
} catch (XmlException ex) {
LoggingService.Debug(ex.ToString());
} finally {
editor.Document.EndUndoableAction();
}
}
示例10: IndentLine
public virtual void IndentLine(ITextEditor editor, IDocumentLine line)
{
IDocument document = editor.Document;
int lineNumber = line.LineNumber;
if (lineNumber > 1) {
IDocumentLine previousLine = document.GetLineByNumber(lineNumber - 1);
string indentation = DocumentUtilities.GetWhitespaceAfter(document, previousLine.Offset);
// copy indentation to line
string newIndentation = DocumentUtilities.GetWhitespaceAfter(document, line.Offset);
document.Replace(line.Offset, newIndentation.Length, indentation);
}
}
示例11: IsInsideDocumentationComment
public static bool IsInsideDocumentationComment(ITextEditor editor, IDocumentLine curLine, int cursorOffset)
{
for (int i = curLine.Offset; i < cursorOffset; ++i) {
char ch = editor.Document.GetCharAt(i);
if (ch == '"')
return false;
if (ch == '\'' && i + 2 < cursorOffset && editor.Document.GetCharAt(i + 1) == '\'' &&
editor.Document.GetCharAt(i + 2) == '\'')
return true;
}
return false;
}
示例12: HighlightLine
/// <summary>
/// Highlights the specified line in the specified document.
///
/// Before calling this method, <see cref="CurrentSpanStack"/> must be set to the proper
/// state for the beginning of this line. After highlighting has completed,
/// <see cref="CurrentSpanStack"/> will be updated to represent the state after the line.
/// </summary>
public HighlightedLine HighlightLine(IDocument document, IDocumentLine line)
{
this.lineStartOffset = line.Offset;
this.lineText = document.GetText(line);
try {
this.highlightedLine = new HighlightedLine(document, line);
HighlightLineInternal();
return this.highlightedLine;
} finally {
this.highlightedLine = null;
this.lineText = null;
this.lineStartOffset = 0;
}
}
示例13: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
int lineNr = line.LineNumber;
DocumentAccessor acc = new DocumentAccessor(editor.Document, lineNr, lineNr);
CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();
indentStrategy.IndentationString = editor.Options.IndentationString;
indentStrategy.Indent(acc, false);
string t = acc.Text;
if (t.Length == 0) {
// use AutoIndentation for new lines in comments / verbatim strings.
base.IndentLine(editor, line);
}
}
示例14: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
if (line.LineNumber > 1)
{
IDocumentLine above = editor.Document.GetLine(line.LineNumber - 1);
string up = above.Text.Trim();
if (up.StartsWith("--") == false)
{
// above line is an indent statement
if (up.EndsWith("do")
|| up.EndsWith("then")
|| (up.StartsWith("function") && up.EndsWith(")"))
|| (up.Contains("function") && up.EndsWith(")"))) // e.g. aTable.x = function([...])
{
string indentation = DocumentUtilitites.GetWhitespaceAfter(editor.Document, above.Offset);
string newLine = line.Text.TrimStart();
newLine = indentation + editor.Options.IndentationString + newLine;
editor.Document.SmartReplaceLine(line, newLine);
}
else // above line is not an indent statement
{
string indentation = DocumentUtilitites.GetWhitespaceAfter(editor.Document, above.Offset);
string newLine = line.Text.TrimStart();
newLine = indentation + newLine;
editor.Document.SmartReplaceLine(line, newLine);
}
}
if (line.Text.StartsWith("end"))
{
string indentation = DocumentUtilitites.GetWhitespaceAfter(editor.Document, above.Offset);
string newLine = line.Text.TrimStart();
string newIndent = "";
if (indentation.Length >= editor.Options.IndentationSize)
newIndent = indentation.Substring(0, indentation.Length - editor.Options.IndentationSize);
newLine = newIndent + newLine;
editor.Document.SmartReplaceLine(line, newLine);
}
}
else
{
}
//base.IndentLine(editor, line);
}
示例15: IndentLine
public override void IndentLine(ITextEditor editor, IDocumentLine line)
{
IDocument document = editor.Document;
int lineNumber = line.LineNumber;
if (lineNumber > 1) {
IDocumentLine previousLine = document.GetLine(line.LineNumber - 1);
if (previousLine.Text.EndsWith(":", StringComparison.Ordinal)) {
string indentation = DocumentUtilitites.GetWhitespaceAfter(document, previousLine.Offset);
indentation += editor.Options.IndentationString;
string newIndentation = DocumentUtilitites.GetWhitespaceAfter(document, line.Offset);
document.Replace(line.Offset, newIndentation.Length, indentation);
return;
}
}
base.IndentLine(editor, line);
}