Exemplo n.º 1
0
 /// <summary>
 /// Constructs a Text Change object.
 /// </summary>
 /// <param name="oldPosition">
 /// The character position in the TextBuffer at which the text change happened.
 /// </param>
 /// <param name="oldText">
 /// The text in the buffer that was replaced.
 /// </param>
 /// <param name="newText">
 /// The text that replaces the old text.
 /// </param>
 /// <param name="boundaryConditions">
 /// Information about neighboring line break characters.
 /// </param>
 public TextChange(int oldPosition, ChangeString oldText, ChangeString newText, LineBreakBoundaryConditions boundaryConditions)
 {
     if (oldPosition < 0)
     {
         throw new ArgumentOutOfRangeException("oldPosition");
     }
     _oldPosition = oldPosition;
     _newPosition = oldPosition;
     _oldText     = oldText;
     _newText     = newText;
     _lineBreakBoundaryConditions = boundaryConditions;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a Text Change object.
        /// </summary>
        /// <param name="oldPosition">
        /// The character position in the TextBuffer at which the text change happened.
        /// </param>
        /// <param name="oldText">
        /// The text in the buffer that was replaced.
        /// </param>
        /// <param name="newText">
        /// The text that replaces the old text.
        /// </param>
        /// <param name="boundaryConditions">
        /// Information about neighboring line break characters.
        /// </param>
        public TextChange(int oldPosition, StringRebuilder oldText, StringRebuilder newText, LineBreakBoundaryConditions boundaryConditions)
        {
            if (oldPosition < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(oldPosition));
            }

            _oldPosition = oldPosition;
            _newPosition = oldPosition;
            _oldText     = oldText;
            _newText     = newText;
            _lineBreakBoundaryConditions = boundaryConditions;
        }
Exemplo n.º 3
0
        private static LineBreakBoundaryConditions ComputeLineBreakBoundaryConditions(ITextSnapshot currentSnapshot, int position, int oldLength)
        {
            LineBreakBoundaryConditions conditions = LineBreakBoundaryConditions.None;

            if (position > 0 && currentSnapshot[position - 1] == '\r')
            {
                conditions = LineBreakBoundaryConditions.PrecedingReturn;
            }
            int end = position + oldLength;

            if (end < currentSnapshot.Length && currentSnapshot[end] == '\n')
            {
                conditions = conditions | LineBreakBoundaryConditions.SucceedingNewline;
            }
            return(conditions);
        }
Exemplo n.º 4
0
        static public int ComputeLineCountDelta(LineBreakBoundaryConditions boundaryConditions, StringRebuilder oldText, StringRebuilder newText)
        {
            int delta = 0;

            delta -= oldText.LineBreakCount;
            delta += newText.LineBreakCount;
            if ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0)
            {
                if (oldText.FirstCharacter == '\n')
                {
                    delta++;
                }
                if (newText.FirstCharacter == '\n')
                {
                    delta--;
                }
            }

            if ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0)
            {
                if (oldText.LastCharacter == '\r')
                {
                    delta++;
                }
                if (newText.LastCharacter == '\r')
                {
                    delta--;
                }
            }

            if ((oldText.Length == 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0))
            {
                // return and newline were adjacent before and were separated by the insertion
                delta++;
            }

            if ((newText.Length == 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0))
            {
                // return and newline were separated before and were made adjacent by the deletion
                delta--;
            }
            return(delta);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Compute the impact of a change that substitutes <paramref name="newText"/> for <paramref name="oldText"/> in the
        /// context described by the <paramref name="boundaryConditions"/>.
        /// </summary>
        /// <param name="boundaryConditions">Immediate surroundings of the change with respect to compound line breaks.</param>
        /// <param name="oldText">The replaced text.</param>
        /// <param name="newText">The newly inserted text.</param>
        /// <returns></returns>
        static public int ComputeLineCountDelta(LineBreakBoundaryConditions boundaryConditions, ChangeString oldText, ChangeString newText)
        {
            int delta = 0;

            delta -= oldText.ComputeLineBreakCount();
            delta += newText.ComputeLineBreakCount();
            if ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0)
            {
                if (oldText.Length > 0 && oldText[0] == '\n')
                {
                    delta++;
                }
                if (newText.Length > 0 && newText[0] == '\n')
                {
                    delta--;
                }
            }

            if ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0)
            {
                if (oldText.Length > 0 && oldText[oldText.Length - 1] == '\r')
                {
                    delta++;
                }
                if (newText.Length > 0 && newText[newText.Length - 1] == '\r')
                {
                    delta--;
                }
            }

            if ((oldText.Length == 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0))
            {
                // return and newline were adjacent before and were separated by the insertion
                delta++;
            }

            if ((newText.Length == 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.PrecedingReturn) != 0) &&
                ((boundaryConditions & LineBreakBoundaryConditions.SucceedingNewline) != 0))
            {
                // return and newline were separated before and were made adjacent by the deletion
                delta--;
            }
            return(delta);
        }
        private static LineBreakBoundaryConditions ComputeBoundaryConditions(TextChange outerChange, ChangeString oldText, Span leftSpan)
        {
            LineBreakBoundaryConditions bc = LineBreakBoundaryConditions.None;

            if (leftSpan.Start == 0)
            {
                bc = (outerChange.LineBreakBoundaryConditions & LineBreakBoundaryConditions.PrecedingReturn);
            }
            else if (oldText[leftSpan.Start - 1] == '\r')
            {
                bc = LineBreakBoundaryConditions.PrecedingReturn;
            }
            if (leftSpan.End == oldText.Length)
            {
                bc |= (outerChange.LineBreakBoundaryConditions & LineBreakBoundaryConditions.SucceedingNewline);
            }
            else if (oldText[leftSpan.End] == '\n')
            {
                bc |= LineBreakBoundaryConditions.SucceedingNewline;
            }
            return(bc);
        }
Exemplo n.º 7
0
 internal TextChange(int oldPosition, string oldText, string newText, LineBreakBoundaryConditions boundaryConditions)
     : this(oldPosition, StringRebuilder.Create(oldText), StringRebuilder.Create(newText), boundaryConditions)
 {
 }