本文整理汇总了C#中TextEditor.GetLine方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.GetLine方法的具体用法?C# TextEditor.GetLine怎么用?C# TextEditor.GetLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.GetLine方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CorrectIndentingImplementation
protected override void CorrectIndentingImplementation (PolicyContainer policyParent, TextEditor editor, int line)
{
var lineSegment = editor.GetLine (line);
if (lineSegment == null)
return;
try {
var policy = policyParent.Get<CSharpFormattingPolicy> (MimeType);
var textpolicy = policyParent.Get<TextStylePolicy> (MimeType);
var tracker = new CSharpIndentEngine (policy.CreateOptions (textpolicy));
tracker.Update (IdeApp.Workbench.ActiveDocument.Editor, lineSegment.Offset);
for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++) {
tracker.Push (editor.GetCharAt (i));
}
string curIndent = lineSegment.GetIndentation (editor);
int nlwsp = curIndent.Length;
if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && editor.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
// Possibly replace the indent
string newIndent = tracker.ThisLineIndent;
if (newIndent != curIndent)
editor.ReplaceText (lineSegment.Offset, nlwsp, newIndent);
}
} catch (Exception e) {
LoggingService.LogError ("Error while indenting", e);
}
}
示例2:
void IActionTextLineMarker.MouseHover (TextEditor editor, MarginMouseEventArgs args, TextLineMarkerHoverResult result)
{
if (args.Button != 0)
return;
var line = editor.GetLine (loc.Line);
var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value;
var y = editor.LineToY (line.LineNumber) - editor.VAdjustment.Value;
if (args.X - x >= 0 * editor.Options.Zoom &&
args.X - x < tagMarkerWidth * editor.Options.Zoom &&
y - args.Y < (tagMarkerHeight) * editor.Options.Zoom) {
result.Cursor = arrowCursor;
Popup ();
} else {
codeActionEditorExtension.CancelSmartTagPopupTimeout ();
}
}
示例3: Draw
public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
{
var line = editor.GetLine (loc.Line);
var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;
cr.Rectangle (Math.Floor (x) + 0.5, Math.Floor (y) + 0.5 + (line == editor.GetLineByOffset (startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);
if (HslColor.Brightness (editor.ColorStyle.PlainText.Background) < 0.5) {
cr.Color = new Cairo.Color (0.8, 0.8, 1, 0.9);
} else {
cr.Color = new Cairo.Color (0.2, 0.2, 1, 0.9);
}
cr.Stroke ();
}
示例4: FixLineStart
public bool FixLineStart (TextEditor textEditorData, ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine stateTracker, int lineNumber)
{
if (lineNumber > 1) {
var line = textEditorData.GetLine (lineNumber);
if (line == null)
return false;
var prevLine = textEditorData.GetLine (lineNumber - 1);
if (prevLine == null)
return false;
string trimmedPreviousLine = textEditorData.GetTextAt (prevLine).TrimStart ();
//xml doc comments
//check previous line was a doc comment
//check there's a following line?
if (trimmedPreviousLine.StartsWith ("///", StringComparison.Ordinal)) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("///", StringComparison.Ordinal))
return false;
//check that the newline command actually inserted a newline
textEditorData.EnsureCaretIsNotVirtual ();
var nextLineSegment = textEditorData.GetLine (lineNumber + 1);
string nextLine = nextLineSegment != null ? textEditorData.GetTextAt (nextLineSegment).TrimStart () : "";
if (trimmedPreviousLine.Length > "///".Length || nextLine.StartsWith ("///", StringComparison.Ordinal)) {
var insertionPoint = textEditorData.CaretOffset;
textEditorData.InsertText (insertionPoint, "/// ");
textEditorData.CaretOffset = insertionPoint + "/// ".Length;
return true;
}
//multi-line comments
} else if (stateTracker.IsInsideMultiLineComment) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("*", StringComparison.Ordinal))
return false;
textEditorData.EnsureCaretIsNotVirtual ();
string commentPrefix = string.Empty;
if (trimmedPreviousLine.StartsWith ("* ", StringComparison.Ordinal)) {
commentPrefix = "* ";
} else if (trimmedPreviousLine.StartsWith ("/**", StringComparison.Ordinal) || trimmedPreviousLine.StartsWith ("/*", StringComparison.Ordinal)) {
commentPrefix = " * ";
} else if (trimmedPreviousLine.StartsWith ("*", StringComparison.Ordinal)) {
commentPrefix = "*";
}
int indentSize = line.GetIndentation (textEditorData).Length;
var insertedText = prevLine.GetIndentation (textEditorData) + commentPrefix;
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
textEditorData.CaretOffset = line.Offset + insertedText.Length;
return true;
} else if (wasInStringLiteral) {
var lexer = new ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngineBase.MiniLexer (textEditorData.GetTextAt (0, prevLine.EndOffset).TrimEnd ());
lexer.Parse ();
if (!lexer.IsInString)
return false;
textEditorData.EnsureCaretIsNotVirtual ();
textEditorData.InsertText (prevLine.Offset + prevLine.Length, "\" +");
int indentSize = textEditorData.CaretOffset - line.Offset;
var insertedText = prevLine.GetIndentation (textEditorData) + (trimmedPreviousLine.StartsWith ("\"", StringComparison.Ordinal) ? "" : "\t") + "\"";
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
return true;
}
}
return false;
}
示例5: LimitColumn
static DocumentLocation LimitColumn (TextEditor data, DocumentLocation loc)
{
return new DocumentLocation (loc.Line, System.Math.Min (loc.Column, data.GetLine (loc.Line).Length + 1));
}
示例6: ExpandSelectionToLine
public static void ExpandSelectionToLine (TextEditor textEditor)
{
// from Mono.TextEditor.SelectionActions.ExpandSelectionToLine
using (var undoGroup = textEditor.OpenUndoGroup ()) {
var curLineSegment = textEditor.GetLine (textEditor.CaretLine).SegmentIncludingDelimiter;
var range = textEditor.SelectionRange;
var selection = TextSegment.FromBounds (
System.Math.Min (range.Offset, curLineSegment.Offset),
System.Math.Max (range.EndOffset, curLineSegment.EndOffset));
textEditor.CaretOffset = selection.EndOffset;
textEditor.SelectionRange = selection;
}
}
示例7: DuplicateCurrentLine
public static void DuplicateCurrentLine (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.DuplicateLine
using (var undoGroup = textEditor.OpenUndoGroup ()) {
if (textEditor.IsSomethingSelected) {
var selectedText = textEditor.SelectedText;
textEditor.ClearSelection ();
textEditor.InsertAtCaret (selectedText);
} else {
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
textEditor.InsertText (line.Offset, textEditor.GetTextAt (line.SegmentIncludingDelimiter));
}
}
}
示例8: TransposeCharacters
public static void TransposeCharacters (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.TransposeCharacters
if (textEditor.CaretOffset == 0)
return;
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
using (var undoGroup = textEditor.OpenUndoGroup ()) {
int transposeOffset = textEditor.CaretOffset - 1;
char ch;
if (textEditor.CaretColumn == 0) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
if (lineAbove.Length == 0 && line.Length == 0)
return;
if (line.Length != 0) {
ch = textEditor.GetCharAt (textEditor.CaretOffset);
textEditor.RemoveText (textEditor.CaretOffset, 1);
textEditor.InsertText (lineAbove.Offset + lineAbove.Length, ch.ToString ());
return;
}
int lastCharOffset = lineAbove.Offset + lineAbove.Length - 1;
ch = textEditor.GetCharAt (lastCharOffset);
textEditor.RemoveText (lastCharOffset, 1);
textEditor.InsertAtCaret (ch.ToString ());
return;
}
int offset = textEditor.CaretOffset;
if (textEditor.CaretColumn >= line.Length + 1) {
offset = line.Offset + line.Length - 1;
transposeOffset = offset - 1;
// case one char in line:
if (transposeOffset < line.Offset) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
transposeOffset = lineAbove.Offset + lineAbove.Length;
ch = textEditor.GetCharAt (offset);
textEditor.RemoveText (offset, 1);
textEditor.InsertText (transposeOffset, ch.ToString ());
textEditor.CaretOffset = line.Offset;
return;
}
}
ch = textEditor.GetCharAt (offset);
textEditor.ReplaceText (offset, 1, textEditor.GetCharAt (transposeOffset).ToString ());
textEditor.ReplaceText (transposeOffset, 1, ch.ToString ());
if (textEditor.CaretColumn < line.Length + 1)
textEditor.CaretOffset = offset + 1;
}
}
示例9:
void IActionTextLineMarker.MouseHover (TextEditor editor, MarginMouseEventArgs args, TextLineMarkerHoverResult result)
{
if (args.Button != 0)
return;
var line = editor.GetLine (loc.Line);
if (line == null)
return;
var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.TextStartPosition;
var y = editor.LineToY (line.LineNumber + 1) - editor.VAdjustment.Value;
if (args.X - x >= 0 * editor.Options.Zoom &&
args.X - x < tagMarkerWidth * editor.Options.Zoom &&
args.Y - y < (editor.LineHeight / 2) * editor.Options.Zoom) {
result.Cursor = null;
Popup ();
} else {
codeActionEditorExtension.CancelSmartTagPopupTimeout ();
}
}
示例10: Format
static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, TextEditor editor, DocumentContext context, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false, OptionSet optionSet = null)
{
TextSpan span;
if (exact) {
span = new TextSpan (startOffset, endOffset - startOffset);
} else {
span = new TextSpan (0, endOffset);
}
var analysisDocument = context.AnalysisDocument;
if (analysisDocument == null)
return;
using (var undo = editor.OpenUndoGroup (/*OperationType.Format*/)) {
try {
var syntaxTree = analysisDocument.GetSyntaxTreeAsync ().Result;
if (formatLastStatementOnly) {
var root = syntaxTree.GetRoot ();
var token = root.FindToken (endOffset);
var tokens = ICSharpCode.NRefactory6.CSharp.FormattingRangeHelper.FindAppropriateRange (token);
if (tokens.HasValue) {
span = new TextSpan (tokens.Value.Item1.SpanStart, tokens.Value.Item2.Span.End - tokens.Value.Item1.SpanStart);
} else {
var parent = token.Parent;
if (parent != null)
span = parent.FullSpan;
}
}
if (optionSet == null) {
var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
optionSet = policy.CreateOptions (textPolicy);
}
var doc = Formatter.FormatAsync (analysisDocument, span, optionSet).Result;
var newTree = doc.GetSyntaxTreeAsync ().Result;
var caretOffset = editor.CaretOffset;
int delta = 0;
foreach (var change in newTree.GetChanges (syntaxTree)) {
if (!exact && change.Span.Start + delta >= caretOffset)
continue;
var newText = change.NewText;
editor.ReplaceText (delta + change.Span.Start, change.Span.Length, newText);
delta = delta - change.Span.Length + newText.Length;
}
if (startOffset < caretOffset) {
var caretEndOffset = caretOffset + delta;
if (0 <= caretEndOffset && caretEndOffset < editor.Length)
editor.CaretOffset = caretEndOffset;
if (editor.CaretColumn == 1) {
if (editor.CaretLine > 1 && editor.GetLine (editor.CaretLine - 1).Length == 0)
editor.CaretLine--;
editor.CaretColumn = editor.GetVirtualIndentationColumn (editor.CaretLine);
}
}
} catch (Exception e) {
LoggingService.LogError ("Error in on the fly formatter", e);
}
}
}
示例11: GetSelectedLines
static IEnumerable<IDocumentLine> GetSelectedLines (TextEditor Editor)
{
if (!Editor.IsSomethingSelected) {
yield return Editor.GetLine (Editor.CaretLine);
yield break;
}
var selection = Editor.SelectionRegion;
var line = Editor.GetLine(selection.EndLine);
if (selection.EndColumn == 1)
line = line.PreviousLine;
while (line != null && line.LineNumber >= selection.BeginLine) {
yield return line;
line = line.PreviousLine;
}
}
示例12:
void IActionTextLineMarker.MouseHover (TextEditor editor, MarginMouseEventArgs args, TextLineMarkerHoverResult result)
{
if (args.Button != 0)
return;
var line = editor.GetLine (loc.Line);
var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value;
var y = editor.LineToY (line.LineNumber) - editor.VAdjustment.Value;
if (args.X - x >= 0 * editor.Options.Zoom &&
args.X - x < tagMarkerWidth * editor.Options.Zoom &&
y - args.Y < (tagMarkerHeight) * editor.Options.Zoom) {
Popup ();
}
}
示例13: DrawLine
void DrawLine (Cairo.Context g, TextEditor editor, int lineNumber, ref int y)
{
using (var drawingLayout = new Pango.Layout (this.PangoContext)) {
drawingLayout.FontDescription = fontDescription;
var line = editor.GetLine (lineNumber);
var correctedIndentLength = CorrectIndent (editor, line, indentLength);
drawingLayout.SetMarkup (editor.GetPangoMarkup (line.Offset + Math.Min (correctedIndentLength, line.Length), Math.Max (0, line.Length - correctedIndentLength)));
g.Save ();
g.Translate (textBorder, y);
g.ShowLayout (drawingLayout);
g.Restore ();
y += lineHeight;
}
}
示例14: AddRegisterDirective
public void AddRegisterDirective (WebFormsPageInfo.RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
{
if (doc == null)
return;
var node = GetRegisterInsertionPointNode ();
if (node == null)
return;
doc.Info.RegisteredTags.Add (directive);
var line = Math.Max (node.Region.EndLine, node.Region.BeginLine);
var pos = editor.LocationToOffset (line, editor.GetLine (line - 1).Length);
if (pos < 0)
return;
using (var undo = editor.OpenUndoGroup ()) {
var oldCaret = editor.CaretOffset;
var text = editor.FormatString (pos, editor.EolMarker + directive);
var inserted = text.Length;
editor.InsertText (pos, text);
if (preserveCaretPosition) {
editor.CaretOffset = (pos < oldCaret)? oldCaret + inserted : oldCaret;
}
}
}