示例#1
0
        public void TextChange_EditWhitespaceTest(int start, int oldLength, int newLength, string newText, TextChangeType expected) {
            string expression = "x <- a + b";

            using (var tree = EditorTreeTest.ApplyTextChange(_coreShell, expression, start, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
示例#2
0
        public void TextChange_EditComment01(int oldLength, int newLength, string newText, TextChangeType expected) {
            string expression = "x <- a + b # comment";

            using (var tree = EditorTreeTest.ApplyTextChange(_coreShell, expression, 12, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
示例#3
0
 // Token: 0x06002BD1 RID: 11217 RVA: 0x000C7918 File Offset: 0x000C5B18
 private void AddChange(ITextPointer startPosition, int symbolCount, PrecursorTextChangeType precursorTextChange)
 {
     Invariant.Assert(!this._isReadOnly, "Illegal to modify DocumentSequenceTextContainer inside Change event scope!");
     ((ITextContainer)this).BeginChange();
     try
     {
         if (this.Changing != null)
         {
             this.Changing(this, EventArgs.Empty);
         }
         if (this._changes == null)
         {
             this._changes = new TextContainerChangedEventArgs();
         }
         this._changes.AddChange(precursorTextChange, DocumentSequenceTextPointer.GetOffsetToPosition(this._start, startPosition), symbolCount, false);
         if (this.Change != null)
         {
             Invariant.Assert(precursorTextChange == PrecursorTextChangeType.ContentAdded || precursorTextChange == PrecursorTextChangeType.ContentRemoved);
             TextChangeType textChange = (precursorTextChange == PrecursorTextChangeType.ContentAdded) ? TextChangeType.ContentAdded : TextChangeType.ContentRemoved;
             this._isReadOnly = true;
             try
             {
                 this.Change(this, new TextContainerChangeEventArgs(startPosition, symbolCount, -1, textChange));
             }
             finally
             {
                 this._isReadOnly = false;
             }
         }
     }
     finally
     {
         ((ITextContainer)this).EndChange();
     }
 }
示例#4
0
 private static TextChangedEvent updateLine(TextChangeType type, int line, string text, TextChangedEvent e = null)
 {
     if (e==null) e = new TextChangedEvent();
     ITextLine snapshot = new TextLineSnapshot(line, text, null);
     e.TextChanges.Add(new TextChange(type, line, snapshot));
     return e;
 }
示例#5
0
 // Token: 0x0600539A RID: 21402 RVA: 0x00173170 File Offset: 0x00171370
 private void AddChange(ITextPointer startPosition, int symbolCount, PrecursorTextChangeType precursorTextChange)
 {
     Invariant.Assert(this._changeBlockLevel > 0, "All public APIs must call BeginChange!");
     Invariant.Assert(!this._isReadOnly, "Illegal to modify PasswordTextContainer inside Change event scope!");
     if (this.Changing != null)
     {
         this.Changing(this, EventArgs.Empty);
     }
     if (this._changes == null)
     {
         this._changes = new TextContainerChangedEventArgs();
     }
     this._changes.AddChange(precursorTextChange, startPosition.Offset, symbolCount, false);
     if (this.Change != null)
     {
         Invariant.Assert(precursorTextChange == PrecursorTextChangeType.ContentAdded || precursorTextChange == PrecursorTextChangeType.ContentRemoved);
         TextChangeType textChange = (precursorTextChange == PrecursorTextChangeType.ContentAdded) ? TextChangeType.ContentAdded : TextChangeType.ContentRemoved;
         this._isReadOnly = true;
         try
         {
             this.Change(this, new TextContainerChangeEventArgs(startPosition, symbolCount, symbolCount, textChange));
         }
         finally
         {
             this._isReadOnly = false;
         }
     }
 }
示例#6
0
        public void EditComment01(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            const string expression = "x <- a + b # comment";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 12, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
 internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange, DependencyProperty property, bool affectsRenderOnly) 
 {
     _textPosition = textPosition.GetFrozenPointer(LogicalDirection.Forward); 
     _count = count; 
     _charCount = charCount;
     _textChange = textChange; 
     _property = property;
     _affectsRenderOnly = affectsRenderOnly;
 }
 internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange, DependencyProperty property, bool affectsRenderOnly)
 {
     _textPosition      = textPosition.GetFrozenPointer(LogicalDirection.Forward);
     _count             = count;
     _charCount         = charCount;
     _textChange        = textChange;
     _property          = property;
     _affectsRenderOnly = affectsRenderOnly;
 }
示例#9
0
        public void Clear()
        {
            TextChangeType    = TextChangeType.Trivial;
            OldRange          = TextRange.EmptyRange;
            NewRange          = TextRange.EmptyRange;
            FullParseRequired = false;

            OldTextProvider = null;
            NewTextProvider = null;
        }
示例#10
0
        public static TextChangedEvent UpdateLine(TextChangeType type, int line, string text, TextChangedEvent e = null)
        {
            if (e == null)
            {
                e = new TextChangedEvent();
            }
            ITextLine snapshot = new TextLineSnapshot(line, text, null);

            e.TextChanges.Add(new TextChange(type, line, snapshot));
            return(e);
        }
        private void AddChange(ITextPointer startPosition, int symbolCount, PrecursorTextChangeType precursorTextChange)
        {
            Invariant.Assert(!_isReadOnly, "Illegal to modify DocumentSequenceTextContainer inside Change event scope!");

            ITextContainer textContainer = (ITextContainer)this;

            textContainer.BeginChange();
            try
            {
                // Contact any listeners.
                if (this.Changing != null)
                {
                    Changing(this, EventArgs.Empty);
                }

                // Fire the ChangingEvent now if we haven't already.
                if (_changes == null)
                {
                    _changes = new TextContainerChangedEventArgs();
                }

                _changes.AddChange(precursorTextChange, DocumentSequenceTextPointer.GetOffsetToPosition(_start, startPosition), symbolCount, false /* collectTextChanges */);

                if (this.Change != null)
                {
                    Invariant.Assert(precursorTextChange == PrecursorTextChangeType.ContentAdded || precursorTextChange == PrecursorTextChangeType.ContentRemoved);
                    TextChangeType textChange = (precursorTextChange == PrecursorTextChangeType.ContentAdded) ?
                                                TextChangeType.ContentAdded : TextChangeType.ContentRemoved;

                    _isReadOnly = true;
                    try
                    {
                        // Pass in a -1 for charCount parameter.  DocumentSequenceTextContainer
                        // doesn't support this feature because it is only consumed by IMEs
                        // which never run on read-only documents.
                        Change(this, new TextContainerChangeEventArgs(startPosition, symbolCount, -1, textChange));
                    }
                    finally
                    {
                        _isReadOnly = false;
                    }
                }
            }
            finally
            {
                textContainer.EndChange();
            }
        }
示例#12
0
        internal override TextChangedEvent Decode()
        {
            var result = new TextChangedEvent();

            foreach (MsgPack item in msgpack.ForcePathObject("Events"))
            {
                TextChangeType type     = (TextChangeType)item.AsArray[0].AsInteger; //Type
                int            line     = (int)item.AsArray[1].AsInteger;            //Line
                string         text     = item.AsArray[2].AsString;                  //Text
                ITextLine      snapshot = new TextLineSnapshot(line, text, null);
                result.TextChanges.Add(new TextChange(type, line, snapshot));
            }
            //System.Console.WriteLine("TextChangedEventSerializer.Decode(): decoded "+result.TextChanges.Count+" events.");
            //foreach(var change in result.TextChanges) System.Console.WriteLine(" - "+change.ToString());
            return(result);
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        private void AddChange(ITextPointer startPosition, int symbolCount, PrecursorTextChangeType precursorTextChange)
        {
            Invariant.Assert(_changeBlockLevel > 0, "All public APIs must call BeginChange!");
            Invariant.Assert(!_isReadOnly, "Illegal to modify PasswordTextContainer inside Change event scope!");

            // Contact any listeners.
            if (this.Changing != null)
            {
                Changing(this, EventArgs.Empty);
            }

            // Fire the ChangingEvent now if we haven't already.
            if (_changes == null)
            {
                _changes = new TextContainerChangedEventArgs();
            }

            _changes.AddChange(precursorTextChange, startPosition.Offset, symbolCount, false /* collectTextChanges */);

            if (this.Change != null)
            {
                Invariant.Assert(precursorTextChange == PrecursorTextChangeType.ContentAdded || precursorTextChange == PrecursorTextChangeType.ContentRemoved);
                TextChangeType textChange = (precursorTextChange == PrecursorTextChangeType.ContentAdded) ?
                                            TextChangeType.ContentAdded : TextChangeType.ContentRemoved;

                _isReadOnly = true;
                try
                {
                    Change(this, new TextContainerChangeEventArgs(startPosition, symbolCount, symbolCount, textChange));
                }
                finally
                {
                    _isReadOnly = false;
                }
            }
        }
示例#14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">Type of chage applied to the line</param>
 /// <param name="lineIndex">Index of the line which was changed</param>
 /// <param name="newLine">New line content after the update (null in case of a LineRemoved event)</param>
 public TextChange(TextChangeType type, int lineIndex, ITextLine newLine)
 {
     Type      = type;
     LineIndex = lineIndex;
     NewLine   = newLine;
 }
示例#15
0
        public void Clear()
        {
            TextChangeType = TextChangeType.Trivial;
            OldRange = TextRange.EmptyRange;
            NewRange = TextRange.EmptyRange;
            FullParseRequired = false;

            OldTextProvider = null;
            NewTextProvider = null;
        }
示例#16
0
        /// <summary>
        /// Combines one text change with another
        /// </summary>
        public void Combine(TextChange other)
        {
            if (other.IsEmpty)
                return;

            FullParseRequired |= other.FullParseRequired;
            TextChangeType |= other.TextChangeType;

            if (OldRange == TextRange.EmptyRange || NewRange == TextRange.EmptyRange)
            {
                OldRange = other.OldRange;
                NewRange = other.NewRange;
                OldTextProvider = other.OldTextProvider;
                NewTextProvider = other.NewTextProvider;
            }
            else
            {
                ITextSnapshotProvider oldSnapshotProvider = OldTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider newSnapshotProvider = NewTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider otherOldSnapshotProvider = other.OldTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider otherNewSnapshotProvider = other.NewTextProvider as ITextSnapshotProvider;
                bool changesAreFromNextSnapshot = false;

                if ((oldSnapshotProvider != null) && (newSnapshotProvider != null) && 
                    (otherOldSnapshotProvider != null) && (otherNewSnapshotProvider != null))
                {
                    ITextSnapshot newSnapshot = newSnapshotProvider.Snapshot;
                    ITextSnapshot otherOldSnapshot = otherOldSnapshotProvider.Snapshot;
                    if (newSnapshot.Version.ReiteratedVersionNumber == otherOldSnapshot.Version.ReiteratedVersionNumber)
                    {
                        changesAreFromNextSnapshot = true;
                    }
                }

                if (!changesAreFromNextSnapshot)
                {
                    // Assume these changes are from the same snapshot
                    int oldStart = Math.Min(other.OldRange.Start, this.OldRange.Start);
                    int oldEnd = Math.Max(other.OldRange.End, this.OldRange.End);

                    int newStart = Math.Min(other.NewRange.Start, this.NewRange.Start);
                    int newEnd = Math.Max(other.NewRange.End, this.NewRange.End);

                    OldRange = TextRange.FromBounds(oldStart, oldEnd);
                    NewRange = TextRange.FromBounds(newStart, newEnd);
                }
                else
                {
                    // the "other" change is from the subsequent snapshot. Merge the changes.
                    ITextSnapshot oldSnapshot = oldSnapshotProvider.Snapshot;
                    ITextSnapshot newSnapshot = newSnapshotProvider.Snapshot;
                    ITextSnapshot otherOldSnapshot = otherOldSnapshotProvider.Snapshot;
                    ITextSnapshot otherNewSnapshot = otherNewSnapshotProvider.Snapshot;

                    SnapshotSpan otherOldSpan = other.OldRange.ToSnapshotSpan(otherOldSnapshot);
                    SnapshotSpan oldSpan = otherOldSpan.TranslateTo(oldSnapshot, SpanTrackingMode.EdgeInclusive);

                    SnapshotSpan newSpan = NewRange.ToSnapshotSpan(newSnapshot);
                    SnapshotSpan otherNewSpan = newSpan.TranslateTo(otherNewSnapshot, SpanTrackingMode.EdgeInclusive);

                    OldRange = new TextRange(TextRange.Union(OldRange, oldSpan.ToTextRange()));
                    NewRange = new TextRange(TextRange.Union(other.NewRange, otherNewSpan.ToTextRange()));
                    NewTextProvider = other.NewTextProvider;
                }
            }

            Version = Math.Max(this.Version, other.Version);
        }
 public TxtChangedEventArgs(TextChangeType textChangeType, TranslationType?translationType, string text)
 {
     ChangeType      = textChangeType;
     TranslationType = translationType;
     Text            = text;
 }
示例#18
0
 public TextChangedEventArgs(TextChangeType textChangeType, char charAddedOrDeleted)
 {
     this.textChangeType     = textChangeType;
     this.charAddedOrDeleted = charAddedOrDeleted;
 }
        //----------------------------------------------------- 
        //
        //  Constructors
        //
        //----------------------------------------------------- 

        #region Constructors 
 
        internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange) :
            this(textPosition, count, charCount, textChange, null, false) 
        {
        }
示例#20
0
        public void TextChange_EditString(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + \"boo\"";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 10, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
示例#21
0
 private static void CheckLine(string filename, TextChangeMap tce, int index, string expectedText, TextChangeType expectedTextChangeType = TextChangeType.LineInserted, string expectedSequenceNumber = null, string expectedComment = null)
 {
     bool hasError = false;
     string error = filename + "," + index + ": ";
     hasError = hasError | (tce.LineIndex != index);
     if (hasError)
     {
         error += "[line index: " + tce.LineIndex + ", expected: " + index + "]";
     }
     hasError = hasError | (tce.Type != expectedTextChangeType);
     if (hasError)
     {
         error += "[text change type: " + tce.Type + ", expected: " + expectedTextChangeType + "]";
     }
     hasError = hasError | (tce.NewLineMap.SequenceNumberText != expectedSequenceNumber);
     if (hasError)
     {
         error += "[sequence number area: " + tce.NewLineMap.SequenceNumberText + ", expected: " + expectedSequenceNumber + "]";
     }
     hasError = hasError | (tce.NewLineMap.CommentText != expectedComment);
     if (hasError)
     {
         error += "[comment area: " + tce.NewLineMap.CommentText + ", expected: " + expectedComment + "]";
     }
     hasError = hasError | (tce.NewLineMap.SourceText != expectedText);
     if (hasError)
     {
         error += "[text: " + tce.NewLineMap.SourceText + ", expected: " + expectedText + "]";
     }
     if (hasError)
     {
         throw new Exception(error);
     }
 }
示例#22
0
        /// <summary>
        /// Combines one text change with another
        /// </summary>
        public void Combine(TextChange other)
        {
            if (other.IsEmpty)
            {
                return;
            }

            FullParseRequired |= other.FullParseRequired;
            TextChangeType    |= other.TextChangeType;

            if (OldRange == TextRange.EmptyRange || NewRange == TextRange.EmptyRange)
            {
                OldRange        = other.OldRange;
                NewRange        = other.NewRange;
                OldTextProvider = other.OldTextProvider;
                NewTextProvider = other.NewTextProvider;
            }
            else
            {
                ITextSnapshotProvider oldSnapshotProvider      = OldTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider newSnapshotProvider      = NewTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider otherOldSnapshotProvider = other.OldTextProvider as ITextSnapshotProvider;
                ITextSnapshotProvider otherNewSnapshotProvider = other.NewTextProvider as ITextSnapshotProvider;
                bool changesAreFromNextSnapshot = false;

                if ((oldSnapshotProvider != null) && (newSnapshotProvider != null) &&
                    (otherOldSnapshotProvider != null) && (otherNewSnapshotProvider != null))
                {
                    ITextSnapshot newSnapshot      = newSnapshotProvider.Snapshot;
                    ITextSnapshot otherOldSnapshot = otherOldSnapshotProvider.Snapshot;
                    if (newSnapshot.Version.ReiteratedVersionNumber == otherOldSnapshot.Version.ReiteratedVersionNumber)
                    {
                        changesAreFromNextSnapshot = true;
                    }
                }

                if (!changesAreFromNextSnapshot)
                {
                    // Assume these changes are from the same snapshot
                    int oldStart = Math.Min(other.OldRange.Start, this.OldRange.Start);
                    int oldEnd   = Math.Max(other.OldRange.End, this.OldRange.End);

                    int newStart = Math.Min(other.NewRange.Start, this.NewRange.Start);
                    int newEnd   = Math.Max(other.NewRange.End, this.NewRange.End);

                    OldRange = TextRange.FromBounds(oldStart, oldEnd);
                    NewRange = TextRange.FromBounds(newStart, newEnd);
                }
                else
                {
                    // the "other" change is from the subsequent snapshot. Merge the changes.
                    ITextSnapshot oldSnapshot      = oldSnapshotProvider.Snapshot;
                    ITextSnapshot newSnapshot      = newSnapshotProvider.Snapshot;
                    ITextSnapshot otherOldSnapshot = otherOldSnapshotProvider.Snapshot;
                    ITextSnapshot otherNewSnapshot = otherNewSnapshotProvider.Snapshot;

                    SnapshotSpan otherOldSpan = other.OldRange.ToSnapshotSpan(otherOldSnapshot);
                    SnapshotSpan oldSpan      = otherOldSpan.TranslateTo(oldSnapshot, SpanTrackingMode.EdgeInclusive);

                    SnapshotSpan newSpan      = NewRange.ToSnapshotSpan(newSnapshot);
                    SnapshotSpan otherNewSpan = newSpan.TranslateTo(otherNewSnapshot, SpanTrackingMode.EdgeInclusive);

                    OldRange        = new TextRange(TextRange.Union(OldRange, oldSpan.ToTextRange()));
                    NewRange        = new TextRange(TextRange.Union(other.NewRange, otherNewSpan.ToTextRange()));
                    NewTextProvider = other.NewTextProvider;
                }
            }

            Version = Math.Max(this.Version, other.Version);
        }
示例#23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">Type of chage applied to the line</param>
 /// <param name="lineIndex">Index of the line which was changed</param>
 /// <param name="newLine">New line content after the update (null in case of a LineRemoved event)</param>
 public TextChange(TextChangeType type, int lineIndex, ITextLine newLine)
 {
     Type = type;
     LineIndex = lineIndex;
     NewLine = newLine;
 }
示例#24
0
        private static void CheckLine(string filename, TextChangeMap tce, int index, string expectedText, TextChangeType expectedTextChangeType = TextChangeType.LineInserted, string expectedSequenceNumber = null, string expectedComment = null)
        {
            bool   hasError = false;
            string error    = filename + "," + index + ": ";

            hasError = hasError | (tce.LineIndex != index);
            if (hasError)
            {
                error += "[line index: " + tce.LineIndex + ", expected: " + index + "]";
            }
            hasError = hasError | (tce.Type != expectedTextChangeType);
            if (hasError)
            {
                error += "[text change type: " + tce.Type + ", expected: " + expectedTextChangeType + "]";
            }
            hasError = hasError | (tce.NewLineMap.SequenceNumberText != expectedSequenceNumber);
            if (hasError)
            {
                error += "[sequence number area: " + tce.NewLineMap.SequenceNumberText + ", expected: " + expectedSequenceNumber + "]";
            }
            hasError = hasError | (tce.NewLineMap.CommentText != expectedComment);
            if (hasError)
            {
                error += "[comment area: " + tce.NewLineMap.CommentText + ", expected: " + expectedComment + "]";
            }
            hasError = hasError | (tce.NewLineMap.SourceText != expectedText);
            if (hasError)
            {
                error += "[text: " + tce.NewLineMap.SourceText + ", expected: " + expectedText + "]";
            }
            if (hasError)
            {
                throw new Exception(error);
            }
        }
示例#25
0
        public void TextChange_EditComment01(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b # comment";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 12, oldLength, newLength, newText);

            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
        public void TextChange_AddWhitespace(int start, int oldLength, int newLength, string newText, TextChangeType expected) {
            string expression = "x <- aa";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, start, oldLength, newLength, newText);
            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
示例#27
0
        public void TextChange_EditWhitespaceTest(int start, int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, start, oldLength, newLength, newText);

            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
        public void TextChange_EditString(int oldLength, int newLength, string newText, TextChangeType expected) {
            string expression = "x <- a + \"boo\"";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 10, oldLength, newLength, newText);
            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
示例#29
0
 internal TextChange(TextChangeType type, string text)
 {
     Type = type;
     Text = text;
 }
 // Token: 0x060037C1 RID: 14273 RVA: 0x000F9037 File Offset: 0x000F7237
 internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange) : this(textPosition, count, charCount, textChange, null, false)
 {
 }
示例#31
0
        public void TextChange_AddWhitespace(int start, int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- aa";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, start, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }