本文整理汇总了C#中IDocument.GetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetOffset方法的具体用法?C# IDocument.GetOffset怎么用?C# IDocument.GetOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static SearchResultMatch Create(IDocument document, TextLocation startLocation, TextLocation endLocation, IHighlighter highlighter)
{
int startOffset = document.GetOffset(startLocation);
int endOffset = document.GetOffset(endLocation);
var inlineBuilder = SearchResultsPad.CreateInlineBuilder(startLocation, endLocation, document, highlighter);
var defaultTextColor = highlighter.DefaultTextColor;
return new SearchResultMatch(FileName.Create(document.FileName),
startLocation, endLocation,
startOffset, endOffset - startOffset,
inlineBuilder, defaultTextColor);
}
示例2: AttachTo
internal void AttachTo(IDocument document)
{
if (isDeleted)
return;
Debug.Assert(currentDocument == null && document != null);
this.currentDocument = document;
line = Math.Min(line, document.LineCount);
column = Math.Min(column, document.GetLineByNumber(line).Length + 1);
baseAnchor = document.CreateAnchor(document.GetOffset(line, column));
baseAnchor.MovementType = movementType;
baseAnchor.SurviveDeletion = surviveDeletion;
baseAnchor.Deleted += baseAnchor_Deleted;
}
示例3: TryFix
public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
{
var typeDeclaration = syntaxTree.GetNodeAt<DelegateDeclaration>(location);
if (typeDeclaration != null) {
if (typeDeclaration.RParToken.IsNull) {
var lastNode = GetLastNonErrorChild (typeDeclaration);
if (lastNode == null)
return false;
var insertionOffset = document.GetOffset(lastNode.EndLocation);
document.Insert(insertionOffset, ");\n");
newOffset += ");\n".Length;
return true;
}
}
return false;
}
示例4: Insert
public void Insert (IDocument document, string text)
{
int offset = document.GetOffset (Location);
using (var undo = document.OpenUndoGroup ()) {
text = DocumentUtilities.NormalizeNewLines(text, document, Location.Line);
var line = document.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (document, LineBefore, ref offset);
document.Insert (offset, text);
offset += text.Length;
InsertNewLine (document, LineAfter, ref offset);
}
}
示例5:
public static QuickFix ForFirstLineInRegion
(DomRegion region, IDocument document) {
// Note that we could display an arbitrary amount of
// context to the user: ranging from one line to tens,
// hundreds..
var text = document.GetText
( offset: document.GetOffset(region.BeginLine, column: 0)
, length: document.GetLineByNumber
(region.BeginLine).Length)
.Trim();
return new QuickFix
{ FileName = region.FileName
, Line = region.BeginLine
, Column = region.BeginColumn
, Text = text};
}
示例6: InsertWithCursorOnLayer
void InsertWithCursorOnLayer(EditorScript currentScript, InsertionCursorLayer layer, TaskCompletionSource<Script> tcs, IList<AstNode> nodes, IDocument target)
{
var doc = target as TextDocument;
var op = new UndoOperation(layer, tcs);
if (doc != null) {
doc.UndoStack.Push(op);
}
layer.Exited += delegate(object s, InsertionCursorEventArgs args) {
doc.UndoStack.StartContinuedUndoGroup();
try {
if (args.Success) {
if (args.InsertionPoint.LineAfter == NewLineInsertion.None &&
args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
}
foreach (var node in nodes.Reverse ()) {
int indentLevel = currentScript.GetIndentLevelAt(target.GetOffset(args.InsertionPoint.Location));
var output = currentScript.OutputNode(indentLevel, node);
var offset = target.GetOffset(args.InsertionPoint.Location);
var delta = args.InsertionPoint.Insert(target, output.Text);
output.RegisterTrackedSegments(currentScript, delta + offset);
}
tcs.SetResult(currentScript);
}
layer.Dispose();
DisposeOnClose();
} finally {
doc.UndoStack.EndUndoGroup();
}
op.Reset();
};
}
示例7: CreateProvider
static CompletionDataList CreateProvider (CSharpCompletionEngine engine, IDocument doc, TextLocation loc)
{
var cursorPosition = doc.GetOffset (loc);
var data = engine.GetCompletionData (cursorPosition, true);
return new CompletionDataList {
Data = data,
AutoCompleteEmptyMatch = engine.AutoCompleteEmptyMatch,
AutoSelect = engine.AutoSelect,
DefaultCompletionString = engine.DefaultCompletionString
};
}
示例8: ExtendSelectionToEndOfLineComments
/// <summary>
/// If there is a comment block behind selection on the same line ("var i = 5; // comment"), add it to selection.
/// </summary>
Selection ExtendSelectionToEndOfLineComments(IDocument document, TextLocation selectionStart, TextLocation selectionEnd, IEnumerable<AstNode> commentsBlankLines)
{
var lineComment = commentsBlankLines.FirstOrDefault(c => c.StartLocation.Line == selectionEnd.Line && c.StartLocation >= selectionEnd);
if (lineComment == null) {
return null;
}
// bool isWholeLineSelected = IsWhitespaceBetween(document, new TextLocation(selectionStart.Line, 1), selectionStart);
// if (!isWholeLineSelected) {
// // whole line must be selected before we add the comment
// return null;
// }
int endPos = document.GetOffset(lineComment.EndLocation);
return new Selection { Start = selectionStart, End = document.GetLocation(endPos) };
}
示例9: InsertWithCursorOnLayer
void InsertWithCursorOnLayer(EditorScript currentScript, InsertionCursorLayer layer, TaskCompletionSource<Script> tcs, IList<AstNode> nodes, IDocument target)
{
layer.Exited += delegate(object s, InsertionCursorEventArgs args) {
if (args.Success) {
if (args.InsertionPoint.LineAfter == NewLineInsertion.None &&
args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
}
foreach (var node in nodes.Reverse ()) {
int indentLevel = currentScript.GetIndentLevelAt(target.GetOffset(args.InsertionPoint.Location));
var output = currentScript.OutputNode(indentLevel, node);
var offset = target.GetOffset(args.InsertionPoint.Location);
var delta = args.InsertionPoint.Insert(target, output.Text);
output.RegisterTrackedSegments(currentScript, delta + offset);
}
tcs.SetResult(currentScript);
}
layer.Dispose();
DisposeOnClose();
};
}
示例10: GetInsertionPoints
public static List<InsertionPoint> GetInsertionPoints (IDocument document, IUnresolvedTypeDefinition type)
{
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 = document.GetOffset (type.Region.Begin);
if (offset < 0)
return result;
while (offset < document.TextLength && document.GetCharAt (offset) != '{') {
offset++;
}
var realStartLocation = document.GetLocation (offset);
result.Add (GetInsertionPosition (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) {
domLocation = member.Region.End;
}
result.Add (GetInsertionPosition (document, domLocation.Line, domLocation.Column));
}
result [result.Count - 1].LineAfter = NewLineInsertion.None;
CheckStartPoint (document, result [0], result.Count == 1);
if (result.Count > 1) {
result.RemoveAt (result.Count - 1);
NewLineInsertion insertLine;
var lineBefore = GetLineOrNull(document, type.BodyRegion.EndLine - 1);
if (lineBefore != null && lineBefore.Length == GetLineIndent(document, lineBefore).Length) {
insertLine = NewLineInsertion.None;
} else {
insertLine = NewLineInsertion.Eol;
}
// search for line start
var line = document.GetLineByNumber (type.BodyRegion.EndLine);
int col = type.BodyRegion.EndColumn - 1;
while (col > 1 && char.IsWhiteSpace (document.GetCharAt (line.Offset + col - 2)))
col--;
result.Add (new InsertionPoint (new TextLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol));
CheckEndPoint (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;
}
示例11: SwapText
/// <summary>
/// Swaps 2 ranges of text in a document.
/// </summary>
void SwapText(IDocument document, TextLocation start1, TextLocation end1, TextLocation start2, TextLocation end2)
{
if (start1 > start2) {
TextLocation sw;
sw = start1; start1 = start2; start2 = sw;
sw = end1; end1 = end2; end2 = sw;
}
if (end1 >= start2)
throw new InvalidOperationException("Cannot swap overlaping segments");
int offset1 = document.GetOffset(start1);
int len1 = document.GetOffset(end1) - offset1;
int offset2 = document.GetOffset(start2);
int len2 = document.GetOffset(end2) - offset2;
string text1 = document.GetText(offset1, len1);
string text2 = document.GetText(offset2, len2);
using (var undoGroup = document.OpenUndoGroup()) {
document.Replace(offset2, len2, text1);
document.Replace(offset1, len1, text2);
}
}
示例12: ExtendLeft
/// <summary>
/// If the text at startPos is preceded by any of the prefixes, moves the start backwards to include one prefix
/// (the rightmost one).
/// </summary>
TextLocation ExtendLeft(TextLocation startPos, IDocument document, params String[] prefixes)
{
int startOffset = document.GetOffset(startPos);
foreach (string prefix in prefixes) {
if (startOffset < prefix.Length) continue;
string realPrefix = document.GetText(startOffset - prefix.Length, prefix.Length);
if (realPrefix == prefix) {
return document.GetLocation(startOffset - prefix.Length);
}
}
// no prefixes -> do not extend
return startPos;
}
示例13: IsWhitespaceBetween
bool IsWhitespaceBetween(IDocument document, TextLocation startPos, TextLocation endPos)
{
int startOffset = document.GetOffset(startPos);
int endOffset = document.GetOffset(endPos);
if (startOffset > endOffset) {
throw new ArgumentException("Invalid range for (startPos, endPos)");
}
return string.IsNullOrWhiteSpace(document.GetText(startOffset, endOffset - startOffset));
}
示例14: GetEndOffset
static int GetEndOffset(IDocument document, DomRegion region)
{
if (region.EndLine < 1)
return 0;
if (region.EndLine > document.LineCount)
return document.TextLength;
return document.GetOffset(region.End);
}
示例15: CopyFileHeader
string CopyFileHeader(IDocument document, CSharpFullParseInformation info)
{
var lastHeadNode = info.SyntaxTree.Children
.TakeWhile(node => node.NodeType == NodeType.Whitespace && (!(node is Comment) || !((Comment)node).IsDocumentation))
.LastOrDefault();
if (lastHeadNode == null)
return "";
return document.GetText(0, document.GetOffset(lastHeadNode.EndLocation));
}