public GetIndentationString ( Mono.TextEditor.DocumentLocation loc ) : string | ||
loc | Mono.TextEditor.DocumentLocation | |
return | string |
public int GetVisualColumn(TextEditorData editor, int logicalColumn) { int result = 1; int offset = Offset; if (editor.Options.IndentStyle == IndentStyle.Virtual && Length == 0 && logicalColumn > DocumentLocation.MinColumn) { foreach (char ch in editor.GetIndentationString(Offset)) { if (ch == '\t') { result += editor.Options.TabSize; continue; } result++; } return(result); } for (int i = 0; i < logicalColumn - 1; i++) { if (i < Length && editor.Document.GetCharAt(offset + i) == '\t') { result = TextViewMargin.GetNextTabstop(editor, result); } else { result++; } } return(result); }
static void NewLineSmartIndent(TextEditorData data) { using (var undo = data.OpenUndoGroup()) { data.EnsureCaretIsNotVirtual(); data.InsertAtCaret(data.EolMarker); data.InsertAtCaret(data.GetIndentationString(data.Caret.Location)); } }
static void NewLineSmartIndent(TextEditorData data) { using (var undo = data.OpenUndoGroup()) { data.EnsureCaretIsNotVirtual(); data.InsertAtCaret(data.EolMarker); var line = data.Document.GetLine(data.Caret.Line); data.InsertAtCaret(data.GetIndentationString(line.EndOffset)); } }
static void NewLineSmartIndent(TextEditorData data) { using (var undo = data.OpenUndoGroup()) { data.EnsureCaretIsNotVirtual(); string indentString; if (data.HasIndentationTracker) { indentString = data.IndentationTracker.GetIndentationString(data.Caret.Location); } else { indentString = data.GetIndentationString(data.Caret.Location); } data.InsertAtCaret(data.EolMarker); data.InsertAtCaret(indentString); } }
static void NewLineSmartIndent(TextEditorData data) { using (var undo = data.OpenUndoGroup()) { data.EnsureCaretIsNotVirtual(); var oldCaretLine = data.Caret.Location.Line; string indentString = data.GetIndentationString(data.Caret.Location); data.InsertAtCaret(data.EolMarker); // Don't insert the indent string if the EOL insertion modified the caret location in an unexpected fashion // (This likely means someone has custom logic regarding insertion of the EOL) if (data.Caret.Location.Line == oldCaretLine + 1 && data.Caret.Location.Column == 1) { data.InsertAtCaret(indentString); } } }
public int GetVisualColumn (TextEditorData editor, int logicalColumn) { int result = 1; int offset = Offset; if (editor.Options.IndentStyle == IndentStyle.Virtual && Length == 0 && logicalColumn > DocumentLocation.MinColumn) { foreach (char ch in editor.GetIndentationString (Offset)) { if (ch == '\t') { result += editor.Options.TabSize; continue; } result++; } return result; } for (int i = 0; i < logicalColumn - 1; i++) { if (i < Length && editor.Document.GetCharAt (offset + i) == '\t') { result = TextViewMargin.GetNextTabstop (editor, result); } else { result++; } } return result; }
static void NewLineSmartIndent (TextEditorData data) { using (var undo = data.OpenUndoGroup ()) { data.EnsureCaretIsNotVirtual (); data.InsertAtCaret (data.EolMarker); data.InsertAtCaret (data.GetIndentationString (data.Caret.Location)); } }
public static void Backspace(TextEditorData data, Action <TextEditorData> removeCharBeforeCaret) { if (!data.CanEditSelection) { return; } DocumentLine line; bool smartBackspace = false; 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; var changes = new List <Microsoft.CodeAnalysis.Text.TextChange> (); 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; changes.Add(new Microsoft.CodeAnalysis.Text.TextChange(new Microsoft.CodeAnalysis.Text.TextSpan(lineSegment.Offset + insertOffset, 1), "")); } data.Document.ApplyTextChanges(changes); var visualColumn = data.GetLine(data.Caret.Location.Line).GetVisualColumn(data, col - 1); data.MainSelection = new MonoDevelop.Ide.Editor.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(); line = data.Document.GetLine(data.Caret.Line); // smart backspace (delete indentation) if (data.HasIndentationTracker && (data.IndentationTracker.SupportedFeatures & IndentationTrackerFeatures.SmartBackspace) != 0 && (data.Options.IndentStyle == IndentStyle.Smart || data.Options.IndentStyle == IndentStyle.Virtual) && data.Options.SmartBackspace) { if (data.Caret.Column == data.GetVirtualIndentationColumn(data.Caret.Location)) { bool isAllIndent = line.GetIndentation(data.Document).Length == data.Caret.Column - 1; if (isAllIndent) { if (!data.Options.GenerateFormattingUndoStep) { SmartBackspace(data, line); return; } smartBackspace = true; } } } // 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.GetVirtualIndentationColumn(data.Caret.Line - 1, 1)); data.Replace(lineAbove.EndOffsetIncludingDelimiter - lineAbove.DelimiterLength, lineAbove.DelimiterLength, data.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(); } if (data.Options.GenerateFormattingUndoStep && smartBackspace) { using (var undo = data.OpenUndoGroup()) { data.EnsureCaretIsNotVirtual(); SmartBackspace(data, line); } } }
static void NewLineSmartIndent (TextEditorData data) { using (var undo = data.OpenUndoGroup ()) { data.EnsureCaretIsNotVirtual (); string indentString; if (data.HasIndentationTracker) { indentString = data.IndentationTracker.GetIndentationString (data.Caret.Location); } else { indentString = data.GetIndentationString (data.Caret.Location); } data.InsertAtCaret (data.EolMarker); data.InsertAtCaret (indentString); } }
static void NewLineSmartIndent (TextEditorData data) { using (var undo = data.OpenUndoGroup ()) { data.EnsureCaretIsNotVirtual (); data.InsertAtCaret (data.EolMarker); var line = data.Document.GetLine (data.Caret.Line); data.InsertAtCaret (data.GetIndentationString (line.EndOffset)); } }