本文整理汇总了C#中Mono.TextEditor.TextDocument.LocationToOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.LocationToOffset方法的具体用法?C# TextDocument.LocationToOffset怎么用?C# TextDocument.LocationToOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextDocument
的用法示例。
在下文中一共展示了TextDocument.LocationToOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
protected override void Run (object dataItem)
{
base.Run (dataItem);
if (IdeApp.Workspace == null) return;
if (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.FileName == FilePath.Null) return;
var document = IdeApp.Workbench.ActiveDocument;
ResolveResult resolveResult = null;
object item = CurrentRefactoryOperationsHandler.GetItem (document, out resolveResult);
IMethod method = item as IMethod;
if (method == null)
return;
ISearchProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
ThreadPool.QueueUserWorkItem((data) =>
{
try
{
ImplementationsFinder.Find(method, implementation =>
{
FileProvider fileProvider = new FileProvider(implementation.Region.FileName);
TextDocument doc = new TextDocument();
doc.Text = fileProvider.ReadString();
int offset = doc.LocationToOffset(implementation.Region.BeginLine, implementation.Region.BeginColumn);
while ((offset + implementation.Name.Length) < doc.TextLength)
{
if (doc.GetTextAt(offset, implementation.Name.Length) == implementation.Name)
{
break;
}
offset++;
}
monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult(fileProvider, offset, implementation.Name.Length));
});
}
catch (Exception exception)
{
if (monitor != null)
{
monitor.ReportError("Error finding references", exception);
}
else
{
LoggingService.LogError("Error finding references", exception);
}
}
finally
{
if (monitor != null)
{
monitor.Dispose();
}
}
});
}
示例2: GetJumpTypePartSearchResult
static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult (IUnresolvedTypeDefinition part)
{
var provider = new MonoDevelop.Ide.FindInFiles.FileProvider (part.Region.FileName);
var doc = new Mono.TextEditor.TextDocument ();
doc.Text = provider.ReadString ();
int position = doc.LocationToOffset (part.Region.BeginLine, part.Region.BeginColumn);
while (position + part.Name.Length < doc.TextLength) {
if (doc.GetTextAt (position, part.Name.Length) == part.Name)
break;
position++;
}
return new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length);
}
示例3: GetInsertionPosition
static InsertionPoint GetInsertionPosition (TextDocument doc, int line, int column)
{
int bodyEndOffset = doc.LocationToOffset (line, column) + 1;
DocumentLine curLine = doc.GetLine (line);
if (curLine != null) {
if (bodyEndOffset < curLine.Offset + curLine.Length) {
// case1: positition is somewhere inside the start line
return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine);
}
}
// -> if position is at line end check next line
DocumentLine nextLine = doc.GetLine (line + 1);
if (nextLine == null) // check for 1 line case.
return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine);
for (int i = nextLine.Offset; i < nextLine.Offset + nextLine.Length; i++) {
char ch = doc.GetCharAt (i);
if (!char.IsWhiteSpace (ch)) {
// case2: next line contains non ws chars.
return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine);
}
}
// case3: whitespace line
return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.None);
}