private void IndentCaretInNewScope(IScope scope, ISnapshotPoint caretBufferPoint, RFormatOptions options) { if (scope?.OpenCurlyBrace == null) { return; } var rSnapshot = caretBufferPoint.Snapshot; var rTextBuffer = rSnapshot.EditorBuffer; var innerIndentSize = SmartIndenter.InnerIndentSizeFromNode(rTextBuffer, scope, options); var openBraceLineNumber = rSnapshot.GetLineNumberFromPosition(scope.OpenCurlyBrace.Start); var braceLine = rSnapshot.GetLineFromLineNumber(openBraceLineNumber); var indentLine = rSnapshot.GetLineFromLineNumber(openBraceLineNumber + 1); var lineBreakText = braceLine.LineBreak; rTextBuffer.Insert(indentLine.Start, lineBreakText); // Fetch the line again since snapshot has changed when line break was inserted indentLine = rTextBuffer.CurrentSnapshot.GetLineFromLineNumber(openBraceLineNumber + 1); // Map new caret position back to the view var positionInView = _editorView.MapToView(rTextBuffer.CurrentSnapshot, indentLine.Start); if (positionInView != null) { var viewIndentLine = _editorView.EditorBuffer.CurrentSnapshot.GetLineFromPosition(positionInView.Position); _editorView.Caret.MoveTo(viewIndentLine.Start, innerIndentSize); } }
public CaretPosition(ISnapshotPoint point, int virtualSpaces) { _point = point; VirtualSpaces = virtualSpaces; }