本文整理汇总了C#中IDocument.OffsetToPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.OffsetToPosition方法的具体用法?C# IDocument.OffsetToPosition怎么用?C# IDocument.OffsetToPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.OffsetToPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHighlight
public BracketHighlight GetHighlight(IDocument document, int offset)
{
int searchOffset;
if (document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After) {
searchOffset = offset;
} else {
searchOffset = offset + 1;
}
char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, searchOffset)));
TextLocation endP = document.OffsetToPosition(searchOffset);
if (word == opentag) {
if (searchOffset < document.TextLength) {
int bracketOffset = TextUtilities.SearchBracketForward(document, searchOffset + 1, opentag, closingtag);
if (bracketOffset >= 0) {
TextLocation p = document.OffsetToPosition(bracketOffset);
return new BracketHighlight(p, endP);
}
}
} else if (word == closingtag) {
if (searchOffset > 0) {
int bracketOffset = TextUtilities.SearchBracketBackward(document, searchOffset - 1, opentag, closingtag);
if (bracketOffset >= 0) {
TextLocation p = document.OffsetToPosition(bracketOffset);
return new BracketHighlight(p, endP);
}
}
}
return null;
}
示例2: SelectText
/// <summary>
/// Selects the specified text range.
/// </summary>
static void SelectText(SelectionManager selectionManager, IDocument document, int startOffset, int length)
{
selectionManager.ClearSelection();
TextLocation selectionStart = document.OffsetToPosition(startOffset);
TextLocation selectionEnd = document.OffsetToPosition(startOffset + length);
selectionManager.SetSelection(selectionStart, selectionEnd);
}
示例3: GetHighlight
public Highlight GetHighlight(IDocument document, int offset)
{
char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, offset)));
Point endP = document.OffsetToPosition(offset);
if (word == opentag) {
if (offset < document.TextLength) {
int bracketOffset = TextUtilities.SearchBracketForward(document, offset + 1, opentag, closingtag);
if (bracketOffset >= 0) {
Point p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
} else if (word == closingtag) {
if (offset > 0) {
int bracketOffset = TextUtilities.SearchBracketBackward(document, offset - 1, opentag, closingtag);
if (bracketOffset >= 0) {
Point p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
}
return null;
}
示例4: GetHighlight
/// <summary>
/// Gets the highlight.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <returns>The matching bracers.</returns>
public Highlight GetHighlight(IDocument document, int offset)
{
int searchOffset;
if (document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After)
searchOffset = offset;
else
searchOffset = offset + 1;
char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, searchOffset)));
TextLocation endP = document.OffsetToPosition(searchOffset);
if (word == _openTag)
{
if (searchOffset < document.TextLength)
{
int bracketOffset = TextHelper.FindClosingBracket(document, searchOffset + 1, _openTag, _closingTag);
if (bracketOffset >= 0)
{
TextLocation p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
}
else if (word == _closingTag)
{
if (searchOffset > 0)
{
int bracketOffset = TextHelper.FindOpeningBracket(document, searchOffset - 1, _openTag, _closingTag);
if (bracketOffset >= 0)
{
TextLocation p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
}
return null;
}
示例5: SearchBracket
public BracketSearchResult SearchBracket(IDocument document, int offset)
{
if (offset > 0) {
char c = document.GetCharAt(offset - 1);
int index = openingBrackets.IndexOf(c);
int otherOffset = -1;
if (index > -1)
otherOffset = SearchBracketForward(document, offset, openingBrackets[index], closingBrackets[index]);
index = closingBrackets.IndexOf(c);
if (index > -1)
otherOffset = SearchBracketBackward(document, offset - 2, openingBrackets[index], closingBrackets[index]);
if (otherOffset > -1)
return new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1,
Math.Max(offset - 1, otherOffset), 1);
int length;
VBStatement statement;
int startIndex = FindBeginStatementAroundOffset(document, offset, out statement, out length);
int endIndex = 0;
if (statement != null)
endIndex = FindEndStatement(document, statement);
else {
endIndex = FindEndStatementAroundOffset(document, offset, out statement);
if (statement != null)
startIndex = FindBeginStatement(document, statement, document.OffsetToPosition(endIndex), out length);
}
if (startIndex > -1 && endIndex > -1)
return new BracketSearchResult(startIndex, length, endIndex,
statement.EndStatement.Length);
}
return null;
}
示例6: 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>
Location ExtendLeft(Location startPos, IDocument document, params String[] prefixes)
{
int startOffset = document.PositionToOffset(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.OffsetToPosition(startOffset - prefix.Length);
}
}
// no prefixes -> do not extend
return startPos;
}
示例7: 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, Location selectionStart, Location selectionEnd, IEnumerable<Comment> commentsBlankLines)
{
var lineComment = commentsBlankLines.FirstOrDefault(c => c.StartPosition.Line == selectionEnd.Line && c.StartPosition >= selectionEnd);
if (lineComment == null) {
return null;
}
bool isWholeLineSelected = IsWhitespaceBetween(document, new Location(1, selectionStart.Line), selectionStart);
if (!isWholeLineSelected) {
// whole line must be selected before we add the comment
return null;
}
// fix the end of comment set to next line incorrectly by the parser
int fixEndPos = document.PositionToOffset(lineComment.EndPosition) - 1;
return new Selection { Start = selectionStart, End = document.OffsetToPosition(fixEndPos) };
}
示例8: GetEndPosition
public virtual Point GetEndPosition(IDocument document)
{
return document.OffsetToPosition(Offset + Length);
}
示例9: GetStartPosition
public virtual Point GetStartPosition(IDocument document)
{
return document.OffsetToPosition(Offset);
}
示例10: GenerateFoldMarkers
public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
{
List<FoldMarker> Back = new List<FoldMarker>();
//get all the text
string Script = document.GetText(0, document.TextLength);
//tokenize text
TokenList Tokens = Script.GetTokens();
#region Calculate folding for BEGIN <----> END
List<Token> FoldStarter = Tokens.GetByType(TokenType.BLOCKSTART);
List<Token> FoldEnder = Tokens.GetByType(TokenType.BLOCKEND);
for (int i = 0; i < FoldEnder.Count; i++)
{
for (int j = FoldStarter.Count - 1; j >= 0; j--)
{
if (Tokens.GetStartOf(FoldStarter[j]) < Tokens.GetStartOf(FoldEnder[i]))
{
Token Starter, Ender;
Ender = FoldEnder[i];
Starter = FoldStarter[j];
TextLocation Start, End, afterFoldHelper;
Start = document.OffsetToPosition(Tokens.GetStartOf(Starter) + "begin".Length);
afterFoldHelper = document.OffsetToPosition(Tokens.GetStartOf(Starter));
End = document.OffsetToPosition(Tokens.GetStartOf(Ender));
string afterStarter = document.GetText(document.GetLineSegment(afterFoldHelper.Line)).Substring(afterFoldHelper.Column).Trim(' ', '\t', '\n', '\r');
afterStarter = afterStarter.Length > 5 ? afterStarter.Substring(5) : "";
if (String.IsNullOrEmpty(afterStarter) || afterStarter.Trim().Length == 0)
afterStarter = "...";
Back.Add(new FoldMarker(document, Start.Line, Start.Column, End.Line, End.Column, FoldType.Region, afterStarter, false));
FoldStarter.RemoveAt(j);
break;
}
}
}
#endregion
#region Calculate folding for block comments
List<Token> BlockCommentFolds = Tokens.GetByType(TokenType.BLOCKCOMMENT);
for (int i = 0; i < BlockCommentFolds.Count; i++)
{
Token BlockComment = BlockCommentFolds[i];
TextLocation Start, End;
Start = document.OffsetToPosition(Tokens.GetStartOf(BlockComment) + 2);
End = document.OffsetToPosition(Tokens.GetEndOf(BlockComment) - 1);
Back.Add(new FoldMarker(document, Start.Line, Start.Column, End.Line, End.Column, FoldType.Region, "***", false));
}
#endregion
#region Calculate folding for custom folders --fold <----> --/fold
FoldStarter = Tokens.GetCustomFolders(true);
FoldEnder = Tokens.GetCustomFolders(false);
for (int i = 0; i < FoldEnder.Count; i++)
{
for (int j = FoldStarter.Count - 1; j >= 0; j--)
{
if (Tokens.GetStartOf(FoldStarter[j]) < Tokens.GetStartOf(FoldEnder[i]))
{
Token Starter, Ender;
Ender = FoldEnder[i];
Starter = FoldStarter[j];
TextLocation Start, End, afterFoldHelper;
Start = document.OffsetToPosition(Tokens.GetStartOf(Starter) + "--fold".Length);
afterFoldHelper = document.OffsetToPosition(Tokens.GetStartOf(Starter));
End = document.OffsetToPosition(Tokens.GetStartOf(Ender));
string afterStarter = document.GetText(document.GetLineSegment(afterFoldHelper.Line)).Substring(afterFoldHelper.Column).Trim(' ', '\t', '\n', '\r');
afterStarter = afterStarter.Length > 6 ? afterStarter.Substring(6) : "";
if (String.IsNullOrEmpty(afterStarter) || afterStarter.Trim().Length == 0)
afterStarter = "...";
Back.Add(new FoldMarker(document, Start.Line, Start.Column, End.Line, End.Column, FoldType.Region, afterStarter, false));
FoldStarter.RemoveAt(j);
break;
}
}
}
#endregion
return Back;
}
示例11: Resolve
public static ResolveResult Resolve(int offset, IDocument document, string fileName)
{
var position = document.OffsetToPosition(offset);
return Resolve(position.Line, position.Column, document, fileName);
}
示例12: GetEndPosition
public virtual TextLocation GetEndPosition(IDocument document)
{
return document.OffsetToPosition(Math.Min(Offset + Length, document.TextLength));
}
示例13: GetTextSpan
private NiTextSpan GetTextSpan(IDocument document, int offset, int length)
{
var start = document.OffsetToPosition(offset);
var end = document.OffsetToPosition(offset + length);
return new NiTextSpan(start.Line, start.Column, end.Line, end.Column);
}
示例14: ToRegion
public DomRegion ToRegion(IDocument document)
{
Location start = document.OffsetToPosition(minChar);
Location end = document.OffsetToPosition(limChar);
return DomRegion.FromLocation(start, end);
}
示例15: GetStartPosition
public virtual Location GetStartPosition(IDocument document)
{
return document.OffsetToPosition(Math.Min(Offset, document.TextLength));
}