本文整理汇总了C#中IDocument.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.Remove方法的具体用法?C# IDocument.Remove怎么用?C# IDocument.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.Remove方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertCodeAtEnd
/// <summary>
/// Ensure that code is inserted correctly in {} code blocks - SD2-1180
/// </summary>
public override void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
{
string beginLineIndentation = GetIndentation(document, region.BeginLine);
int insertionLine = region.EndLine - 1;
IDocumentLine endLine = document.GetLine(region.EndLine);
string endLineText = endLine.Text;
int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}'
int pos = originalPos;
if (pos >= endLineText.Length || endLineText[pos] != '}') {
LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')"
+ " endLineText=" + endLineText + ", pos=" + pos);
} else {
for (pos--; pos >= 0; pos--) {
if (!char.IsWhiteSpace(endLineText[pos])) {
// range before '}' is not empty: we cannot simply insert in the line before the '}', so
//
pos++; // set pos to first whitespace character / the '{' character
if (pos < originalPos) {
// remove whitespace between last non-white character and the '}'
document.Remove(endLine.Offset + pos, originalPos - pos);
}
// insert newline and same indentation as used in beginLine before the '}'
document.Insert(endLine.Offset + pos, Environment.NewLine + beginLineIndentation);
insertionLine++;
pos = region.BeginColumn - 1;
if (region.BeginLine == region.EndLine && pos >= 1 && pos < endLineText.Length) {
// The whole block was in on a single line, e.g. "get { return field; }".
// Insert an additional newline after the '{'.
originalPos = pos = endLineText.IndexOf('{', pos);
if (pos >= 0 && pos < region.EndColumn - 1) {
// find next non-whitespace after originalPos
originalPos++; // point to insertion position for newline after {
for (pos++; pos < endLineText.Length; pos++) {
if (!char.IsWhiteSpace(endLineText[pos])) {
// remove all between originalPos and pos
if (originalPos < pos) {
document.Remove(endLine.Offset + originalPos, pos - originalPos);
}
document.Insert(endLine.Offset + originalPos, Environment.NewLine + beginLineIndentation + '\t');
insertionLine++;
break;
}
}
}
}
break;
}
}
}
InsertCodeAfter(insertionLine, document, beginLineIndentation + this.Options.IndentString, nodes);
}
示例2: SortLines
public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
{
List<string> lines = new List<string>();
for (int i = startLine; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(comparer);
if (removeDuplicates) {
lines = lines.Distinct(comparer).ToList();
}
using (document.OpenUndoGroup()) {
for (int i = 0; i < lines.Count; ++i) {
IDocumentLine line = document.GetLine(startLine + i);
document.Replace(line.Offset, line.Length, lines[i]);
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例3: RemoveFieldDeclaration
protected override void RemoveFieldDeclaration(IDocument document, IField field)
{
// In VB, the field region begins at the start of the declaration
// and ends on the first column of the line following the declaration.
int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
int endOffset = document.PositionToOffset(field.Region.EndLine, 1);
document.Remove(startOffset, endOffset - startOffset);
}
示例4: Convert
protected override void Convert(IDocument document, int y1, int y2)
{
for (int i = y2 - 1; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
int removeNumber = 0;
for (int x = line.Offset + line.Length - 1; x >= line.Offset && Char.IsWhiteSpace(document.GetCharAt(x)); --x) {
++removeNumber;
}
if (removeNumber > 0) {
document.Remove(line.Offset + line.Length - removeNumber, removeNumber);
}
}
}
示例5: Convert
protected override void Convert(IDocument document, int y1, int y2)
{
int redocounter = 0; // must count how many Delete operations occur
for (int i = y1; i < y2; ++i) {
LineSegment line = document.GetLineSegment(i);
int removeNumber = 0;
for (int x = line.Offset; x < line.Offset + line.Length && Char.IsWhiteSpace(document.GetCharAt(x)); ++x) {
++removeNumber;
}
if (removeNumber > 0) {
document.Remove(line.Offset, removeNumber);
++redocounter; // count deletes
}
}
if (redocounter > 0) {
document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
}
}
示例6: RemoveComment
void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
{
document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
}
示例7: RemoveCommentAt
void RemoveCommentAt(IDocument document, string comment, SelectionManager selmgr, int y1, int y2)
{
firstLine = y1;
lastLine = y2;
for (int i = y2; i >= y1; --i)
{
LineSegment line = document.GetLineSegment(i);
if (selmgr != null && i == y2 && line.Offset == selmgr.StartOffset + selmgr.Length)
{
--lastLine;
continue;
}
string lineText = document.GetText(line.Offset, line.Length);
if (lineText.Trim().StartsWith(comment))
{
document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
}
}
}
示例8: RemoveTabs
void RemoveTabs(IDocument document, SelectionManager selmgr, int y1, int y2)
{
document.UndoStack.StartUndoGroup();
for (int i = y2; i >= y1; --i)
{
LineSegment line = document.GetLineSegment(i);
if (i == y2 && line.Offset == selmgr.EndOffset)
{
continue;
}
if (line.Length > 0)
{
/**** TextPad Strategy:
/// first convert leading whitespace to tabs (controversial! - not all editors work like this)
string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset,line.Length),document.Properties.Get("TabIndent", 4));
if(newLine.Length > 0 && newLine[0] == '\t') {
document.Replace(line.Offset,line.Length,newLine.Substring(1));
++redocounter;
}
else if(newLine.Length > 0 && newLine[0] == ' ') {
/// there were just some leading spaces but less than TabIndent of them
int leadingSpaces = 1;
for(leadingSpaces = 1; leadingSpaces < newLine.Length && newLine[leadingSpaces] == ' '; leadingSpaces++) {
/// deliberately empty
}
document.Replace(line.Offset,line.Length,newLine.Substring(leadingSpaces));
++redocounter;
}
/// else
/// there were no leading tabs or spaces on this line so do nothing
/// MS Visual Studio 6 strategy:
****/
// string temp = document.GetText(line.Offset,line.Length);
if (line.Length > 0)
{
int charactersToRemove = 0;
if(document.GetCharAt(line.Offset) == '\t') // first character is a tab - just remove it
{
charactersToRemove = 1;
}
else if(document.GetCharAt(line.Offset) == ' ')
{
int leadingSpaces = 1;
int tabIndent = document.TextEditorProperties.IndentationSize;
for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
{
// deliberately empty
}
if(leadingSpaces >= tabIndent)
{
// just remove tabIndent
charactersToRemove = tabIndent;
}
else if(line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
{
// remove the leading spaces and the following tab as they add up
// to just one tab stop
charactersToRemove = leadingSpaces+1;
}
else
{
// just remove the leading spaces
charactersToRemove = leadingSpaces;
}
}
if (charactersToRemove > 0)
{
document.Remove(line.Offset,charactersToRemove);
}
}
}
}
document.UndoStack.EndUndoGroup();
}
示例9: RemoveFieldDeclaration
/// <summary>
/// Removes a field declaration from the source code document.
/// </summary>
/// <remarks>
/// The default implementation assumes that the field region starts at the very beginning
/// of the line of the field declaration and ends at the end of that line.
/// Override this method if that is not the case in a specific language.
/// </remarks>
protected virtual void RemoveFieldDeclaration(IDocument document, IField field)
{
int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
int endOffset = document.PositionToOffset(field.Region.EndLine + 1, 1);
document.Remove(startOffset, endOffset - startOffset);
}
示例10: RemoveCommentAt
void RemoveCommentAt(IDocument document, string comment, ISelection selection, int y1, int y2)
{
int redocounter = 0;
firstLine = y1;
lastLine = y2;
for (int i = y2; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
if (selection != null && i == y2 && line.Offset == selection.Offset + selection.Length) {
--lastLine;
continue;
}
string lineText = document.GetText(line.Offset, line.Length);
if (lineText.Trim().StartsWith(comment)) {
document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
++redocounter;
}
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
}
}
示例11: SortLines
public void SortLines(IDocument document, int startLine, int endLine)
{
ArrayList lines = new ArrayList();
for (int i = startLine; i <= endLine; ++i) {
LineSegment line = document.GetLineSegment(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(new SortComparer());
bool removeDupes = PropertyService.Get(SortOptionsDialog.removeDupesOption, false);
if (removeDupes) {
for (int i = 0; i < lines.Count - 1; ++i) {
if (lines[i].Equals(lines[i + 1])) {
lines.RemoveAt(i);
--i;
}
}
}
for (int i = 0; i < lines.Count; ++i) {
LineSegment line = document.GetLineSegment(startLine + i);
document.Replace(line.Offset, line.Length, lines[i].ToString());
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
LineSegment line = document.GetLineSegment(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
示例12: Convert
/// <summary>
/// Formats the specified lines.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="startLine">The start line.</param>
/// <param name="endLine">The end line.</param>
/// <remarks>
/// This method is called for all selections in the document.
/// </remarks>
protected override void Convert(IDocument document, int startLine, int endLine)
{
for (int i = endLine - 1; i >= startLine; --i)
{
LineSegment line = document.GetLineSegment(i);
int removeNumber = 0;
for (int x = line.Offset + line.Length - 1; x >= line.Offset && Char.IsWhiteSpace(document.GetCharAt(x)); --x)
++removeNumber;
if (removeNumber > 0)
{
document.Remove(line.Offset + line.Length - removeNumber, removeNumber);
}
}
}
示例13: RemoveTabs
static void RemoveTabs(IDocument document, ISelection selection, int y1, int y2)
{
document.UndoStack.StartUndoGroup();
for (int i = y2; i >= y1; --i)
{
LineSegment line = document.GetLineSegment(i);
if (i == y2 && line.Offset == selection.EndOffset)
continue;
if (line.Length > 0)
{
if (line.Length > 0)
{
int charactersToRemove = 0;
if (document.GetCharAt(line.Offset) == '\t')
{
// first character is a tab - just remove it
charactersToRemove = 1;
}
else if (document.GetCharAt(line.Offset) == ' ')
{
int leadingSpaces;
int tabIndent = document.TextEditorProperties.IndentationSize;
for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
{
// deliberately empty
}
if (leadingSpaces >= tabIndent)
{
// just remove tabIndent
charactersToRemove = tabIndent;
}
else if (line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
{
// remove the leading spaces and the following tab as they add up
// to just one tab stop
charactersToRemove = leadingSpaces + 1;
}
else
{
// just remove the leading spaces
charactersToRemove = leadingSpaces;
}
}
if (charactersToRemove > 0)
{
document.Remove(line.Offset, charactersToRemove);
}
}
}
}
document.UndoStack.EndUndoGroup();
}
示例14: RemoveTabs
void RemoveTabs(IDocument document, ISelection selection, int y1, int y2)
{
int redocounter = 0;
for (int i = y2; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
if (i == y2 && line.Offset == selection.EndOffset) {
continue;
}
if (line.Length > 0)
{
int charactersToRemove = 0;
if(document.GetCharAt(line.Offset) == '\t')
{ // first character is a tab - just remove it
charactersToRemove = 1;
}
else if(document.GetCharAt(line.Offset) == ' ')
{
int leadingSpaces = 1;
int tabIndent = document.TextEditorProperties.TabIndent;
for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
{
// deliberately empty
}
if(leadingSpaces >= tabIndent)
{
// just remove tabIndent
charactersToRemove = tabIndent;
}
else if(line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
{
// remove the leading spaces and the following tab as they add up
// to just one tab stop
charactersToRemove = leadingSpaces+1;
}
else
{
// just remove the leading spaces
charactersToRemove = leadingSpaces;
}
}
if (charactersToRemove > 0)
{
document.Remove(line.Offset,charactersToRemove);
++redocounter;
}
}
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
}
}