本文整理汇总了C#中Mono.TextEditor.TextEditorData.PasteText方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.PasteText方法的具体用法?C# TextEditorData.PasteText怎么用?C# TextEditorData.PasteText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.PasteText方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PastePlainText
static int PastePlainText (TextEditorData data, int offset, string text)
{
int inserted;
using (var undo = data.OpenUndoGroup ()) {
var version = data.Document.Version;
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
offset = version.MoveOffsetTo (data.Document.Version, offset);
inserted = data.Insert (offset, text);
}
data.PasteText (offset, text, inserted);
return inserted;
}
示例2: PastePlainText
static int PastePlainText (TextEditorData data, int offset, string text, bool preserveSelection = false)
{
int inserted = 0;
using (var undo = data.OpenUndoGroup ()) {
var version = data.Document.Version;
if (!preserveSelection)
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
var selection = data.MainSelection;
var visualInsertLocation = data.LogicalToVisualLocation (selection.Anchor);
for (int lineNumber = selection.MinLine; lineNumber <= selection.MaxLine; lineNumber++) {
var lineSegment = data.GetLine (lineNumber);
int insertOffset = lineSegment.GetLogicalColumn (data, visualInsertLocation.Column) - 1;
string textToInsert;
if (lineSegment.Length < insertOffset) {
int visualLastColumn = lineSegment.GetVisualColumn (data, lineSegment.Length + 1);
int charsToInsert = visualInsertLocation.Column - visualLastColumn;
int spaceCount = charsToInsert % data.Options.TabSize;
textToInsert = new string ('\t', (charsToInsert - spaceCount) / data.Options.TabSize) + new string (' ', spaceCount) + text;
insertOffset = lineSegment.Length;
} else {
textToInsert = text;
}
inserted = data.Insert (lineSegment.Offset + insertOffset, textToInsert);
}
} else {
offset = version.MoveOffsetTo (data.Document.Version, offset);
inserted = data.PasteText (offset, text);
}
}
return inserted;
}
示例3: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes [0] & 1) == 1;
bool pasteLine = (selBytes [0] & 2) == 2;
using (var undo = data.OpenUndoGroup ()) {
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
if (pasteBlock) {
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
DocumentLine curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.TextLength, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines [i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
}
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
}
} else if (pasteLine) {
result = text.Length;
DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
data.Insert (curLine.Offset, text + data.EolMarker);
} else {
int offset = data.Caret.Offset;
data.InsertAtCaret (text);
data.PasteText (offset, text, data.Caret.Offset - offset);
}
/* data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
data.Caret.Location,
lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
}
});
// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
return result;
}
if (result < 0 && clipboard.WaitIsTextAvailable ()) {
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
using (var undo = data.OpenUndoGroup ()) {
int caretPos = data.Caret.Offset;
if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
data.Caret.PreserveSelection = true;
data.DeleteSelectedText (false);
int textLength = 0;
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
var visualInsertLocation = data.LogicalToVisualLocation (data.Caret.Location);
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
DocumentLine lineSegment = data.GetLine (lineNumber);
int insertOffset = lineSegment.GetLogicalColumn (data, visualInsertLocation.Column) - 1;
if (lineSegment.Length < insertOffset) {
int visualLastColumn = lineSegment.GetVisualColumn (data, lineSegment.Length + 1);
int charsToInsert = visualInsertLocation.Column - visualLastColumn;
int spaceCount = charsToInsert % data.Options.TabSize;
string textToInsert = new string ('\t', (charsToInsert - spaceCount) / data.Options.TabSize) + new string (' ', spaceCount) + text;
insertOffset = lineSegment.Length;
int insertedChars = data.Insert (lineSegment.Offset + insertOffset, textToInsert);
data.PasteText (lineSegment.Offset + insertOffset, textToInsert, insertedChars);
} else {
textLength = data.Insert (lineSegment.Offset + insertOffset, text);
data.PasteText (lineSegment.Offset + insertOffset, text, textLength);
}
}
data.MainSelection.Anchor = new DocumentLocation (System.Math.Max (DocumentLocation.MinLine, data.Caret.Line == minLine ? maxLine : minLine), System.Math.Max (DocumentLocation.MinColumn, data.Caret.Column - textLength));
data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
data.Caret.PreserveSelection = false;
//.........这里部分代码省略.........
示例4: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes [0] & 1) == 1;
bool pasteLine = (selBytes [0] & 2) == 2;
// var clearSelection = data.IsSomethingSelected ? data.MainSelection.SelectionMode != SelectionMode.Block : true;
if (pasteBlock) {
using (var undo = data.OpenUndoGroup ()) {
var version = data.Document.Version;
if (!preserveSelection)
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
insertionOffset = version.MoveOffsetTo (data.Document.Version, insertionOffset);
data.Caret.PreserveSelection = true;
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
DocumentLine curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.TextLength, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines [i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
}
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
}
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
} else if (pasteLine) {
using (var undo = data.OpenUndoGroup ()) {
if (!preserveSelection)
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
data.Caret.PreserveSelection = true;
result = text.Length;
DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
data.PasteText (curLine.Offset, text + data.EolMarker);
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
} else {
result = PastePlainText (data, insertionOffset, text, preserveSelection);
}
}
});
// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
return result;
}
if (result < 0 && clipboard.WaitIsTextAvailable ()) {
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
using (var undo = data.OpenUndoGroup ()) {
result = PastePlainText (data, insertionOffset, text, preserveSelection);
}
});
}
return result;
}
示例5: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes[0] & 1) == 1;
bool pasteLine = (selBytes[0] & 2) == 2;
if (!pasteBlock && !pasteLine)
return;
data.Document.BeginAtomicUndo ();
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
if (pasteBlock) {
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
LineSegment curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.Length, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines[i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.EditableLength + 1 < lineCol) {
result += lineCol - curLine.EditableLength;
data.Insert (curLine.Offset + curLine.EditableLength, new string (' ', lineCol - curLine.EditableLength));
}
data.Insert (curLine.Offset + lineCol, lines[i]);
result += lines[i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines[i].Length;
}
} else if (pasteLine) {
result += text.Length;
LineSegment curLine = data.Document.GetLine (data.Caret.Line);
data.Insert (curLine.Offset, text + data.EolMarker);
if (!preserveState)
data.Caret.Offset += text.Length + data.EolMarker.Length;
}
/* data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
data.Caret.Location,
lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
data.Document.EndAtomicUndo ();
}
});
if (result < 0) {
clipboard.WaitIsTextAvailable ();
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
data.Document.BeginAtomicUndo ();
int caretPos = data.Caret.Offset;
if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
data.Caret.PreserveSelection = true;
if (!data.MainSelection.IsDirty) {
data.DeleteSelectedText (false);
data.MainSelection.IsDirty = true;
}
int textLength = 0;
int column = data.Caret.Column;
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
int offset = data.Document.GetLine (lineNumber).Offset + column;
textLength = data.Insert (offset, text);
data.PasteText (offset, text);
}
data.Caret.Offset += textLength;
data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, data.Caret.Column - textLength);
data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
data.Caret.PreserveSelection = false;
data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
} else {
ISegment selection = data.SelectionRange;
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
//int oldLine = data.Caret.Line;
int textLength = data.Insert (insertionOffset, text);
result = textLength;
//.........这里部分代码省略.........
示例6: PastePlainText
static void PastePlainText (TextEditorData data, string text)
{
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
int offset = data.Caret.Offset;
data.InsertAtCaret (text);
data.PasteText (offset, text, data.Caret.Offset - offset);
}
示例7: SetCompletionText
public static void SetCompletionText (TextEditorData data, CodeCompletionContext ctx, string partial_word, string complete_word, int wordOffset)
{
if (data == null || data.Document == null)
return;
int triggerOffset = ctx.TriggerOffset;
int length = String.IsNullOrEmpty (partial_word) ? 0 : partial_word.Length;
bool blockMode = false;
if (data.IsSomethingSelected) {
blockMode = data.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block;
if (blockMode) {
data.Caret.PreserveSelection = true;
triggerOffset = data.Caret.Offset - length;
} else {
if (data.SelectionRange.Offset < ctx.TriggerOffset)
triggerOffset = ctx.TriggerOffset - data.SelectionRange.Length;
data.DeleteSelectedText ();
}
length = 0;
}
// | in the completion text now marks the caret position
int idx = complete_word.IndexOf ('|');
if (idx >= 0) {
complete_word = complete_word.Remove (idx, 1);
}
triggerOffset += data.EnsureCaretIsNotVirtual ();
if (blockMode) {
using (var undo = data.OpenUndoGroup ()) {
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
int column = triggerOffset - data.Document.GetLineByOffset (triggerOffset).Offset;
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
DocumentLine lineSegment = data.Document.GetLine (lineNumber);
if (lineSegment == null)
continue;
int offset = lineSegment.Offset + column;
data.Replace (offset, length, complete_word);
}
int minColumn = System.Math.Min (data.MainSelection.Anchor.Column, data.MainSelection.Lead.Column);
data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, minColumn);
data.MainSelection.Lead = data.Caret.Location;
data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
data.Caret.PreserveSelection = false;
}
} else {
data.Replace (triggerOffset, length, complete_word);
}
data.Document.CommitLineUpdate (data.Caret.Line);
if (idx >= 0)
data.Caret.Offset = triggerOffset + idx;
data.PasteText (triggerOffset, complete_word, complete_word.Length);
}
示例8: PastePlainText
static int PastePlainText (TextEditorData data, int offset, string text)
{
int inserted = data.Insert (offset, text);
data.PasteText (offset, text, inserted);
return inserted;
}