예제 #1
0
        private bool SetDecreasedIndention(char typedChar)
        {
            using (var undo = _undoHistory.CreateTransaction("set indention"))
            {
                _operations.InsertText(typedChar.ToString());

                ISmartIndent smartIndent = new VisualRustSmartIndent(_textView);

                var caret              = _textView.Caret;
                var caretPosition      = caret.Position.BufferPosition.Position;
                var textSnapshot       = _textView.TextSnapshot;
                var caretLine          = textSnapshot.GetLineFromPosition(caretPosition);
                var desiredIndentation = smartIndent.GetDesiredIndentation(caretLine);
                if (desiredIndentation.HasValue)
                {
                    _operations.MoveToPreviousCharacter(false);
                    _operations.DeleteToBeginningOfLine();
                    _operations.InsertText(GetSpaces(desiredIndentation.Value));
                    _operations.MoveToNextCharacter(false);

                    undo.Complete();
                }
                else
                {
                    return(false);
                }

                return(true);
            }
        }
예제 #2
0
        private bool SetDecreasedIndention(char typedChar)
        {
            using (var undo = _undoHistory.CreateTransaction("set indention"))
            {
                _operations.InsertText(typedChar.ToString());

                ISmartIndent smartIndent = new VisualRustSmartIndent(_textView);

            var caret = _textView.Caret;
            var caretPosition = caret.Position.BufferPosition.Position;
            var textSnapshot = _textView.TextSnapshot;
            var caretLine = textSnapshot.GetLineFromPosition(caretPosition);
                var desiredIndentation = smartIndent.GetDesiredIndentation(caretLine);
                if (desiredIndentation.HasValue)
                {
                    _operations.MoveToPreviousCharacter(false);
                    _operations.DeleteToBeginningOfLine();
                    _operations.InsertText(GetSpaces(desiredIndentation.Value));
                    _operations.MoveToNextCharacter(false);

                    undo.Complete();
                }
                else
                {
                    return false;
                }

                return true;
            }
        }