/// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document insert to.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (this.text.Count == 0 || document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            if (this.line == -1)
            {
                this.line = 0;
                document.AddLine(string.Empty);
            }

            string paragraph = document.AllLines[this.line];
            string partToMove = paragraph.Substring(this.position);
            if (paragraph.Length > this.position)
            {
                paragraph = paragraph.Remove(this.position);
            }

            document.ChangeLineAtIndex(this.line, paragraph.Insert(this.position, this.text.First()));
            List<string> newLines = new List<string>(this.text);
            newLines.RemoveAt(0);
            for (int i = 0; i < newLines.Count; i++)
            {
                document.InsertLineAtIndex(this.line + i + 1, newLines[i]);
            }

            string lastLine = document.AllLines[this.line + this.text.Count - 1];
            document.ChangeLineAtIndex(this.line + this.text.Count - 1, lastLine + partToMove);
        }
示例#2
0
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document to run command.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            string paragraph = document.AllLines[this.line];
            this.changedLine = document.AllLines[this.line];

            string substringToTranslate = string.Empty;
            if (this.position < paragraph.Length)
            {
                int substringLength = paragraph.Length - this.position;
                substringToTranslate = paragraph.Substring(this.position, substringLength);
                document.ChangeLineAtIndex(this.line, paragraph.Remove(this.position, substringLength));
            }

            for (int i = 0; i < this.indentationLevel; i++)
            {
                substringToTranslate = " " + substringToTranslate;
            }

            document.InsertLineAtIndex(this.line + 1, substringToTranslate);
        }