本文整理汇总了C#中IDocument.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.Insert方法的具体用法?C# IDocument.Insert怎么用?C# IDocument.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.Insert方法的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: 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;
}
示例3: InsertEventHandler
public override int InsertEventHandler(IDocument document, string eventHandler)
{
int line = document.TotalNumberOfLines;
IDocumentLine lastLineSegment = document.GetLine(line);
int offset = lastLineSegment.Offset + lastLineSegment.Length;
string newContent = "\r\n" + eventHandler;
if (lastLineSegment.Length > 0) {
// Add an extra new line between the last line and the event handler.
newContent = "\r\n" + newContent;
}
document.Insert(offset, newContent);
// Set position so it points to the line
// where the event handler was inserted.
return line + 1;
}
示例4: InsertTabs
void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
{
string indentationString = GetIndentationString(document);
for (int i = y2; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) {
continue;
}
// this bit is optional - but useful if you are using block tabbing to sort out
// a source file with a mixture of tabs and spaces
// string newLine = document.GetText(line.Offset,line.Length);
// document.Replace(line.Offset,line.Length,newLine);
document.Insert(line.Offset, indentationString);
}
}
示例5: InsertNewLine
void InsertNewLine (IDocument document, NewLineInsertion insertion, ref int offset)
{
string eolMarker = DocumentUtilities.GetLineTerminator(document, 1);
string str = null;
switch (insertion) {
case NewLineInsertion.Eol:
str = eolMarker;
break;
case NewLineInsertion.BlankLine:
str = eolMarker + eolMarker;
break;
default:
return;
}
document.Insert (offset, str);
offset += str.Length;
}
示例6: InsertTabs
void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
{
int redocounter = 0;
string indentationString = GetIndentationString(document);
for (int i = y2; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) {
continue;
}
document.Insert(line.Offset, indentationString);
++redocounter;
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
}
}
示例7: InsertTabs
void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
{
int redocounter = 0;
string indentationString = GetIndentationString(document);
for (int i = y2; i >= y1; --i) {
LineSegment line = document.GetLineSegment(i);
if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) {
continue;
}
// this bit is optional - but useful if you are using block tabbing to sort out
// a source file with a mixture of tabs and spaces
// string newLine = document.GetText(line.Offset,line.Length);
// document.Replace(line.Offset,line.Length,newLine);
// ++redocounter;
document.Insert(line.Offset, indentationString);
++redocounter;
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
}
}
示例8: SetCommentAt
void SetCommentAt(IDocument document, int offsetStart, int offsetEnd, string commentStart, string commentEnd)
{
document.Insert(offsetEnd, commentEnd);
document.Insert(offsetStart, commentStart);
}
示例9: SetCommentAt
void SetCommentAt(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);
document.Insert(line.Offset, comment);
++redocounter;
}
if (redocounter > 0) {
document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
}
}
示例10: CreateComponentEvent
// static method that for use by the WPF designer
public static void CreateComponentEvent(
IClass c, IDocument document,
Type eventType, string eventMethodName, string body, out int lineNumber)
{
if (c == null)
throw new ArgumentNullException("c");
if (document == null)
throw new ArgumentNullException("document");
if (eventType == null)
throw new ArgumentNullException("edesc");
CSharpDesignerGenerator gen = new CSharpDesignerGenerator();
gen.CurrentClassPart = c;
int line = gen.GetEventHandlerInsertionLine(c);
int offset = document.GetLineSegment(line - 1).Offset;
string tabs = SharpDevelop.DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.IndentationString;
tabs += tabs;
document.Insert(offset, gen.CreateEventHandler(eventType, eventMethodName, body, tabs));
lineNumber = line + gen.GetCursorLineAfterEventHandlerCreation();
}
示例11: SetCommentAt
void SetCommentAt(IDocument document, int offsetStart, int offsetEnd, string commentStart, string commentEnd)
{
document.Insert(offsetEnd, commentEnd);
document.Insert(offsetStart, commentStart);
document.UndoStack.CombineLast(2);
}
示例12: SetCommentAt
void SetCommentAt(IDocument document, string comment, ISelection selection, int y1, int y2)
{
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;
}
document.Insert(line.Offset, comment);
}
}
示例13: Insert
public int 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);
return offset;
}
}
示例14: InsertEventHandlerBeforeLine
void InsertEventHandlerBeforeLine(IDocument doc, string eventHandler, IDocumentLine classEndLine)
{
string newContent = "\r\n" + eventHandler + "\r\n";
int offset = classEndLine.Offset;
doc.Insert(offset, newContent);
}