本文整理汇总了C#中Mono.TextEditor.TextEditorData.LocationToOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.LocationToOffset方法的具体用法?C# TextEditorData.LocationToOffset怎么用?C# TextEditorData.LocationToOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.LocationToOffset方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInsertionPoints
public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IUnresolvedTypeDefinition type)
{
if (data == null)
throw new ArgumentNullException ("data");
if (parsedDocument == null)
throw new ArgumentNullException ("parsedDocument");
if (type == null)
throw new ArgumentNullException ("type");
// update type from parsed document, since this is always newer.
//type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type;
List<InsertionPoint> result = new List<InsertionPoint> ();
int offset = data.LocationToOffset (type.Region.Begin);
if (offset < 0 || type.BodyRegion.IsEmpty)
return result;
while (offset < data.Length && data.GetCharAt (offset) != '{') {
offset++;
}
var realStartLocation = data.OffsetToLocation (offset);
result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column));
result [0].LineBefore = NewLineInsertion.None;
foreach (var member in type.Members) {
TextLocation domLocation = member.BodyRegion.End;
if (domLocation.Line <= 0) {
DocumentLine lineSegment = data.GetLine (member.Region.BeginLine);
if (lineSegment == null)
continue;
domLocation = new TextLocation (member.Region.BeginLine, lineSegment.Length + 1);
}
result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
}
foreach (var nestedType in type.NestedTypes) {
TextLocation domLocation = nestedType.BodyRegion.End;
if (domLocation.Line <= 0) {
DocumentLine lineSegment = data.GetLine (nestedType.Region.BeginLine);
if (lineSegment == null)
continue;
domLocation = new TextLocation (nestedType.Region.BeginLine, lineSegment.Length + 1);
}
result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
}
result [result.Count - 1].LineAfter = NewLineInsertion.None;
CheckStartPoint (data.Document, result [0], result.Count == 1);
if (result.Count > 1) {
result.RemoveAt (result.Count - 1);
NewLineInsertion insertLine;
var lineBefore = data.GetLine (type.BodyRegion.EndLine - 1);
if (lineBefore != null && lineBefore.Length == lineBefore.GetIndentation (data.Document).Length) {
insertLine = NewLineInsertion.None;
} else {
insertLine = NewLineInsertion.Eol;
}
// search for line start
int col = type.BodyRegion.EndColumn - 1;
var line = data.GetLine (type.BodyRegion.EndLine);
if (line != null) {
while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2)))
col--;
}
result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol));
CheckEndPoint (data.Document, result [result.Count - 1], result.Count == 1);
}
foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) {
result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
}
result.Sort ((left, right) => left.Location.CompareTo (right.Location));
return result;
}
示例2: GetInsertionPoint
private InsertionPoint GetInsertionPoint(MonoDevelop.Ide.Gui.Document document, IType type)
{
data = document.Editor;
if (data == null) {
throw new System.ArgumentNullException ("data");
}
var parsedDocument = document.ParsedDocument;
if (parsedDocument == null) {
throw new System.ArgumentNullException ("parsedDocument");
}
if (type == null) {
throw new System.ArgumentNullException ("type");
}
type = (parsedDocument.CompilationUnit.GetTypeAt (type.Location) ?? type);
DomRegion domRegion = type.BodyRegion;
var start = type.BodyRegion.Start.Line;
indent = data.GetLine(start).GetIndentation(data.Document);
DomLocation domLocation = domRegion.End;
int num = data.LocationToOffset (domLocation.Line, 1);
while (num < data.Length && data.GetCharAt(num) != '}') {
num++;
}
num++;
DocumentLocation documentLocation = data.OffsetToLocation (num);
LineSegment lineAfterClassEnd = data.GetLine (domLocation.Line + 1);
NewLineInsertion lineAfter;
if (lineAfterClassEnd != null && lineAfterClassEnd.EditableLength == lineAfterClassEnd.GetIndentation (data.Document).Length)
lineAfter = NewLineInsertion.BlankLine;
else
lineAfter = NewLineInsertion.None;
return new InsertionPoint (documentLocation, NewLineInsertion.None, lineAfter);
}
示例3: Down
public static void Down (TextEditorData data)
{
//on Mac, when deselecting and moving up/down a line, column is always the column of the selection's start
if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
int col = data.MainSelection.Anchor > data.MainSelection.Lead ? data.MainSelection.Lead.Column : data.MainSelection.Anchor.Column;
int line = data.MainSelection.MaxLine + 1;
data.ClearSelection ();
if (line <= data.Document.LineCount) {
int offset = data.Document.LocationToOffset (line, col);
data.Caret.SetToOffsetWithDesiredColumn (MoveCaretOutOfFolding (data, offset));
} else {
data.Caret.Offset = data.Document.TextLength;
}
return;
}
if (data.Caret.Line < data.Document.LineCount) {
int nextLine = data.LogicalToVisualLine (data.Caret.Line) + 1;
int line = data.VisualToLogicalLine (nextLine);
int offset = MoveCaretOutOfFolding (data, data.LocationToOffset (line, data.Caret.Column), true);
data.Caret.SetToOffsetWithDesiredColumn (offset);
} else {
ToDocumentEnd (data);
}
}
示例4: PageUp
public static void PageUp (TextEditorData data)
{
int pageLines = (int)((data.VAdjustment.PageSize + ((int)data.VAdjustment.Value % data.LineHeight)) / data.LineHeight);
int visualLine = data.LogicalToVisualLine (data.Caret.Line);
visualLine -= pageLines;
int line = System.Math.Max (data.VisualToLogicalLine (visualLine), DocumentLocation.MinLine);
int offset = data.LocationToOffset (line, data.Caret.Column);
ScrollActions.PageUp (data);
data.Caret.Offset = MoveCaretOutOfFolding (data, offset);
}
示例5: IsFolded
public static bool IsFolded (TextEditorData data, int line, int column)
{
int offset = data.LocationToOffset (line, column);
return data.Document.GetFoldingsFromOffset (offset).Any (f => f.isFolded && f.Offset < offset && offset < f.EndOffset);
}
示例6: GetInsertionPoints
public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IType type)
{
if (data == null)
throw new ArgumentNullException ("data");
if (parsedDocument == null)
throw new ArgumentNullException ("parsedDocument");
if (type == null)
throw new ArgumentNullException ("type");
List<InsertionPoint> result = new List<InsertionPoint> ();
int offset = data.LocationToOffset (type.BodyRegion.Start.Line, type.BodyRegion.Start.Column);
if (offset < 0)
return result;
while (offset < data.Length && data.GetCharAt (offset) != '{') {
offset++;
}
var realStartLocation = data.OffsetToLocation (offset);
result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column));
result[0].LineBefore = NewLineInsertion.None;
foreach (IMember member in type.Members) {
DomLocation domLocation = member.BodyRegion.End;
if (domLocation.Line <= 0) {
LineSegment lineSegment = data.GetLine (member.Location.Line);
if (lineSegment == null)
continue;
domLocation = new DomLocation (member.Location.Line, lineSegment.EditableLength + 1);
}
result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
}
result[result.Count - 1].LineAfter = NewLineInsertion.None;
CheckStartPoint (data.Document, result[0], result.Count == 1);
if (result.Count > 1) {
result.RemoveAt (result.Count - 1);
NewLineInsertion insertLine;
var lineBefore = data.GetLine (type.BodyRegion.End.Line - 1);
if (lineBefore != null && lineBefore.EditableLength == lineBefore.GetIndentation (data.Document).Length) {
insertLine = NewLineInsertion.None;
} else {
insertLine = NewLineInsertion.Eol;
}
// search for line start
var line = data.GetLine (type.BodyRegion.End.Line);
int col = type.BodyRegion.End.Column - 1;
while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2)))
col--;
result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.End.Line, col), insertLine, NewLineInsertion.Eol));
CheckEndPoint (data.Document, result[result.Count - 1], result.Count == 1);
}
foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.Contains (r.Region))) {
result.Add (new InsertionPoint (new DocumentLocation (region.Region.Start.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
}
result.Sort ((left, right) => left.Location.CompareTo (right.Location));
return result;
}
示例7: ResolveExpression
public static string ResolveExpression (TextEditorData editor, ResolveResult result, AstNode node, out int startOffset)
{
//Console.WriteLine ("result is a {0}", result.GetType ().Name);
startOffset = -1;
if (result is NamespaceResolveResult ||
result is ConversionResolveResult ||
result is ConstantResolveResult ||
result is ForEachResolveResult ||
result is TypeIsResolveResult ||
result is TypeOfResolveResult ||
result is ErrorResolveResult)
return null;
if (result.IsCompileTimeConstant)
return null;
startOffset = editor.LocationToOffset (node.StartLocation.Line, node.StartLocation.Column);
if (result is InvocationResolveResult) {
var ir = (InvocationResolveResult) result;
if (ir.Member.Name == ".ctor") {
// if the user is hovering over something like "new Abc (...)", we want to show them type information for Abc
return ir.Member.DeclaringType.FullName;
}
// do not support general method invocation for tooltips because it could cause side-effects
return null;
} else if (result is LocalResolveResult) {
if (node is ParameterDeclaration) {
// user is hovering over a method parameter, but we don't want to include the parameter type
var param = (ParameterDeclaration) node;
return GetIdentifierName (editor, param.NameToken, out startOffset);
}
if (node is VariableInitializer) {
// user is hovering over something like "int fubar = 5;", but we don't want the expression to include the " = 5"
var variable = (VariableInitializer) node;
return GetIdentifierName (editor, variable.NameToken, out startOffset);
}
} else if (result is MemberResolveResult) {
var mr = (MemberResolveResult) result;
if (node is PropertyDeclaration) {
var prop = (PropertyDeclaration) node;
var name = GetIdentifierName (editor, prop.NameToken, out startOffset);
// if the property is static, then we want to return "Full.TypeName.Property"
if (prop.Modifiers.HasFlag (Modifiers.Static))
return mr.Member.DeclaringType.FullName + "." + name;
// otherwise we want to return "this.Property" so that it won't conflict with anything else in the local scope
return "this." + name;
}
if (node is FieldDeclaration) {
var field = (FieldDeclaration) node;
var name = GetIdentifierName (editor, field.NameToken, out startOffset);
// if the field is static, then we want to return "Full.TypeName.Field"
if (field.Modifiers.HasFlag (Modifiers.Static))
return mr.Member.DeclaringType.FullName + "." + name;
// otherwise we want to return "this.Field" so that it won't conflict with anything else in the local scope
return "this." + name;
}
if (node is VariableInitializer) {
// user is hovering over a field declaration that includes initialization
var variable = (VariableInitializer) node;
var name = GetIdentifierName (editor, variable.NameToken, out startOffset);
// walk up the AST to find the FieldDeclaration so that we can determine if it is static or not
var field = variable.GetParent<FieldDeclaration> ();
// if the field is static, then we want to return "Full.TypeName.Field"
if (field.Modifiers.HasFlag (Modifiers.Static))
return mr.Member.DeclaringType.FullName + "." + name;
// otherwise we want to return "this.Field" so that it won't conflict with anything else in the local scope
return "this." + name;
}
if (node is NamedExpression) {
// user is hovering over 'Property' in an expression like: var fubar = new Fubar () { Property = baz };
var variable = node.GetParent<VariableInitializer> ();
if (variable != null) {
var variableName = GetIdentifierName (editor, variable.NameToken, out startOffset);
var name = GetIdentifierName (editor, ((NamedExpression) node).NameToken, out startOffset);
return variableName + "." + name;
}
}
} else if (result is TypeResolveResult) {
return ((TypeResolveResult) result).Type.FullName;
}
return editor.GetTextBetween (node.StartLocation, node.EndLocation);
//.........这里部分代码省略.........
示例8: GetIdentifierName
static string GetIdentifierName (TextEditorData editor, Identifier id, out int startOffset)
{
startOffset = editor.LocationToOffset (id.StartLocation.Line, id.StartLocation.Column);
return editor.GetTextBetween (id.StartLocation, id.EndLocation);
}
示例9: ResolveExpression
public string ResolveExpression (TextEditorData ed, Document doc, int offset, out int startOffset)
{
startOffset = offset;
var editorData = DResolverWrapper.CreateEditorData(doc);
if (editorData == null)
return null;
editorData.CaretOffset = offset;
var edLoc = ed.OffsetToLocation(offset);
editorData.CaretLocation = new CodeLocation(edLoc.Column,edLoc.Line);
var o = DResolver.GetScopedCodeObject(editorData);
if (o != null) {
startOffset = ed.LocationToOffset (o.Location.Line, o.Location.Column);
if (o is INode)
return (o as INode).Name;
return o.ToString ();
}
return null;
}