Mono.TextEditor.TextEditorData.EnsureCaretIsNotVirtual C# (CSharp) Method

EnsureCaretIsNotVirtual() public method

Ensures the caret is not in a virtual position by adding whitespaces up to caret position. That method should always be called in an undo group.
public EnsureCaretIsNotVirtual ( ) : int
return int
		public int EnsureCaretIsNotVirtual ()
		{
			return EnsureIsNotVirtual (Caret.Location);
		}

Usage Example

Example #1
0
        static void NewLineSmartIndent(TextEditorData data)
        {
            using (var undo = data.OpenUndoGroup()) {
                data.EnsureCaretIsNotVirtual();

                var oldCaretLine = data.Caret.Location.Line;
                var indentString = data.IndentationTracker.GetIndentationString(data.Caret.Line);
                data.InsertAtCaret(data.EolMarker);

                if (data.HasIndentationTracker)
                {
                    // 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)
                    {
                        var line                    = data.GetLine(data.Caret.Line);
                        var currentIndent           = line.GetIndentation(data.Document);
                        var currentCalculatedIndent = data.IndentationTracker.GetIndentationString(data.Caret.Line);
                        if (!string.IsNullOrEmpty(currentCalculatedIndent))
                        {
                            indentString = currentCalculatedIndent;
                        }
                        if (indentString != currentIndent)
                        {
                            data.InsertAtCaret(indentString);
                        }
                    }
                }
            }
        }
All Usage Examples Of Mono.TextEditor.TextEditorData::EnsureCaretIsNotVirtual