本文整理汇总了C#中Mono.TextEditor.TextEditorData.LogicalToVisualLocation方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.LogicalToVisualLocation方法的具体用法?C# TextEditorData.LogicalToVisualLocation怎么用?C# TextEditorData.LogicalToVisualLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.LogicalToVisualLocation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOutermostClosedFold
/// <summary>
/// Gets the outermost closed fold pertaining to the current caret position
/// </summary>
static FoldSegment GetOutermostClosedFold (TextEditorData data)
{
FoldSegment currentFold = null;
int endOffset = -1, startOffset = int.MaxValue;
IEnumerable<FoldSegment> folds = data.Document.GetFoldingContaining (data.Caret.Line);
int lineNumber = data.LogicalToVisualLocation (data.Caret.Location).Line;
if (null != folds) {
foreach (FoldSegment fold in folds) {
if (fold.IsFolded && data.Document.LogicalToVisualLine (data.Document.OffsetToLineNumber (fold.Offset)) == lineNumber &&
fold.Offset <= startOffset && fold.EndOffset >= endOffset) {
currentFold = fold;
startOffset = fold.Offset;
endOffset = fold.EndOffset;
}
}
}
return currentFold;
}
示例2: CopyData
void CopyData (TextEditorData data, Selection selection)
{
copiedDocument = null;
monoDocument = null;
if (selection != null && data != null && data.Document != null) {
copiedDocument = new TextDocument ();
monoDocument = new TextDocument ();
this.docStyle = data.ColorStyle;
this.options = data.Options;
this.mode = SyntaxModeService.GetSyntaxMode (monoDocument, data.MimeType);
switch (selection.SelectionMode) {
case SelectionMode.Normal:
isBlockMode = false;
var segment = selection.GetSelectionRange (data);
var text = data.GetTextAt (segment);
copiedDocument.Text = text;
monoDocument.Text = text;
var line = data.Document.GetLineByOffset (segment.Offset);
var spanStack = line.StartSpan.Clone ();
SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, segment.Offset);
this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack;
break;
case SelectionMode.Block:
isBlockMode = true;
DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor);
DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead);
int startCol = System.Math.Min (visStart.Column, visEnd.Column);
int endCol = System.Math.Max (visStart.Column, visEnd.Column);
for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) {
DocumentLine curLine = data.Document.GetLine (lineNr);
int col1 = curLine.GetLogicalColumn (data, startCol) - 1;
int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length);
if (col1 < col2) {
copiedDocument.Insert (copiedDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1));
monoDocument.Insert (monoDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1));
}
if (lineNr < selection.MaxLine) {
// Clipboard line end needs to be system dependend and not the document one.
copiedDocument.Insert (copiedDocument.TextLength, Environment.NewLine);
// \r in mono document stands for block selection line end.
monoDocument.Insert (monoDocument.TextLength, "\r");
}
}
line = data.Document.GetLine (selection.MinLine);
spanStack = line.StartSpan.Clone ();
SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, line.Offset + startCol);
this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack;
break;
}
} else {
copiedDocument = null;
}
}
示例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: 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;
}
示例5: InsertTab
public static void InsertTab (TextEditorData data)
{
if (!data.CanEditSelection)
return;
if (data.IsMultiLineSelection && data.MainSelection.SelectionMode != SelectionMode.Block) {
IndentSelection (data);
return;
}
using (var undo = data.OpenUndoGroup ()) {
string indentationString = "\t";
bool convertTabToSpaces = data.TabsToSpaces;
if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs) {
for (int i = 1; i < data.Caret.Column; i++) {
if (data.Document.GetCharAt (data.Caret.Offset - i) != '\t') {
convertTabToSpaces = true;
break;
}
}
}
if (convertTabToSpaces) {
DocumentLocation visualLocation = data.LogicalToVisualLocation (data.Caret.Location);
int tabWidth = TextViewMargin.GetNextTabstop (data, visualLocation.Column) - visualLocation.Column;
indentationString = new string (' ', tabWidth);
}
if (data.IsSomethingSelected)
data.DeleteSelectedText (data.MainSelection.SelectionMode != SelectionMode.Block);
data.InsertAtCaret (indentationString);
}
}
示例6: CopyData
void CopyData (TextEditorData data, Selection selection)
{
if (!selection.IsEmpty && data != null && data.Document != null) {
this.docStyle = data.ColorStyle;
this.options = data.Options;
copyData = null;
switch (selection.SelectionMode) {
case SelectionMode.Normal:
isBlockMode = false;
var segment = selection.GetSelectionRange (data);
copiedColoredChunks = ColoredSegment.GetChunks (data, segment);
var pasteHandler = data.TextPasteHandler;
if (pasteHandler != null)
copyData = pasteHandler.GetCopyData (segment);
break;
case SelectionMode.Block:
isBlockMode = true;
DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor);
DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead);
int startCol = System.Math.Min (visStart.Column, visEnd.Column);
int endCol = System.Math.Max (visStart.Column, visEnd.Column);
copiedColoredChunks = new List<List<ColoredSegment>> ();
for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) {
DocumentLine curLine = data.Document.GetLine (lineNr);
int col1 = curLine.GetLogicalColumn (data, startCol) - 1;
int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length);
if (col1 < col2) {
copiedColoredChunks.Add (ColoredSegment.GetChunks (data, new TextSegment (curLine.Offset + col1, col2 - col1)).First ());
} else {
copiedColoredChunks.Add (new List<ColoredSegment> ());
}
}
break;
}
} else {
copiedColoredChunks = null;
}
}
示例7: Backspace
public static void Backspace (TextEditorData data, Action<TextEditorData> removeCharBeforeCaret)
{
if (!data.CanEditSelection)
return;
using (var undo = data.OpenUndoGroup ()) {
if (data.IsSomethingSelected) {
var visualAnchorLocation = data.LogicalToVisualLocation (data.MainSelection.Anchor);
var visualLeadLocation = data.LogicalToVisualLocation (data.MainSelection.Lead);
// case: zero width block selection
if (data.MainSelection.SelectionMode == SelectionMode.Block && visualAnchorLocation.Column == visualLeadLocation.Column) {
var col = data.MainSelection.Lead.Column;
if (col <= DocumentLocation.MinColumn) {
data.ClearSelection ();
return;
}
bool preserve = data.Caret.PreserveSelection;
data.Caret.PreserveSelection = true;
for (int lineNumber = data.MainSelection.MinLine; lineNumber <= data.MainSelection.MaxLine; lineNumber++) {
var lineSegment = data.Document.GetLine (lineNumber);
int insertOffset = lineSegment.GetLogicalColumn (data, visualAnchorLocation.Column - 1) - 1;
data.Remove (lineSegment.Offset + insertOffset, 1);
}
var visualColumn = data.GetLine (data.Caret.Location.Line).GetVisualColumn (data, col - 1);
data.MainSelection = new Selection (
new DocumentLocation (data.MainSelection.Anchor.Line, data.GetLine (data.MainSelection.Anchor.Line).GetLogicalColumn (data, visualColumn)),
new DocumentLocation (data.MainSelection.Lead.Line, data.GetLine (data.MainSelection.Lead.Line).GetLogicalColumn (data, visualColumn)),
SelectionMode.Block
);
data.Caret.PreserveSelection = preserve;
data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
return;
}
data.DeleteSelectedText (data.MainSelection.SelectionMode != SelectionMode.Block);
return;
}
if (data.Caret.Line == DocumentLocation.MinLine && data.Caret.Column == DocumentLocation.MinColumn)
return;
// Virtual indentation needs to be fixed before to have the same behavior
// if it's there or not (otherwise user has to press multiple backspaces in some cases)
data.EnsureCaretIsNotVirtual ();
DocumentLine line = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column > line.Length + 1) {
data.Caret.Column = line.Length + 1;
} else if (data.Caret.Offset == line.Offset) {
DocumentLine lineAbove = data.Document.GetLine (data.Caret.Line - 1);
if (lineAbove.Length == 0 && data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual) {
data.Caret.Location = new DocumentLocation (data.Caret.Line - 1, data.IndentationTracker.GetVirtualIndentationColumn (data.Caret.Line - 1, 1));
data.Replace (lineAbove.EndOffsetIncludingDelimiter - lineAbove.DelimiterLength, lineAbove.DelimiterLength, data.IndentationTracker.GetIndentationString (data.Caret.Line - 1, 1));
} else {
data.Remove (lineAbove.EndOffsetIncludingDelimiter - lineAbove.DelimiterLength, lineAbove.DelimiterLength);
}
} else {
removeCharBeforeCaret (data);
}
// Needs to be fixed after, the line may just contain the indentation
data.FixVirtualIndentation ();
}
}
示例8: CopyData
void CopyData (TextEditorData data, Selection selection)
{
copiedDocument = null;
monoDocument = null;
if (selection != null && data != null && data.Document != null) {
copiedDocument = new Document ();
monoDocument = new Document ();
this.docStyle = data.ColorStyle;
this.options = data.Options;
this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default;
switch (selection.SelectionMode) {
case SelectionMode.Normal:
isBlockMode = false;
ISegment segment = selection.GetSelectionRange (data);
copiedDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length);
monoDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length);
LineSegment line = data.Document.GetLineByOffset (segment.Offset);
var spanStack = line.StartSpan.Clone ();
SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset);
this.copiedDocument.GetLine (0).StartSpan = spanStack;
break;
case SelectionMode.Block:
isBlockMode = true;
DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor);
DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead);
int startCol = System.Math.Min (visStart.Column, visEnd.Column);
int endCol = System.Math.Max (visStart.Column, visEnd.Column);
for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) {
LineSegment curLine = data.Document.GetLine (lineNr);
int col1 = curLine.GetLogicalColumn (data, startCol);
int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol), curLine.EditableLength);
if (col1 < col2) {
((IBuffer)copiedDocument).Insert (copiedDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1));
((IBuffer)monoDocument).Insert (monoDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1));
}
if (lineNr < selection.MaxLine) {
// Clipboard line end needs to be system dependend and not the document one.
((IBuffer)copiedDocument).Insert (copiedDocument.Length, Environment.NewLine);
// \r in mono document stands for block selection line end.
((IBuffer)monoDocument).Insert (monoDocument.Length, "\r");
}
}
line = data.Document.GetLine (selection.MinLine);
spanStack = line.StartSpan.Clone ();
SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol);
this.copiedDocument.GetLine (0).StartSpan = spanStack;
break;
}
} else {
copiedDocument = null;
}
}
示例9: InsertTab
public static void InsertTab (TextEditorData data)
{
if (!data.CanEditSelection)
return;
if (data.IsMultiLineSelection) {
IndentSelection (data);
return;
}
data.Document.BeginAtomicUndo ();
if (data.IsSomethingSelected) {
data.DeleteSelectedText ();
}
string indentationString = "\t";
bool convertTabToSpaces = data.Options.TabsToSpaces;
if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs) {
for (int i = 1; i < data.Caret.Column; i++) {
if (data.Document.GetCharAt (data.Caret.Offset - i) != '\t') {
convertTabToSpaces = true;
break;
}
}
}
if (convertTabToSpaces) {
DocumentLocation visualLocation = data.LogicalToVisualLocation (data.Caret.Location);
int tabWidth = TextViewMargin.GetNextTabstop (data, visualLocation.Column) - visualLocation.Column;
indentationString = new string (' ', tabWidth);
}
int length = data.Insert (data.Caret.Offset, indentationString);
data.Caret.Column += length;
data.Document.EndAtomicUndo ();
}