Example #1
0
        /// <summary>
        /// Performs the given operation on the line buffer. This will raise any
        /// events that were appropriate for the operation.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        /// <returns>
        /// The results to the changes to the buffer.
        /// </returns>
        protected override LineBufferOperationResults Do(
            InsertTextOperation operation)
        {
            LineBufferOperationResults results = base.Do(operation);

            return(CheckForStyleChanged(
                       (int)operation.TextPosition.LinePosition, results));
        }
Example #2
0
        /// <summary>
        /// Deletes text from the buffer.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        /// <returns>
        /// The results to the changes to the buffer.
        /// </returns>
        protected override LineBufferOperationResults Do(
            DeleteTextOperation operation)
        {
            LineBufferOperationResults results = base.Do(operation);

            int lineIndex = operation.TextRange.FirstLinePosition.GetLineIndex(LineCount);

            return(CheckForStyleChanged(lineIndex, results));
        }
        private LineBufferOperationResults GetOperationResults()
        {
            int blockIndex =
                project.Blocks.IndexOf(project.Commands.LastPosition.BlockKey);
            var results =
                new LineBufferOperationResults(
                    new TextPosition(blockIndex, (int)project.Commands.LastPosition.TextIndex));

            return(results);
        }
        public void InsertOneLine()
        {
            // Setup

            // Operation
            LineBufferOperationResults results = buffer.InsertLines(0, 1);

            // Validation
            Assert.AreEqual(2, buffer.LineCount);
            Assert.AreEqual(1, results.TextPosition.LinePosition.Index);
            Assert.AreEqual(0, results.TextPosition.CharacterPosition.Index);
        }
        public void SetTextIntoEmptyLine()
        {
            // Setup
            const string input = "Test";

            // Operation
            LineBufferOperationResults results = buffer.SetText(0, input);

            // Verification
            Assert.AreEqual(input, buffer.GetLineText(0, LineContexts.None));
            Assert.AreEqual(input.Length, buffer.GetLineLength(0, LineContexts.None));
            Assert.AreEqual(0, results.TextPosition.LinePosition.Index);
            Assert.AreEqual(input.Length, results.TextPosition.CharacterPosition.Index);
        }
        public void DeleteTextFromMaxEndOfLine()
        {
            // Setup
            const string input = "one two three";

            buffer.SetText(0, input);

            // Operation
            LineBufferOperationResults results = buffer.DeleteText(0, 7, Int32.MaxValue);

            // Verification
            Assert.AreEqual("one two", buffer.GetLineText(0, LineContexts.None));
            Assert.AreEqual("one two".Length, buffer.GetLineLength(0, LineContexts.None));
            Assert.AreEqual(0, results.TextPosition.LinePosition.Index);
            Assert.AreEqual(7, results.TextPosition.CharacterPosition.Index);
        }
        /// <summary>
        /// Performs the set text operation on the buffer.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        /// <returns>
        /// The results to the changes to the buffer.
        /// </returns>
        protected override LineBufferOperationResults Do(SetTextOperation operation)
        {
            // Set the text of the line.
            lines[operation.LineIndex] = operation.Text;

            // Fire a line changed operation.
            var lineChangedArgs = new LineChangedArgs(operation.LineIndex);

            RaiseLineChanged(lineChangedArgs);

            // Return the appropriate results.
            var bufferPosition = new TextPosition(
                operation.LineIndex, CharacterPosition.End);
            var results = new LineBufferOperationResults(bufferPosition);

            return(results);
        }
        public void InsertTextIntoBeginningOfLine()
        {
            // Setup
            const string input = "Test ";

            buffer.SetText(0, "Original");

            // Operation
            LineBufferOperationResults results = buffer.InsertText(
                new TextPosition(0, 0), input);

            // Verification
            Assert.AreEqual("Test Original", buffer.GetLineText(0, LineContexts.None));
            Assert.AreEqual(
                "Test Original".Length, buffer.GetLineLength(0, LineContexts.None));
            Assert.AreEqual(0, results.TextPosition.LinePosition.Index);
            Assert.AreEqual(input.Length, results.TextPosition.CharacterPosition.Index);
        }
        public void InsertTextIntoMiddleOfLine()
        {
            // Setup
            const string input = "two ";

            buffer.SetText(0, "one three");

            // Operation
            LineBufferOperationResults results = buffer.InsertText(
                new TextPosition(0, 4), input);

            // Verification
            Assert.AreEqual("one two three", buffer.GetLineText(0, LineContexts.None));
            Assert.AreEqual(
                "one two three".Length, buffer.GetLineLength(0, LineContexts.None));
            Assert.AreEqual(0, results.TextPosition.LinePosition.Index);
            Assert.AreEqual(
                4 + input.Length, results.TextPosition.CharacterPosition.Index);
        }
 private LineBufferOperationResults GetOperationResults()
 {
     int blockIndex =
         project.Blocks.IndexOf(project.Commands.LastPosition.BlockKey);
     var results =
         new LineBufferOperationResults(
             new TextPosition(blockIndex, (int) project.Commands.LastPosition.TextIndex));
     return results;
 }
Example #11
0
        /// <summary>
        /// Checks to see if a line operation caused a style to change.
        /// </summary>
        /// <param name="lineIndex">Index of the line.</param>
        /// <param name="results">The results.</param>
        /// <returns></returns>
        private LineBufferOperationResults CheckForStyleChanged(
            int lineIndex,
            LineBufferOperationResults results)
        {
            // Look to see if the line starts with a style change keyword.
            string line = GetLineText(lineIndex);

            if (line.Length < 2 ||
                line.Substring(1, 1) != ":")
            {
                // We don't have a style change, so just return the results.
                return(results);
            }

            // Check to see if we have a style change prefix.
            bool changed = false;

            switch (Char.ToUpper(line[0]))
            {
            case 'T':
                styles.Remove(lineIndex);
                changed = true;
                break;

            case 'B':
                styles[lineIndex] = DemoLineStyleType.Borders;
                changed           = true;
                break;

            case 'C':
                styles[lineIndex] = DemoLineStyleType.Chapter;
                changed           = true;
                break;

            case 'H':
                styles[lineIndex] = DemoLineStyleType.Heading;
                changed           = true;
                break;
            }

            // If we didn't change anything, then just return the unaltered
            // results.
            if (!changed)
            {
                return(results);
            }

            // Figure out what the line would look like without the prefix.
            string newLine    = line.Substring(2).TrimStart(' ');
            int    difference = line.Length - newLine.Length;

            // Set the line text.
            SetText(lineIndex, newLine);

            // Adjust the buffer position and return it.
            int characterIndex =
                results.TextPosition.CharacterPosition.GetCharacterIndex(newLine);

            results.TextPosition = new TextPosition(
                results.TextPosition.LinePosition, Math.Max(0, characterIndex - difference));

            return(results);
        }
Example #12
0
        /// <summary>
        /// Performs the set text operation on the buffer.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        /// <returns>
        /// The results to the changes to the buffer.
        /// </returns>
        protected override LineBufferOperationResults Do(SetTextOperation operation)
        {
            LineBufferOperationResults results = base.Do(operation);

            return(CheckForStyleChanged(operation.LineIndex, results));
        }