本文整理汇总了C#中ICSharpCode.AvalonEdit.Document.TextDocument.GetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.GetOffset方法的具体用法?C# TextDocument.GetOffset怎么用?C# TextDocument.GetOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.AvalonEdit.Document.TextDocument
的用法示例。
在下文中一共展示了TextDocument.GetOffset方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchBrackets
public static BracketSearchResult SearchBrackets(TextDocument doc, int caretOffset, TextLocation caret)
{
var caretLocation = new CodeLocation(caret.Column, caret.Line);
try
{
if (caretOffset < 1 || caretOffset>=doc.TextLength-2)
return null;
// Search backward
DToken lastToken=null;
var tk_start = SearchBackward(doc, caretOffset, caretLocation,out lastToken);
if (tk_start == null)
return null;
// Search forward
var tk_end = SearchForward(doc,
doc.GetOffset(lastToken.EndLocation.Line,lastToken.EndLocation.Column),
lastToken.EndLocation,
getOppositeBracketToken(tk_start.Kind));
if (tk_end == null)
return null;
int start = doc.GetOffset(tk_start.Location.Line, tk_start.Location.Column),
end = doc.GetOffset(tk_end.Location.Line, tk_end.Location.Column);
return new BracketSearchResult(start, 1, end, 1);
}
catch { return null; }
}
示例2: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding"/>s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, XmlReader reader, out int firstErrorOffset)
{
Stack<XmlFoldStart> stack = new Stack<XmlFoldStart>();
List<NewFolding> foldMarkers = new List<NewFolding>();
try {
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (!reader.IsEmptyElement) {
XmlFoldStart newFoldStart = CreateElementFoldStart(document, reader);
stack.Push(newFoldStart);
}
break;
case XmlNodeType.EndElement:
XmlFoldStart foldStart = stack.Pop();
CreateElementFold(document, foldMarkers, reader, foldStart);
break;
case XmlNodeType.Comment:
CreateCommentFold(document, foldMarkers, reader);
break;
}
}
firstErrorOffset = -1;
} catch (XmlException ex) {
// ignore errors
firstErrorOffset = document.GetOffset(ex.LineNumber, ex.LinePosition);
}
foldMarkers.Sort((a,b) => a.StartOffset.CompareTo(b.StartOffset));
return foldMarkers;
}
示例3: SearchBrackets
public static BracketSearchResult SearchBrackets(TextDocument doc, IEditorData ed, IBlockNode curBlock, IStatement stmt)
{
while (stmt != null)
{
if (stmt is IExpressionContainingStatement)
{
var ecs = (IExpressionContainingStatement)stmt;
foreach (var x in ecs.SubExpressions)
{
SurroundingParenthesesExpression spe = null;
var xx = x;
while (xx is ContainerExpression)
{
if (xx is SurroundingParenthesesExpression)
spe = (SurroundingParenthesesExpression)xx;
var subX = ((ContainerExpression)xx).SubExpressions;
if (subX != null && subX.Length != 0)
{
xx = null;
foreach (var sx in subX)
if (ed.CaretLocation > sx.Location && ed.CaretLocation < sx.EndLocation)
{
xx = sx as ContainerExpression;
break;
}
}
}
if (spe != null)
return new BracketSearchResult(
doc.GetOffset(spe.Location.Line, spe.Location.Column), 1,
doc.GetOffset(spe.EndLocation.Line, spe.EndLocation.Column) - 1, 1);
}
}
if (stmt is BlockStatement)
return new BracketSearchResult(
doc.GetOffset(stmt.Location.Line, stmt.Location.Column), 1,
doc.GetOffset(stmt.EndLocation.Line, stmt.EndLocation.Column) - 1, 1);
stmt = stmt.Parent;
}
if (curBlock != null && ed.CaretLocation < curBlock.BlockStartLocation)
curBlock = curBlock.Parent as IBlockNode;
if (curBlock == null || curBlock is DModule)
return null;
//TODO: Meta blocks, everything that could contain parentheses
return new BracketSearchResult(
doc.GetOffset(curBlock.BlockStartLocation.Line, curBlock.BlockStartLocation.Column), 1,
doc.GetOffset(curBlock.EndLocation.Line, curBlock.EndLocation.Column) - 1, 1);
}
示例4: GetOffset
static int GetOffset(TextDocument document, XmlReader reader)
{
IXmlLineInfo info = reader as IXmlLineInfo;
if (info != null && info.HasLineInfo()) {
return document.GetOffset(info.LineNumber, info.LinePosition);
} else {
throw new ArgumentException("XmlReader does not have positioning information.");
}
}
示例5: CreateElementFold
/// <summary>
/// Create an element fold if the start and end tag are on
/// different lines.
/// </summary>
static void CreateElementFold(TextDocument document, List<NewFolding> foldMarkers, XmlReader reader, XmlFoldStart foldStart)
{
IXmlLineInfo lineInfo = (IXmlLineInfo)reader;
int endLine = lineInfo.LineNumber;
if (endLine > foldStart.StartLine) {
int endCol = lineInfo.LinePosition + reader.Name.Length + 1;
foldStart.EndOffset = document.GetOffset(endLine, endCol);
foldMarkers.Add(foldStart);
}
}
示例6: CreateElementFoldStart
/// <summary>
/// Creates an XmlFoldStart for the start tag of an element.
/// </summary>
XmlFoldStart CreateElementFoldStart(TextDocument document, XmlReader reader)
{
// Take off 1 from the offset returned
// from the xml since it points to the start
// of the element name and not the beginning
// tag.
//XmlFoldStart newFoldStart = new XmlFoldStart(reader.Prefix, reader.LocalName, reader.LineNumber - 1, reader.LinePosition - 2);
XmlFoldStart newFoldStart = new XmlFoldStart();
IXmlLineInfo lineInfo = (IXmlLineInfo)reader;
newFoldStart.StartLine = lineInfo.LineNumber;
newFoldStart.StartOffset = document.GetOffset(newFoldStart.StartLine, lineInfo.LinePosition - 1);
if (this.ShowAttributesWhenFolded && reader.HasAttributes) {
newFoldStart.Name = String.Concat("<", reader.Name, " ", GetAttributeFoldText(reader), ">");
} else {
newFoldStart.Name = String.Concat("<", reader.Name, ">");
}
return newFoldStart;
}
示例7: LineMarker
public LineMarker(TextMarkerService svc, TextDocument doc, int beginLine, int endLine)
{
TextMarkerService = svc;
StartOffset = doc.GetOffset(beginLine, 0);
Length = doc.GetLineByNumber(endLine).EndOffset - StartOffset;
}
示例8: CreateNewFoldings
public override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
{
try
{
// Stopwatch sw = new Stopwatch();
// sw.Start();
List<NewFolding> foldMarkers = new List<NewFolding>();
firstErrorOffset = 0;
if (dfd == null) return foldMarkers;
// return foldMarkers;
if (dfd.header.oline != -1 && dfd.header.cline != -1)
foldMarkers.Add(
new NewFolding(document.GetOffset(dfd.header.oline, 0),
document.GetOffset(dfd.header.cline, document.Lines[dfd.header.cline - 1].TotalLength)) { Name = dfd.header.foldcaption });
if (dfd.wsl_oline != -1 && dfd.wsl_cline != -1)
foldMarkers.Add(
new NewFolding(document.GetOffset(dfd.wsl_oline, 0),
document.GetOffset(dfd.wsl_cline, document.Lines[dfd.wsl_cline - 1].TotalLength)) { Name = "<weapon_strength_list>" });
int i = 0;
for (i = 0; i < dfd.frames.Count - 1; i++)
{
if (i == 221)
{ }
try
{
// continue;
if (dfd.frames[i].oline == -1 || dfd.frames[i].cline == -1) continue;
int start = document.GetOffset(dfd.frames[i].oline, 0);
int end = document.GetOffset(dfd.frames[i].cline, document.Lines[dfd.frames[i].cline - 1].TotalLength);
foldMarkers.Add(new NewFolding(start, end) { Name = dfd.frames[i].foldcaption });
}
catch (Exception)
{
MessageBox.Show(i.ToString());
}
}
try
{
if (dfd.frames.Count != 0)
if (dfd.frames[i].oline != -1 && dfd.frames[i].cline != -1)
{
int start2 = document.GetOffset(dfd.frames[i].oline, 0);
int end2 = document.GetOffset(dfd.frames[i].cline, document.Lines[dfd.frames[i].cline - 1].TotalLength + 1);
foldMarkers.Add(new NewFolding(start2, end2) { Name = dfd.frames[i].foldcaption });
}
}
catch (Exception)
{
throw;
}
for (i = 0; i < dfd.regions.Count; i++)
{
if (dfd.regions[i].oline == -1 || dfd.regions[i].cline == -1) continue;
int start = document.GetOffset(dfd.regions[i].oline, 0);
int end = document.GetOffset(dfd.regions[i].cline, document.Lines[dfd.regions[i].cline - 1].TotalLength);
foldMarkers.Add(new NewFolding(start, end) { Name = dfd.regions[i].caption });
}
foldMarkers.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
// sw.Stop();
// G.mainWindow.teOutput.AppendText
// ("Fold/unfold - время прошло: " + sw.ElapsedMilliseconds + " миллисекунд" + Environment.NewLine);
return foldMarkers;
}
catch (Exception ex)
{ new wException(ex).ShowDialog(); firstErrorOffset = 0; return null; }
}
示例9: CreateElementFold
private NewFolding CreateElementFold(TextDocument document, HtmlNode node)
{
NewFolding newFold = new NewFolding();
if (node.Line != node.EndNode.Line)
{
if (this.ShowAttributesWhenFolded && node.HasAttributes)
newFold.Name = String.Concat("<", node.Name, " ", GetAttributeFoldText(node), ">");
else
newFold.Name = String.Concat("<", node.Name, ">");
newFold.StartOffset = document.GetOffset(node.Line, node.LinePosition - 1);
newFold.EndOffset = document.GetOffset(node.EndNode.Line, node.EndNode.LinePosition + node.OriginalName.Length + 3);
}
return newFold;
}
示例10: SetEndPropOffset
public void SetEndPropOffset(TextDocument document, XmlReader reader)
{
if (_properties.Any())
{
var prop = _properties.Last();
IXmlLineInfo lineInfo = (IXmlLineInfo)reader;
prop.EndLine = lineInfo.LineNumber;
prop.EndOffset = document.GetOffset(lineInfo.LineNumber, lineInfo.LinePosition + reader.Name.Length + 1);
}
}
示例11: CreateNewFoldings
public IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, XmlReader reader, out int firstErrorOffset)
{
Stack<AmlFoldStart> stack = new Stack<AmlFoldStart>();
List<NewFolding> foldMarkers = new List<NewFolding>();
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (stack.Any() && stack.Peek().Name == "Item")
{
if (this.ShowAttributesWhenFolded && reader.LocalName == "id")
{
stack.Peek().SetKeyedName(reader.GetAttribute("keyed_name"));
}
else if (this.ShowAttributesWhenFolded && reader.LocalName == "keyed_name")
{
stack.Peek().SetKeyedName(reader.Value);
}
else if (this.ShowAttributesWhenFolded && reader.LocalName == "related_id")
{
stack.Peek().SetKeyedName("Related: " + (reader.GetAttribute("keyed_name") ?? ""));
}
if (reader.LocalName != "Relationships" && reader.LocalName != "related_id")
{
stack.Peek().SetStartPropOffset(document, reader);
if (reader.IsEmptyElement) stack.Peek().SetEndPropOffset(document, reader);
}
}
if (!reader.IsEmptyElement)
{
var newFoldStart = CreateElementFoldStart(document, reader);
stack.Push(newFoldStart);
}
break;
case XmlNodeType.EndElement:
var foldStart = stack.Pop();
foldStart.Flush();
CreateElementFold(document, foldMarkers, reader, foldStart);
if (stack.Any() && stack.Peek().Name == "Item" && reader.LocalName != "Relationships" && reader.LocalName != "related_id")
{
stack.Peek().SetEndPropOffset(document, reader);
}
break;
case XmlNodeType.Comment:
CreateCommentFold(document, foldMarkers, reader);
break;
}
}
firstErrorOffset = -1;
}
catch (XmlException ex)
{
// ignore errors at invalid positions (prevent ArgumentOutOfRangeException)
if (ex.LineNumber >= 1 && ex.LineNumber <= document.LineCount)
firstErrorOffset = document.GetOffset(ex.LineNumber, ex.LinePosition);
else
firstErrorOffset = 0;
}
foldMarkers.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return foldMarkers;
}
示例12: SetStartPropOffset
public void SetStartPropOffset(TextDocument document, XmlReader reader)
{
IXmlLineInfo lineInfo = (IXmlLineInfo)reader;
if (!_properties.Any() || lineInfo.LineNumber > _properties.Last().EndLine + 1)
{
var prop = new AmlFoldStart();
prop.StartLine = lineInfo.LineNumber;
prop.StartOffset = document.GetOffset(lineInfo.LineNumber, lineInfo.LinePosition - 1);
_properties.Add(prop);
}
}