コード例 #1
0
        private static void IndentCaretInNewScope(IEditorView editorView, 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);
            }
        }
コード例 #2
0
ファイル: SmartIndenter.cs プロジェクト: gbull122/vscode-r
        public int?GetDesiredIndentation(IEditorLine line)
        {
            var res = GetDesiredIndentation(line, _settings.IndentStyle);

            if (res != null && line.Snapshot.EditorBuffer != _view.EditorBuffer)
            {
                var target = _view.MapToView(line.Snapshot, line.Start);
                if (target != null)
                {
                    // The indentation level is relative to the line in the text view when
                    // we were created, not to the line we were provided with on this call.
                    var diff = target.Position - target.GetContainingLine().Start;
                    return(diff + res);
                }
            }
            return(res);
        }