本文整理汇总了C#中Mono.TextEditor.TextEditorData.GetVirtualIndentationColumn方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.GetVirtualIndentationColumn方法的具体用法?C# TextEditorData.GetVirtualIndentationColumn怎么用?C# TextEditorData.GetVirtualIndentationColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.GetVirtualIndentationColumn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Left
public static void Left (TextEditorData data)
{
if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
data.ClearSelection ();
return;
}
if (data.Caret.Column > DocumentLocation.MinColumn) {
DocumentLine line = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column > line.Length + 1) {
if (data.Caret.AllowCaretBehindLineEnd) {
data.Caret.Column--;
} else {
data.Caret.Column = line.Length + 1;
}
} else {
int offset = data.Caret.Offset - 1;
foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) {
offset = System.Math.Min (offset, folding.Offset);
}
data.Caret.Offset = offset;
}
} else if (data.Caret.Line > DocumentLocation.MinLine) {
DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1);
var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1);
if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn)
nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation));
data.Caret.Location = nextLocation;
}
}
示例2: InsertNewLine
public static void InsertNewLine (TextEditorData data)
{
if (!data.CanEditSelection)
return;
using (var undo = data.OpenUndoGroup ()) {
if (data.IsSomethingSelected)
data.DeleteSelectedText ();
switch (data.Options.IndentStyle) {
case IndentStyle.None:
data.InsertAtCaret (data.EolMarker);
break;
case IndentStyle.Auto:
data.EnsureCaretIsNotVirtual ();
var sb = new StringBuilder (data.EolMarker);
sb.Append (data.Document.GetLineIndent (data.Caret.Line));
data.InsertAtCaret (sb.ToString ());
break;
case IndentStyle.Smart:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
NewLineSmartIndent (data);
break;
case IndentStyle.Virtual:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
var oldLine = data.Caret.Line;
var curLine = data.GetLine (oldLine);
var indentCol = data.GetVirtualIndentationColumn (data.Caret.Location);
if (curLine.Length >= data.Caret.Column) {
NewLineSmartIndent (data);
data.FixVirtualIndentation ();
data.FixVirtualIndentation (oldLine);
break;
}
data.Insert (data.Caret.Offset, data.EolMarker);
data.FixVirtualIndentation (oldLine);
data.Caret.Column = indentCol;
break;
default:
throw new ArgumentOutOfRangeException ();
}
}
}
示例3: InsertNewLine
public static void InsertNewLine (TextEditorData data)
{
if (!data.CanEditSelection)
return;
using (var undo = data.OpenUndoGroup ()) {
if (data.IsSomethingSelected) {
var end = data.MainSelection.End;
data.DeleteSelectedText ();
if (end.Column == 1) {
CaretMoveActions.InternalCaretMoveHome (data, true, false);
return;
}
}
switch (data.Options.IndentStyle) {
case IndentStyle.None:
data.InsertAtCaret (data.EolMarker);
break;
case IndentStyle.Auto:
data.EnsureCaretIsNotVirtual ();
var indent = data.Document.GetLineIndent (data.Caret.Line);
data.InsertAtCaret (data.EolMarker);
data.EnsureCaretIsNotVirtual ();
if (data.GetLine (data.Caret.Line).Length == 0)
data.InsertAtCaret (indent);
break;
case IndentStyle.Smart:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
NewLineSmartIndent (data);
break;
case IndentStyle.Virtual:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
var oldLine = data.Caret.Line;
var curLine = data.GetLine (oldLine);
var indentCol = data.GetVirtualIndentationColumn (data.Caret.Location);
if (curLine.Length >= data.Caret.Column) {
NewLineSmartIndent (data);
data.FixVirtualIndentation ();
data.FixVirtualIndentation (oldLine);
break;
}
data.Insert (data.Caret.Offset, data.EolMarker);
data.FixVirtualIndentation (oldLine);
data.Caret.Column = indentCol;
break;
default:
throw new ArgumentOutOfRangeException ();
}
}
}
示例4: Right
public static void Right (TextEditorData data)
{
if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
data.Caret.Offset = System.Math.Max (data.SelectionAnchor, data.Caret.Offset);
data.ClearSelection ();
return;
}
DocumentLine line = data.Document.GetLine (data.Caret.Line);
IEnumerable<FoldSegment > foldings = data.Document.GetStartFoldings (line);
FoldSegment segment = null;
foreach (FoldSegment folding in foldings) {
if (folding.IsFolded && folding.Column == data.Caret.Column) {
segment = folding;
break;
}
}
if (segment != null) {
data.Caret.Offset = segment.EndOffset;
return;
}
if (data.Caret.Column >= line.Length + 1) {
int nextColumn;
if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && data.Caret.Column == DocumentLocation.MinColumn) {
nextColumn = data.GetVirtualIndentationColumn (data.Caret.Location);
} else if (data.Caret.AllowCaretBehindLineEnd) {
nextColumn = data.Caret.Column + 1;
} else {
nextColumn = line.Length + 1;
}
if (data.Caret.Column < nextColumn) {
data.Caret.Column = nextColumn;
} else {
if (data.Caret.Line < data.LineCount)
data.Caret.Location = new DocumentLocation (data.Caret.Line + 1, DocumentLocation.MinColumn);
}
} else {
data.Caret.Column++;
}
}
示例5: LineEnd
public static void LineEnd (TextEditorData data)
{
if (!data.Caret.PreserveSelection)
data.ClearSelection ();
var line = data.Document.GetLine (data.Caret.Line);
var newLocation = new DocumentLocation (data.Caret.Line, line.Length + 1);
// handle folding
IEnumerable<FoldSegment> foldings = data.Document.GetStartFoldings (line);
FoldSegment segment = null;
foreach (FoldSegment folding in foldings) {
if (folding.IsFolded && folding.Contains (data.Document.LocationToOffset (newLocation))) {
segment = folding;
break;
}
}
if (segment != null)
newLocation = data.Document.OffsetToLocation (segment.EndLine.Offset + segment.EndColumn - 1);
if (newLocation != data.Caret.Location)
data.Caret.Location = newLocation;
if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual) {
int virtualIndentColumn = data.GetVirtualIndentationColumn (data.Caret.Location);
if (virtualIndentColumn > data.Caret.Column)
data.Caret.Column = virtualIndentColumn;
}
}
示例6: 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 ();
var line = data.Document.GetLine (data.Caret.Line);
// smart backspace (delete indentation)
if (data.HasIndentationTracker && (data.IndentationTracker.SupportedFeatures & IndentatitonTrackerFeatures.SmartBackspace) != 0 && (data.Options.IndentStyle == IndentStyle.Smart || data.Options.IndentStyle == IndentStyle.Virtual)) {
if (data.Caret.Column == data.GetVirtualIndentationColumn (data.Caret.Location)) {
bool isAllIndent = line.GetIndentation (data.Document).Length == data.Caret.Column - 1;
if (isAllIndent) {
var prevLine = line.PreviousLine;
var prevLineIsEmpty = prevLine != null && prevLine.Length == 0;
var startOffset = prevLine != null ? prevLine.EndOffset : 0;
data.Remove (startOffset, data.Caret.Offset - startOffset);
if (prevLine != null) {
if (prevLineIsEmpty) {
if (line.Length - data.Caret.Column - 1 > 0 && data.HasIndentationTracker) {
data.InsertAtCaret (data.IndentationTracker.GetIndentationString (data.Caret.Offset));
} else {
data.Caret.Column = data.GetVirtualIndentationColumn (prevLine.Offset);
}
}
data.FixVirtualIndentation ();
}
return;
}
}
}
// normal backspace.
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 ();
}
}
示例7: SmartBackspace
static void SmartBackspace (TextEditorData data, DocumentLine line)
{
var prevLine = line.PreviousLine;
var prevLineIsEmpty = prevLine != null && prevLine.Length == 0;
var startOffset = prevLine != null ? prevLine.EndOffset : 0;
var count = data.Caret.Offset - startOffset;
if (count < 0)
return;
data.Remove (startOffset, count);
if (prevLine != null) {
if (prevLineIsEmpty) {
if (line.Length - data.Caret.Column - 1 > 0 && data.HasIndentationTracker) {
data.InsertAtCaret (data.IndentationTracker.GetIndentationString (data.Caret.Offset));
} else {
data.Caret.Column = data.GetVirtualIndentationColumn (prevLine.Offset);
}
}
data.FixVirtualIndentation ();
}
}