/// <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;

            int endCaretIndex = this.caretIndex + this.length;
            if (endCaretIndex > document.Text.Length)
            {
                endCaretIndex = document.Text.Length;
            }

            int endPosition = document.CaretPositionInLineByIndex(endCaretIndex);
            int endLineIndex = document.LineNumberByIndex(endCaretIndex);
            this.removedLines = document.AllLines.GetRange(this.line, endLineIndex - this.line + 1);

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

            document.ChangeLineAtIndex(this.line, paragraph + lineToMove);
            document.RemoveLines(this.line + 1, endLineIndex - this.line);
        }
        /// <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);
        }
示例#3
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);
        }
        /// <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;

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

            string paragraph = document.AllLines[this.line];
            document.ChangeLineAtIndex(this.line, paragraph.Insert(this.position, this.text));
        }
        /// <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);

            string paragrapgh = document.AllLines[this.line];
            int paragraphIndex = this.position;
            int length = 0;
            while (paragraphIndex < paragrapgh.Length && paragrapgh[paragraphIndex] == this.snippet.Name[length])
            {
                paragraphIndex++;
                length++;
            }

            this.removeCommand = new RemoveRangeCommand(this.caretIndex, length);
            this.removeCommand.Execute(document);
            this.insertCommand = new InsertLinesCommand(this.snippet.Content, this.caretIndex);
            this.insertCommand.Execute(document);
        }