示例#1
0
        public IndentBlockCommand(Document document)
        {
            before = document.GetCarets();
            after = document.GetCarets();

            after.First.MoveRight();
            after.Second.MoveRight();

            var sortedBefore = Caret.Order(before);

            int firstLine = sortedBefore.First.Line;
            int lastLine = sortedBefore.Second.Line;

            if (sortedBefore.Second.Column == 0)
            {
                --lastLine;
                Caret.Max(after).MoveLeft();
            }

            for (int i = firstLine; i <= lastLine; i++)
            {
                document.Point = document.Mark = Caret.AtStartOfLine(document, i);
                inner.Add(new ReplaceText(document, "\t"));
            }

            document.SetCarets(before);
        }
示例#2
0
        public UnindentBlockCommand(Document document)
        {
            before = document.GetCarets();
            after = document.GetCarets();
            var sortedBefore = Caret.Order(before);

            for (int i = sortedBefore.First.Line; i <= sortedBefore.Second.Line; i++)
            {
                if (sortedBefore.Second.Column == 0 && sortedBefore.Second.Line == i && before.First != before.Second)
                    continue;

                document.Mark = document.Point = Caret.AtStartOfLine(document, i);

                if (document.Point.EndOfLine)
                    continue;

                if (char.IsWhiteSpace(document.Point.CharOnRight))
                {
                    if (i == before.First.Line)
                        after.First.MoveLeft();
                    if (i == before.Second.Line)
                        after.Second.MoveLeft();

                    document.MovePoint(Direction.Right);
                    inner.Add(new ReplaceText(document, ""));
                }
            }

            document.SetCarets(before);
        }