Пример #1
0
        internal override ActionResults Execute(Selection selection, params object[] args)
        {
            undoPos = selection.Start;
            redoSel = selection.Clone();

            if (!selection.IsEmpty)
            {
                @string = DeleteRangeCommand.DeleteRange(Ed, selection);
            }

            var indentKey = Ed.AffinityManager.GetAffinity(new Pos(undoPos.Line, 0)).GetIndentComponentKey(Ed);
            var pos       = InsertNewLine(Document, undoPos);

            selection.Clear(pos);

            var comp = indentKey != null?App.Catalog <IDentComponent>().GetComponent(indentKey) : null;

            indent = comp != null?comp.CalculateIndentation((IView)Ed.FindForm(), pos.Line) : 0;

            if (indent > 0)
            {
                if (pos.Line > 0)
                {
                    var ln = Document.Lines[pos.Line - 1];

                    if (ln.IsEmpty() && ln.Length > 0)
                    {
                        unindent = ln.ToList();
                        ln.RemoveRange(0, ln.Length);
                    }
                }

                var str = Ed.UseTabs ? new string('\t', indent / Ed.IndentSize)
                    : new string(' ', indent);
                Document.Lines[pos.Line].Insert(0, str.MakeCharacters());
                selection.Clear(new Pos(pos.Line, pos.Col + str.Length));
            }

            return(Change);
        }