本文整理汇总了C#中TextPoint.CreateEditPoint方法的典型用法代码示例。如果您正苦于以下问题:C# TextPoint.CreateEditPoint方法的具体用法?C# TextPoint.CreateEditPoint怎么用?C# TextPoint.CreateEditPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextPoint
的用法示例。
在下文中一共展示了TextPoint.CreateEditPoint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTextToFirstMatch
internal static string GetTextToFirstMatch(TextPoint startPoint, string matchString)
{
var startEditPoint = startPoint.CreateEditPoint();
var endEditPoint = startEditPoint.CreateEditPoint();
TextRanges subGroupMatches = null;
if (endEditPoint.FindPattern(matchString, StandardFindOptions, ref endEditPoint, ref subGroupMatches))
{
return startEditPoint.GetText(endEditPoint);
}
return null;
}
示例2: Execute
void Execute(TextPoint StartPoint, TextPoint EndPoint, bool force)
{
TextDocument doc = (TextDocument)(_applicationObject.ActiveDocument.
Object("TextDocument"));
//if (StartPoint.Line == EndPoint.Line && StartPoint.LineCharOffset == EndPoint.LineCharOffset)
// return;
if (AStyle.fileMode == AStyleInterface.AstyleFilemode.CPP && doc.Language != "C/C++")
return;
if (AStyle.fileMode == AStyleInterface.AstyleFilemode.JAVA && doc.Language != "Java")
return;
if (AStyle.fileMode == AStyleInterface.AstyleFilemode.SHARP && doc.Language != "C#")
return;
if (!force && !AStyle.working)
return;
EditPoint startEditPoint = StartPoint.CreateEditPoint();
EditPoint curEditPoint = StartPoint.CreateEditPoint();
EditPoint endEditPoint = EndPoint.CreateEditPoint();
startEditPoint.StartOfLine();
curEditPoint.StartOfLine();
endEditPoint.EndOfLine();
string text = curEditPoint.GetText(endEditPoint);
String textOut = AStyle.FormatSource(text, AStyleInterface.AstyleFilemode.SHARP);
int hashik = text.GetHashCode() ^ endEditPoint.AbsoluteCharOffset;
if(_hashes.Contains(hashik))
return;
if (textOut.TrimStart('\t') == text.TrimStart('\t'))
return;
if (_hashes.Count > 1000000)
_hashes.Clear(); // no memory licking!
_hashes.Add(hashik);
var curOffset = doc.Selection.ActivePoint.AbsoluteCharOffset;
int beginLinePos = curEditPoint.AbsoluteCharOffset;
int beforeLength = endEditPoint.AbsoluteCharOffset - startEditPoint.AbsoluteCharOffset;
curEditPoint.Delete(endEditPoint);
curEditPoint.Insert(textOut);
curEditPoint.MoveToAbsoluteOffset(startEditPoint.AbsoluteCharOffset + textOut.Length);
doc.Selection.Cancel();
doc.Selection.MoveToPoint(startEditPoint, false);
doc.Selection.MoveToPoint(curEditPoint, true);
_applicationObject.ExecuteCommand("Edit.FormatSelection", "");
curEditPoint.EndOfLine();
if (curOffset > beginLinePos)
{
doc.Selection.MoveToAbsoluteOffset(curOffset - beforeLength
+ (curEditPoint.AbsoluteCharOffset - startEditPoint.AbsoluteCharOffset), false);
_applicationObject.ExecuteCommand("Edit.FormatSelection", "");
}
else
doc.Selection.MoveToAbsoluteOffset(curOffset, false);
}
示例3: Expand
private EditPoint Expand(TextPoint point, Action<EditPoint> foundAction)
{
EditPoint i = point.CreateEditPoint();
EditPoint result = null;
do
{
var line = i.Line;
var text = i.GetLine();
if (CodeCommentHelper.LineMatchesRegex(i, _commentLineRegex).Success)
{
result = i.CreateEditPoint();
foundAction(i);
// If result and iterator line are the same, the found action (move line up or
// down) did nothing. This means there is no point to keep searching, it would
// create an infinite loop.
if (result.Line == i.Line)
{
break;
}
}
else
{
if (i != null && result != null && CodeCommentHelper.LineMatchesRegex(i, _codeLineRegex).Success)
{
result = null;
}
i = null;
}
} while (i != null);
return result;
}
示例4: Expand
/// <summary>
/// Expand a textpoint to the full comment, in the direction specified by the <paramref name="foundAction"/>.
/// </summary>
/// <param name="point">The initial starting point for the expansion.</param>
/// <param name="foundAction">An action which advances the search either up or down.</param>
/// <returns>
/// The endpoint of the comment, or <c>null</c> if the expansion did not find a valid comment.
/// </returns>
private EditPoint Expand(TextPoint point, Action<EditPoint> foundAction)
{
EditPoint current = point.CreateEditPoint();
EditPoint result = null;
string prefix = null;
do
{
var line = current.Line;
var text = current.GetLine();
var match = _commentLineRegex.Match(text);
if (match.Success)
{
// Cancel the expansion if the prefix does not match. This takes priority over
// the initial spacer check to allow formatting comments adjacent to Stylecop
// SA1626 style commented code.
var currentPrefix = match.Groups["prefix"].Value.TrimStart();
if (prefix != null && !string.Equals(prefix, currentPrefix))
{
break;
}
else
{
prefix = currentPrefix;
}
// The initial spacer is required, otherwise we assume this is commented out
// code and do not format.
if (match.Groups["initialspacer"].Success)
{
result = current.CreateEditPoint();
foundAction(current);
// If result and iterator line are the same, the found action (move line up or
// down) did nothing. This means we're at the start or end of the file, and
// there is no point to keep searching, it would create an infinite loop.
if (result.Line == current.Line)
{
break;
}
}
else
{
// Did not succesfully match the intial spacer, we have to assume this is
// code and cancel all formatting.
result = null;
current = null;
}
}
else
{
current = null;
}
} while (current != null);
return result;
}
示例5: Expand
private EditPoint Expand(TextPoint point, Action<EditPoint> foundAction)
{
EditPoint current = point.CreateEditPoint();
EditPoint result = null;
string prefix = null;
do
{
var line = current.Line;
var text = current.GetLine();
var match = _commentLineRegex.Match(text);
if (match.Success)
{
// The initial spacer is required, otherwise we assume this is commented out
// code and do not format.
if (match.Groups["initialspacer"].Success)
{
// Get the comment prefix for the current line.
var currentPrefix = match.Groups["prefix"].Value.TrimStart();
if (prefix == null) { prefix = currentPrefix; }
// Cancel the expanding if the prefix does not match.
if (prefix != currentPrefix)
{
break;
}
result = current.CreateEditPoint();
foundAction(current);
// If result and iterator line are the same, the found action (move line up or
// down) did nothing. This means we're at the start or end of the file, and
// there is no point to keep searching, it would create an infinite loop.
if (result.Line == current.Line)
{
break;
}
}
else
{
// This is code! Set to null to abandon loop.
result = null;
current = null;
}
}
else
{
current = null;
}
} while (current != null);
return result;
}